summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Beller <stefanbeller@googlemail.com>2011-01-05 23:27:25 +0100
committerStefan Beller <stefanbeller@googlemail.com>2011-01-05 23:27:48 +0100
commit97fd9bd940f06d0b86f8b2278ba28c1b581f3b64 (patch)
treebbcaeb8eea44de6ec598f90bbc2910432686d1a6
parentd9e0ee6e6f9cb3e36d9ef93aebf2240ea30fb46d (diff)
downloadserverdata-97fd9bd940f06d0b86f8b2278ba28c1b581f3b64.tar.gz
serverdata-97fd9bd940f06d0b86f8b2278ba28c1b581f3b64.tar.bz2
serverdata-97fd9bd940f06d0b86f8b2278ba28c1b581f3b64.tar.xz
serverdata-97fd9bd940f06d0b86f8b2278ba28c1b581f3b64.zip
now the alignment script works with tabs as well
-rwxr-xr-xtools/aligncsv.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/tools/aligncsv.py b/tools/aligncsv.py
index 69e1d871..ce63a988 100755
--- a/tools/aligncsv.py
+++ b/tools/aligncsv.py
@@ -4,7 +4,8 @@
import os
import sys
-tabs=not True
+tabs=True
+additionalspaces = 5
fname = sys.argv[1]
if not os.path.exists(fname):
@@ -20,7 +21,7 @@ for line in lines:
length=max(length, len(line.split(",")))
print "# number of entries =",length
-additionalspaces = 5
+
#setup text array
textarray=range(len(lines)+1)
@@ -34,14 +35,14 @@ for x in range(length):
for lineno in range(len(lines)):
sp=lines[lineno].split(",")
for pieceno in range(len(sp)):
- sp[pieceno] = sp[pieceno].strip()
+ sp[pieceno] = sp[pieceno].strip() + "," #for the comma add a char
textarray[-1][pieceno] = max(len(sp[pieceno]),textarray[-1][pieceno])
if tabs:
#make it divisable by 8 (tabs work then)
for pieceno in range(length):
- if textarray[-1][pieceno] %8:
- textarray[-1][pieceno] = ((textarray[-1][pieceno]/8) *8) +8
+ if (textarray[-1][pieceno] %8) !=0:
+ textarray[-1][pieceno] = (((textarray[-1][pieceno])/8)*8)+8
for lineno in range(len(lines)):
sp=lines[lineno].split(",")
@@ -51,11 +52,16 @@ for lineno in range(len(lines)):
sp[pieceno]= sp[pieceno].strip()
if pieceno<len(sp)-1:
sp[pieceno]= sp[pieceno] + ","
- n=(textarray[-1][pieceno]-len(sp[pieceno])+additionalspaces)
+
if (tabs):
+ n=(textarray[-1][pieceno]-len(sp[pieceno]))
textarray[lineno][pieceno] = sp[pieceno]
- textarray[lineno][pieceno] += "\t" *(n/8)
+ if (n%8) != 0:
+ textarray[lineno][pieceno] += "\t"*((n/8)+1)
+ else:
+ textarray[lineno][pieceno] += "\t"*((n/8))
else:
+ n=(textarray[-1][pieceno]-len(sp[pieceno])+additionalspaces)
textarray[lineno][pieceno] = " "*(n) + sp[pieceno]