diff options
author | nmaligec <wouldnot@hotmail.com> | 2011-01-05 17:01:19 -0500 |
---|---|---|
committer | nmaligec <wouldnot@hotmail.com> | 2011-01-05 17:01:19 -0500 |
commit | d9e0ee6e6f9cb3e36d9ef93aebf2240ea30fb46d (patch) | |
tree | 506eb8e62242e5d08f6638251765cbca78bf049f | |
parent | fd50470e743c46348641ee1d980b5d0d8ed96777 (diff) | |
parent | 675f6d1808fb208a6191a0b9da3cd64e2515b7d5 (diff) | |
download | serverdata-d9e0ee6e6f9cb3e36d9ef93aebf2240ea30fb46d.tar.gz serverdata-d9e0ee6e6f9cb3e36d9ef93aebf2240ea30fb46d.tar.bz2 serverdata-d9e0ee6e6f9cb3e36d9ef93aebf2240ea30fb46d.tar.xz serverdata-d9e0ee6e6f9cb3e36d9ef93aebf2240ea30fb46d.zip |
Merge branch 'master' of git://gitorious.org/~wombat/tmw-eathena-data/cache-serverdata
-rwxr-xr-x | tools/aligncsv.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tools/aligncsv.py b/tools/aligncsv.py new file mode 100755 index 00000000..69e1d871 --- /dev/null +++ b/tools/aligncsv.py @@ -0,0 +1,76 @@ +#!/usr/bin/python +# this formats a csv file to a serious whitespace intended format. + +import os +import sys + +tabs=not True + +fname = sys.argv[1] +if not os.path.exists(fname): + print "that file doesn't exist" + exit(0); + +f=open(fname,"r"); +lines=f.readlines() +f.close(); +length=0 + +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) +for x in range(len(lines)+1): + textarray[x] = range(length) + +for x in range(length): + textarray[-1][x] = 0 + +#find the longest entry in each line in each position +for lineno in range(len(lines)): + sp=lines[lineno].split(",") + for pieceno in range(len(sp)): + sp[pieceno] = sp[pieceno].strip() + 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 + +for lineno in range(len(lines)): + sp=lines[lineno].split(",") + for pieceno in range(length): + textarray[lineno][pieceno] = "" + if pieceno<len(sp): + sp[pieceno]= sp[pieceno].strip() + if pieceno<len(sp)-1: + sp[pieceno]= sp[pieceno] + "," + n=(textarray[-1][pieceno]-len(sp[pieceno])+additionalspaces) + if (tabs): + textarray[lineno][pieceno] = sp[pieceno] + textarray[lineno][pieceno] += "\t" *(n/8) + else: + textarray[lineno][pieceno] = " "*(n) + sp[pieceno] + + +fname = sys.argv[2] +if not os.path.exists(fname): + print "that file doesn't exist" + exit(0); +else: + f=open(fname,"w"); + for line in textarray[:-1]: + for piece in line: + f.write(piece) + f.write("\n") + f.close() + + + + |