def parseOpts(argStrList): """ argStrList :: [str] argument string list return :: argparse.Namespace """ parser = argparse.ArgumentParser( description="Map a function to a list of record from an input stream.") pysows.setVersion(parser) parser.add_argument('-g', '--groups', metavar='COLUMNS', dest='group_indexes', default='1', help=pysows.GROUPS_HELP_MESSAGE) parser.add_argument('-f', '--mapfunc', metavar='FUNCTION', dest='map_func', default='lambda *xs:xs', help='Map function as python code.' + \ ' This must return sequence of printable objects.' + \ " (default: 'lambda *xs:xs')") parser.add_argument('-c', '--constructor', metavar='FUNCTION', dest='record_constructor', default='lambda xs,ys:list(xs)+list(ys)', help='Record constructor.' + \ ' This must return sequence of printable objects.' + \ " (default: 'lambda xs,ys:list(xs)+list(ys)')") parser.add_argument('-l', '--load', metavar='FILE', dest='load_file', default=None, help='Load python code for -f and -c.') parser.add_argument("-s", "--separator", metavar='SEP', dest="separator", default=None, help="Record separator (default: spaces).") return parser.parse_args(argStrList)
def parseOpts(args): """ args :: [str] argument string list return :: arpgarser.Namespace """ parser = argparse.ArgumentParser( description="Sort a list of record as an input stream.") pysows.setVersion(parser) parser.add_argument("-g", "--groups", dest="group_indexes", metavar='COLUMNS', default='0', help=pysows.GROUPS_HELP_MESSAGE) parser.add_argument("-k", "--keyfunc", dest="key_func", metavar='FUNCTION', default="lambda *xs: xs", help="Key function. (default: 'lambda *args: args')") parser.add_argument("-c", "--cmpfunc", dest="cmp_func", metavar='FUNCTION', default=None, help="(Not supported yet) Compare function. -c is prior to -k option.") parser.add_argument("-r", "--reverse", action="store_true", dest="reverse", default=False, help="Reverse the result of comprations.") parser.add_argument("-l", "--load", dest="load_file", default=None, help="Load python code for -k or -c.") parser.add_argument("-s", "--separator", dest="separator", metavar='SEP', default=None, help="Column separator. (default: spaces)") return parser.parse_args(args)
def parseOpts(argStrs): """ argStrs :: [str] argument string list. return :: argparse.Namespace """ parser = argparse.ArgumentParser( description="Join two input streams." + " Left input will be load to memory as hash index." + " This tool provide inner join. Join key must be unique but need not be sorted.") pysows.setVersion(parser) parser.add_argument('-lk', metavar='COLUMNS', dest='left_key', default='1', help='Left key columns like "1,2,3". (default: 1).') parser.add_argument('-rk', metavar='COLUMNS', dest='right_key', default='1', help='Right key columns like "1,2,3". (default: 1).') parser.add_argument('-jk', metavar='COLUMNS', dest='join_key', default=None, help='Both -lk and -rk.') parser.add_argument('-oc', metavar='COLUMNS', dest='out_columns', default='l0,r0', help='Output columns. prefix "l" means left input, ' + '"r" means right input. (default: l0,r0)') parser.add_argument('-li', metavar='INPUT', dest='left_input', default=None, required=True, type=argparse.FileType('r'), help='Left input stream. (required)') parser.add_argument('-ri', metavar='INPUT', dest='right_input', default=sys.stdin, type=argparse.FileType('r'), help='Right input stream. (default: stdin)') parser.add_argument("-s", "--separator", metavar='SEP', dest="separator", default=None, help="Record separator (default: spaces).") args = parser.parse_args(argStrs) return args
def parseOpts(args): """ args :: [str] argument string list return :: argparse.Namespace """ parser = argparse.ArgumentParser( description="Filter a list of record as an input stream.") pysows.setVersion(parser) parser.add_argument("-g", "--groups", dest="group_indexes", metavar='COLUMNS', default='0', help=pysows.GROUPS_HELP_MESSAGE) parser.add_argument("-p", "--predicate", dest="predicate", metavar='PREDICATE', default='lambda *xs:True', help="Predicate as python code." + \ " This must return bool value.") parser.add_argument("-r", "--regex", dest="regex_list", nargs='+', metavar='REGEX_PATTERN', default=None, help="Regular expression." + \ " When both -p and -r options are specified, -r is used.") parser.add_argument("-l", "--load", dest="load_file", metavar='FILE', default=None, help="Load python code for -p.") parser.add_argument("-s", "--separator", dest="separator", metavar='SEP', default=None, help="Record separator. (default: spaces)") parser.add_argument("-v", "--invert", action="store_true", dest="invert", default=False, help="Invert match like grep -v.") return parser.parse_args(args)
def parseOpts(args): """ args :: [str] Argument string list return :: argparse.Namespace """ parser = argparse.ArgumentParser( description="Project a record list as an input stream.") pysows.setVersion(parser) parser.add_argument("-g", "--groups", dest="group_indexes", metavar='COLUMNS', default='0', help="Column index list separated by comma. (default: 0)") parser.add_argument("-s", "--separator", dest="separator", metavar='SEP', default=None, help="Record separator. (default spaces)") return parser.parse_args(args)