forcing everything python3, might end up with bugs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2017 Ville Rantanen
|
||||
#
|
||||
@@ -17,14 +17,21 @@
|
||||
#
|
||||
|
||||
'''TSV 2 SC convert.'''
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
from builtins import chr
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
from past.utils import old_div
|
||||
__author__ = "Ville Rantanen"
|
||||
|
||||
__version__ = "0.2"
|
||||
|
||||
import sys,os
|
||||
import csv
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser
|
||||
import unicodedata, re
|
||||
import subprocess
|
||||
|
||||
@@ -45,10 +52,10 @@ def which(program):
|
||||
|
||||
return None
|
||||
|
||||
class SCWriter:
|
||||
class SCWriter(object):
|
||||
""" Class for writing SC files.
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
def __init__(self,file,alignright,float_precision):
|
||||
self.file=file
|
||||
self.row=0
|
||||
@@ -61,9 +68,9 @@ class SCWriter:
|
||||
self.alignstring="rightstring"
|
||||
else:
|
||||
self.alignstring="leftstring"
|
||||
|
||||
|
||||
def parse_row(self,string):
|
||||
|
||||
|
||||
self.col=0
|
||||
for el in row:
|
||||
self.write_element(self.row,self.col,el)
|
||||
@@ -78,30 +85,30 @@ class SCWriter:
|
||||
self.col_lengths[self.col]=max(len(el_str)+1,self.col_lengths[self.col])
|
||||
self.col+=1
|
||||
self.row+=1
|
||||
|
||||
|
||||
def write_element(self,row,col,content):
|
||||
|
||||
|
||||
colalpha=self.column_to_alpha(col)
|
||||
content=content.strip('"')
|
||||
|
||||
|
||||
if self.is_num(content):
|
||||
self.file.write('let '+colalpha+str(row)+' = ' + str(self.to_num(content))+'\n')
|
||||
else:
|
||||
self.file.write(self.alignstring+' '+colalpha+str(row)+' = "' + content + '"\n')
|
||||
|
||||
|
||||
def column_to_alpha(self,column):
|
||||
''' Returns a column alphabet from column number '''
|
||||
o=chr(column+64+1)
|
||||
if column>25:
|
||||
return self.column_to_alpha((column / 26) -1) + self.column_to_alpha(column % 26);
|
||||
return self.column_to_alpha((old_div(column, 26)) -1) + self.column_to_alpha(column % 26);
|
||||
return o
|
||||
|
||||
|
||||
def write_row(self,row):
|
||||
''' Writes a row as a SC file part '''
|
||||
self.parse_row(row)
|
||||
|
||||
|
||||
def write_formats(self):
|
||||
|
||||
|
||||
for col in range(len(self.col_lengths)):
|
||||
precision="0"
|
||||
if self.col_types[col]=='float':
|
||||
@@ -117,7 +124,7 @@ class SCWriter:
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
return False
|
||||
|
||||
def is_int(self,string):
|
||||
try:
|
||||
@@ -125,7 +132,7 @@ class SCWriter:
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def is_num(self,string):
|
||||
@@ -149,12 +156,12 @@ class SCWriter:
|
||||
return num
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
return string
|
||||
|
||||
def setup_options():
|
||||
''' Setup the command line options '''
|
||||
|
||||
|
||||
parser=ArgumentParser()
|
||||
parser.add_argument("-v","--version",action='version', version=__version__)
|
||||
parser.add_argument("-f",type=int,dest="precision",default=2,
|
||||
@@ -166,8 +173,8 @@ def setup_options():
|
||||
parser.add_argument("tsv",type=str,action="store",
|
||||
help="TSV file to convert")
|
||||
options=parser.parse_args()
|
||||
return options
|
||||
|
||||
return options
|
||||
|
||||
if not which('sc'):
|
||||
print('You don\'t seem to have "sc" installed!')
|
||||
print('sudo apt-get install sc')
|
||||
|
||||
Reference in New Issue
Block a user