Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fiddle with 2tsv and bridges

  • Loading branch information...
commit b35f1fbff51bc41b14befbde188a1cc2700a45a1 1 parent d4403a1
@brendano authored
Showing with 354 additions and 11 deletions.
  1. +320 −0 .gitignore
  2. +10 −3 make_bridges.rb
  3. +23 −8 tsv2fmt
  4. +1 −0  tsvutil.py
View
320 .gitignore
@@ -6,6 +6,326 @@ csv2fmt
csv2html
csv2my
csv2tex
+csv2ssv
+eq2csv
+eq2fmt
+eq2html
+eq2my
+eq2tex
+eq2ssv
+json2csv
+json2fmt
+json2html
+json2my
+json2tex
+json2ssv
+ssv2csv
+ssv2fmt
+ssv2html
+ssv2my
+ssv2tex
+ssv2ssv
+uniq2csv
+uniq2fmt
+uniq2html
+uniq2my
+uniq2tex
+uniq2ssv
+xlsx2csv
+xlsx2fmt
+xlsx2html
+xlsx2my
+xlsx2tex
+xlsx2ssv
+yaml2csv
+yaml2fmt
+yaml2html
+yaml2my
+yaml2tex
+yaml2ssv
+fmt2csv
+fmt2fmt
+fmt2html
+fmt2my
+fmt2tex
+fmt2ssv
+csv2csv
+csv2fmt
+csv2html
+csv2my
+csv2tex
+csv2ssv
+eq2csv
+eq2fmt
+eq2html
+eq2my
+eq2tex
+eq2ssv
+json2csv
+json2fmt
+json2html
+json2my
+json2tex
+json2ssv
+ssv2csv
+ssv2fmt
+ssv2html
+ssv2my
+ssv2tex
+ssv2ssv
+uniq2csv
+uniq2fmt
+uniq2html
+uniq2my
+uniq2tex
+uniq2ssv
+xlsx2csv
+xlsx2fmt
+xlsx2html
+xlsx2my
+xlsx2tex
+xlsx2ssv
+yaml2csv
+yaml2fmt
+yaml2html
+yaml2my
+yaml2tex
+yaml2ssv
+fmt2csv
+fmt2fmt
+fmt2html
+fmt2my
+fmt2tex
+fmt2ssv
+csv2csv
+csv2fmt
+csv2html
+csv2my
+csv2tex
+csv2ssv
+eq2csv
+eq2fmt
+eq2html
+eq2my
+eq2tex
+eq2ssv
+json2csv
+json2fmt
+json2html
+json2my
+json2tex
+json2ssv
+ssv2csv
+ssv2fmt
+ssv2html
+ssv2my
+ssv2tex
+ssv2ssv
+uniq2csv
+uniq2fmt
+uniq2html
+uniq2my
+uniq2tex
+uniq2ssv
+xlsx2csv
+xlsx2fmt
+xlsx2html
+xlsx2my
+xlsx2tex
+xlsx2ssv
+yaml2csv
+yaml2fmt
+yaml2html
+yaml2my
+yaml2tex
+yaml2ssv
+fmt2csv
+fmt2fmt
+fmt2html
+fmt2my
+fmt2tex
+fmt2ssv
+csv2csv
+csv2fmt
+csv2html
+csv2my
+csv2tex
+csv2ssv
+eq2csv
+eq2fmt
+eq2html
+eq2my
+eq2tex
+eq2ssv
+json2csv
+json2fmt
+json2html
+json2my
+json2tex
+json2ssv
+ssv2csv
+ssv2fmt
+ssv2html
+ssv2my
+ssv2tex
+ssv2ssv
+uniq2csv
+uniq2fmt
+uniq2html
+uniq2my
+uniq2tex
+uniq2ssv
+xlsx2csv
+xlsx2fmt
+xlsx2html
+xlsx2my
+xlsx2tex
+xlsx2ssv
+yaml2csv
+yaml2fmt
+yaml2html
+yaml2my
+yaml2tex
+yaml2ssv
+fmt2csv
+fmt2fmt
+fmt2html
+fmt2my
+fmt2tex
+fmt2ssv
+csv2csv
+csv2fmt
+csv2html
+csv2my
+csv2tex
+csv2ssv
+eq2csv
+eq2fmt
+eq2html
+eq2my
+eq2tex
+eq2ssv
+json2csv
+json2fmt
+json2html
+json2my
+json2tex
+json2ssv
+ssv2csv
+ssv2fmt
+ssv2html
+ssv2my
+ssv2tex
+ssv2ssv
+uniq2csv
+uniq2fmt
+uniq2html
+uniq2my
+uniq2tex
+uniq2ssv
+xlsx2csv
+xlsx2fmt
+xlsx2html
+xlsx2my
+xlsx2tex
+xlsx2ssv
+yaml2csv
+yaml2fmt
+yaml2html
+yaml2my
+yaml2tex
+yaml2ssv
+fmt2csv
+fmt2fmt
+fmt2html
+fmt2my
+fmt2tex
+fmt2ssv
+csv2csv
+csv2fmt
+csv2html
+csv2my
+csv2tex
+eq2csv
+eq2fmt
+eq2html
+eq2my
+eq2tex
+json2csv
+json2fmt
+json2html
+json2my
+json2tex
+ssv2csv
+ssv2fmt
+ssv2html
+ssv2my
+ssv2tex
+uniq2csv
+uniq2fmt
+uniq2html
+uniq2my
+uniq2tex
+xlsx2csv
+xlsx2fmt
+xlsx2html
+xlsx2my
+xlsx2tex
+yaml2csv
+yaml2fmt
+yaml2html
+yaml2my
+yaml2tex
+fmt2csv
+fmt2fmt
+fmt2html
+fmt2my
+fmt2tex
+csv2csv
+csv2fmt
+csv2html
+csv2my
+csv2tex
+eq2csv
+eq2fmt
+eq2html
+eq2my
+eq2tex
+json2csv
+json2fmt
+json2html
+json2my
+json2tex
+ssv2csv
+ssv2fmt
+ssv2html
+ssv2my
+ssv2tex
+uniq2csv
+uniq2fmt
+uniq2html
+uniq2my
+uniq2tex
+xlsx2csv
+xlsx2fmt
+xlsx2html
+xlsx2my
+xlsx2tex
+yaml2csv
+yaml2fmt
+yaml2html
+yaml2my
+yaml2tex
+fmt2csv
+fmt2fmt
+fmt2html
+fmt2my
+fmt2tex
+csv2csv
+csv2fmt
+csv2html
+csv2my
+csv2tex
eq2csv
eq2fmt
eq2html
View
13 make_bridges.rb
@@ -1,7 +1,9 @@
# go through tsv as universal intermediary
-sources = %w(csv eq json ssv uniq xlsx yaml)
-dests = %w(csv fmt html my tex)
+sources = %w(csv eq json ssv uniq xlsx yaml fmt)
+dests = %w(csv fmt html my tex ssv)
+
+opts_right = /.*2fmt/
system "mkdir -p bridges"
@@ -14,10 +16,15 @@
right = "tsv2#{d}"
if File.exists?(left) && File.exists?(right)
puts "making #{s}2#{d}"
+ if "#{s}2#{d}" =~ opts_right
+ right = %|#{right} "$@"|
+ else
+ left = %|#{left} "$@"|
+ end
open("bridges/#{s}2#{d}","w") do |f|
f.puts %[
#!/bin/sh
- #{left} "$@" | #{right}
+ #{left} | #{right}
].gsub(/^ */,"").strip
end
bridges << "#{s}2#{d}"
View
31 tsv2fmt
@@ -1,12 +1,22 @@
#!/usr/bin/env python
"""
-Outputs in a ascii-art table, reminiscent of Postgres and MySQL command-lines.
+Outputs an ascii-art table with aligned columns.
+Reminiscent of Postgres and MySQL commandlines.
"""
#from __future__ import print_function
import sys
from collections import defaultdict
-import tsvutil
-tsvutil.fix_stdio()
+#import tsvutil
+#tsvutil.fix_stdio()
+
+OUTER_BORDERS = True
+INNER_BORDERS = True
+if '-o' in sys.argv:
+ OUTER_BORDERS = False
+if '-b' in sys.argv:
+ OUTER_BORDERS = False
+ INNER_BORDERS = False
+
#width_hists = [defaultdict(lambda:0) for j in range(J)]
width_hists = defaultdict(lambda: defaultdict(lambda:0))
@@ -14,16 +24,19 @@ width_hists = defaultdict(lambda: defaultdict(lambda:0))
rows = []
for line in sys.stdin:
vals = line[:-1].split("\t")
+ vals = [v.strip() for v in vals]
#for j in range(J):
for j in xrange(len(vals)):
- width_hists[j][len(vals[j])] += 1
+ val_len = len(vals[j].decode('utf-8','ignore'))
+ width_hists[j][val_len] += 1
rows.append(vals)
+if not rows: sys.exit()
+
J = max(width_hists.keys()) + 1
assert range(J) == sorted(list(width_hists.keys()))
-if not rows: sys.exit()
widths = [max(width_hists[j].keys()) for j in range(J)]
# todo, if >5ish rows, drop high-width outliers in a column when computing the
@@ -32,10 +45,12 @@ widths = [max(width_hists[j].keys()) for j in range(J)]
def print_row(row):
global widths
- sys.stdout.write("| ")
+ if OUTER_BORDERS: sys.stdout.write("| ")
if len(row) < J: row += [""] * (J - len(row))
- sys.stdout.write(" | ".join([("%-"+str(widths[j])+"s") % row[j] for j in range(J)]))
- print>>sys.stdout, " |"
+ joiner = " | " if INNER_BORDERS else " "
+ sys.stdout.write(joiner.join([("%-"+str(widths[j])+"s") % row[j] for j in range(J)]))
+ if OUTER_BORDERS: sys.stdout.write(" |")
+ sys.stdout.write("\n")
def print_sep():
global widths
View
1  tsvutil.py
@@ -27,6 +27,7 @@ def fix_stdio():
# ideally, would be nice to make python shut up and pretend encodings dont exist, like ruby
# by default coerces to ascii -- very bad
# solution seems to be to coerce to utf8 -- but not necessarily ideal either
+ # these /dev thingies aren't good to use on all platforms, have seen problems on linux
sys.stdout = codecs.open('/dev/stdout','w',encoding='utf8',buffering=0)
sys.stdout = IOWrapper(sys.stdout)
sys.stdin = codecs.open('/dev/stdin','U',encoding='utf8',buffering=0)
Please sign in to comment.
Something went wrong with that request. Please try again.