# HG changeset patch # User Henry S. Thompson # Date 1626281430 0 # Node ID a76cc0df2754cdb94b7de4316420428edea4cd52 # Parent d3ef00af2064ba74c3348eabf8ba5bbbbb2c5f4f add usage/help info diff -r d3ef00af2064 -r a76cc0df2754 bin/cdx2tsv.py --- a/bin/cdx2tsv.py Wed Jul 14 16:49:54 2021 +0000 +++ b/bin/cdx2tsv.py Wed Jul 14 16:50:30 2021 +0000 @@ -10,6 +10,21 @@ will output media type and URI scheme''' import json,sys +if len(sys.argv)==1 or sys.argv[1][1]=='-': + print("""Reads index lines from stdin and extracts values from json dict part + + Usage: cdx2tsv.py fieldspecs... + + fieldspec is either a name or a quoted python tuple of a name and + an expression with free variable f which will be evaluated with f + having the field value. + + For example + cdx2tsv.py mime '(url,f.split(":",maxsplit=1)[0])' < xyzzy.cdx + will output media type and URI scheme""", + file=sys.stderr) + exit(1) + fields=sys.argv[1:] fields=[((lambda x,y:(x,eval("lambda f:%s"%y)))(*(f[1:-1].split(',',maxsplit=1))) if f[0]=='(' else f) for f in fields]