scripts: csv.py: Added --help-mods to help explain % modifiers
I guess in addition to its other utilities, csv.py is now also turning into a sort of man database for some of the more complicated APIs in the scripts: ./csv.py --help ./csv.py --help-exprs ./csv.py --help-mods It's a bit minimal, but better than nothing. Also dropped the %c modifier because this never actually worked.
This commit is contained in:
+25
-1
@@ -1281,7 +1281,7 @@ def punescape(s, attrs=None):
|
|||||||
'|' '%u....'
|
'|' '%u....'
|
||||||
'|' '%U........'
|
'|' '%U........'
|
||||||
'|' '%\((?P<field>[^)]*)\)'
|
'|' '%\((?P<field>[^)]*)\)'
|
||||||
'(?P<format>[+\- #0-9\.]*[scdboxXfFeEgG])')
|
'(?P<format>[+\- #0-9\.]*[sdboxXfFeEgG])')
|
||||||
def unescape(m):
|
def unescape(m):
|
||||||
if m.group()[1] == '%': return '%'
|
if m.group()[1] == '%': return '%'
|
||||||
elif m.group()[1] == 'n': return '\n'
|
elif m.group()[1] == 'n': return '\n'
|
||||||
@@ -1310,6 +1310,23 @@ def punescape(s, attrs=None):
|
|||||||
else: assert False
|
else: assert False
|
||||||
return re.sub(pattern, unescape, s)
|
return re.sub(pattern, unescape, s)
|
||||||
|
|
||||||
|
def punescape_help():
|
||||||
|
print('mods:')
|
||||||
|
print(' %-21s %s' % ('%%', 'A literal % character'))
|
||||||
|
print(' %-21s %s' % ('%n', 'A newline'))
|
||||||
|
print(' %-21s %s' % (
|
||||||
|
'%xaa', 'A character with the hex value aa'))
|
||||||
|
print(' %-21s %s' % (
|
||||||
|
'%uaaaa', 'A character with the hex value aaaa'))
|
||||||
|
print(' %-21s %s' % (
|
||||||
|
'%Uaaaaaaaa', 'A character with the hex value aaaaaaaa'))
|
||||||
|
print(' %-21s %s' % (
|
||||||
|
'%(field)s', 'An existing field formatted as a string'))
|
||||||
|
print(' %-21s %s' % (
|
||||||
|
'%(field)[dboxX]', 'An existing field formatted as an integer'))
|
||||||
|
print(' %-21s %s' % (
|
||||||
|
'%(field)[fFeEgG]', 'An existing field formatted as a float'))
|
||||||
|
|
||||||
|
|
||||||
def openio(path, mode='r', buffering=-1):
|
def openio(path, mode='r', buffering=-1):
|
||||||
# allow '-' for stdin/stdout
|
# allow '-' for stdin/stdout
|
||||||
@@ -2122,6 +2139,9 @@ def main(csv_paths, *,
|
|||||||
import builtins
|
import builtins
|
||||||
enumerate_, enumerate = enumerate, builtins.enumerate
|
enumerate_, enumerate = enumerate, builtins.enumerate
|
||||||
|
|
||||||
|
# show mod help text?
|
||||||
|
if args.get('help_mods'):
|
||||||
|
return punescape_help()
|
||||||
# show expr help text?
|
# show expr help text?
|
||||||
if args.get('help_exprs'):
|
if args.get('help_exprs'):
|
||||||
return RExpr.help()
|
return RExpr.help()
|
||||||
@@ -2331,6 +2351,10 @@ if __name__ == "__main__":
|
|||||||
'csv_paths',
|
'csv_paths',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
help="Input *.csv files.")
|
help="Input *.csv files.")
|
||||||
|
parser.add_argument(
|
||||||
|
'--help-mods',
|
||||||
|
action='store_true',
|
||||||
|
help="Show what %% modifiers are available.")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--help-exprs',
|
'--help-exprs',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
|||||||
+1
-1
@@ -480,7 +480,7 @@ def punescape(s, attrs=None):
|
|||||||
'|' '%u....'
|
'|' '%u....'
|
||||||
'|' '%U........'
|
'|' '%U........'
|
||||||
'|' '%\((?P<field>[^)]*)\)'
|
'|' '%\((?P<field>[^)]*)\)'
|
||||||
'(?P<format>[+\- #0-9\.]*[scdboxXfFeEgG])')
|
'(?P<format>[+\- #0-9\.]*[sdboxXfFeEgG])')
|
||||||
def unescape(m):
|
def unescape(m):
|
||||||
if m.group()[1] == '%': return '%'
|
if m.group()[1] == '%': return '%'
|
||||||
elif m.group()[1] == 'n': return '\n'
|
elif m.group()[1] == 'n': return '\n'
|
||||||
|
|||||||
+1
-1
@@ -404,7 +404,7 @@ def punescape(s, attrs=None):
|
|||||||
'|' '%u....'
|
'|' '%u....'
|
||||||
'|' '%U........'
|
'|' '%U........'
|
||||||
'|' '%\((?P<field>[^)]*)\)'
|
'|' '%\((?P<field>[^)]*)\)'
|
||||||
'(?P<format>[+\- #0-9\.]*[scdboxXfFeEgG])')
|
'(?P<format>[+\- #0-9\.]*[sdboxXfFeEgG])')
|
||||||
def unescape(m):
|
def unescape(m):
|
||||||
if m.group()[1] == '%': return '%'
|
if m.group()[1] == '%': return '%'
|
||||||
elif m.group()[1] == 'n': return '\n'
|
elif m.group()[1] == 'n': return '\n'
|
||||||
|
|||||||
+1
-1
@@ -264,7 +264,7 @@ def punescape(s, attrs=None):
|
|||||||
'|' '%u....'
|
'|' '%u....'
|
||||||
'|' '%U........'
|
'|' '%U........'
|
||||||
'|' '%\((?P<field>[^)]*)\)'
|
'|' '%\((?P<field>[^)]*)\)'
|
||||||
'(?P<format>[+\- #0-9\.]*[scdboxXfFeEgG])')
|
'(?P<format>[+\- #0-9\.]*[sdboxXfFeEgG])')
|
||||||
def unescape(m):
|
def unescape(m):
|
||||||
if m.group()[1] == '%': return '%'
|
if m.group()[1] == '%': return '%'
|
||||||
elif m.group()[1] == 'n': return '\n'
|
elif m.group()[1] == 'n': return '\n'
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ def punescape(s, attrs=None):
|
|||||||
'|' '%u....'
|
'|' '%u....'
|
||||||
'|' '%U........'
|
'|' '%U........'
|
||||||
'|' '%\((?P<field>[^)]*)\)'
|
'|' '%\((?P<field>[^)]*)\)'
|
||||||
'(?P<format>[+\- #0-9\.]*[scdboxXfFeEgG])')
|
'(?P<format>[+\- #0-9\.]*[sdboxXfFeEgG])')
|
||||||
def unescape(m):
|
def unescape(m):
|
||||||
if m.group()[1] == '%': return '%'
|
if m.group()[1] == '%': return '%'
|
||||||
elif m.group()[1] == 'n': return '\n'
|
elif m.group()[1] == 'n': return '\n'
|
||||||
|
|||||||
Reference in New Issue
Block a user