Example #1
0
 def add_arguments(self):
     self.argparser.add_argument('files',
                                 metavar='FILES',
                                 nargs='+',
                                 type=CSVFileType())
     self.argparser.add_argument(
         '-g',
         '--groups',
         dest='groups',
         help=
         'A comma-seperated list of values to add as "grouping factors", one for each CSV being stacked. These will be added to the stacked CSV as a new column. You may specify a name for the grouping column using the -n flag.'
     )
     self.argparser.add_argument(
         '-n',
         '--group-name',
         dest='group_name',
         help=
         'A name for the grouping column, e.g. "year". Only used when also specifying -g.'
     )
     self.argparser.add_argument(
         '--filenames',
         dest='group_by_filenames',
         action='store_true',
         help=
         'Use the filename of each input file as its grouping value. When specified, -g will be ignored.'
     )
Example #2
0
 def add_arguments(self):
     self.argparser.add_argument(
         '-c',
         '--columns',
         dest='columns',
         help=
         'A comma separated list of column indices or names to be modified.'
     )
     # todo: support in-place file modification
     # todo: make sure that it supports backup spec, eg '-i.orig'
     # self.argparser.add_argument(
     #   '-i', '--in-place',
     #   dest='inplace',
     #   help='Modify a file in-place (with a value, specifies that the original'
     #   ' should be renamed first, e.g. "-i.orig")')
     self.argparser.add_argument(
         'expr',
         metavar='EXPR',
         help=
         'The "sed" expression to evaluate: currently supports substitution'
         ' (s/REGEX/EXPR/FLAGS) and transliteration (y/SRC/DEST/FLAGS).')
     self.argparser.add_argument(
         'file',
         metavar='FILE',
         nargs='?',
         type=CSVFileType(),
         default=sys.stdin,
         help=
         'The CSV file to operate on. If omitted or "-", will read from STDIN.'
     )
Example #3
0
 def add_arguments(self):
     self.argparser.add_argument('file',
                                 metavar="FILE",
                                 type=CSVFileType(),
                                 help='The CSV file to operate on.')
     self.argparser.add_argument(
         '--dict',
         dest='as_dict',
         action='store_true',
         help='Use CSVKitDictReader instead of CSVKitReader.')
Example #4
0
 def add_arguments(self):
     self.argparser.add_argument('files', metavar="FILES", nargs='+', type=CSVFileType(),
         help='The CSV files to operate on. If only one is specified, it will be copied to STDOUT.')
     self.argparser.add_argument('-c', '--columns', dest='columns',
         help='The column name(s) on which to join. Should be either one name (or index) or a comma-separated list with one name (or index) for each file, in the same order that the files were specified. May also be left unspecified, in which case the two files will be joined sequentially without performing any matching.')
     self.argparser.add_argument('--outer', dest='outer_join', action='store_true',
         help='Perform a full outer join, rather than the default inner join.')
     self.argparser.add_argument('--left', dest='left_join', action='store_true',
         help='Perform a left outer join, rather than the default inner join. If more than two files are provided this will be executed as a sequence of left outer joins, starting at the left.')
     self.argparser.add_argument('--right', dest='right_join', action='store_true',
         help='Perform a right outer join, rather than the default inner join. If more than two files are provided this will be executed as a sequence of right outer joins, starting at the right.')
Example #5
0
 def add_arguments(self):
     self.argparser.add_argument(
         '-n',
         '--names',
         dest='names_only',
         action='store_true',
         help='Display column names and indices from the input CSV and exit.'
     )
     self.argparser.add_argument(
         '-c',
         '--columns',
         dest='columns',
         help=
         'A comma separated list of column indices or names to be searched.'
     )
     self.argparser.add_argument('-m',
                                 '--match',
                                 dest="pattern",
                                 action='store',
                                 help='The string to search for.')
     self.argparser.add_argument(
         '-r',
         '--regex',
         dest='regex',
         action='store',
         help=
         'If specified, must be followed by a regular expression which will be tested against the specified columns.'
     )
     self.argparser.add_argument(
         '-f',
         '--file',
         dest='matchfile',
         type=FileType('r'),
         action='store',
         help=
         'If specified, must be the path to a file. For each tested row, if any line in the file (stripped of line separators) is an exact match for the cell value, the row will pass.'
     )
     self.argparser.add_argument(
         '-i',
         '--invert-match',
         dest='inverse',
         action='store_true',
         help='If specified, select non-matching instead of matching rows.')
     self.argparser.add_argument(
         'file',
         metavar="FILE",
         nargs='?',
         type=CSVFileType(),
         default=sys.stdin,
         help=
         'The CSV file to operate on. If omitted, will accept input on STDIN.'
     )
Example #6
0
 def add_arguments(self):
     self.argparser.add_argument('file', metavar="FILE", nargs='?', default=sys.stdin,
                         help='The CSV file to operate on. If omitted, will accept input on STDIN.')
     self.argparser.add_argument('-f', '--format', dest='format',
                         help='The format of the input file. If not specified will be inferred from the file type. Supported formats: %s.' % ', '.join(sorted(convert.SUPPORTED_FORMATS)))
     self.argparser.add_argument('-s', '--schema', dest='schema', type=CSVFileType(),
                         help='Specifies a CSV-formatted schema file for converting fixed-width files.  See documentation for details.')
     self.argparser.add_argument('-k', '--key', dest='key',
                         help='Specifies a top-level key to use look within for a list of objects to be converted when processing JSON.')
     self.argparser.add_argument('-y', '--snifflimit', dest='snifflimit', type=int,
                         help='Limit CSV dialect sniffing to the specified number of bytes. Specify "0" to disable sniffing entirely.')
     self.argparser.add_argument('--sheet', dest='sheet',
                         help='The name of the XLSX sheet to operate on.')
Example #7
0
 def add_arguments(self):
     self.argparser.add_argument('files', metavar="FILE", nargs='*', type=CSVFileType(), default=sys.stdin,
         help='The CSV file(s) to operate on. If omitted, will accept input on STDIN.')
     self.argparser.add_argument('-y', '--snifflimit', dest='snifflimit', type=int,
         help='Limit CSV dialect sniffing to the specified number of bytes.')
     self.argparser.add_argument('-i', '--dialect', dest='dialect', choices=sql.DIALECTS,
         help='Dialect of SQL to generate. Only valid when --db is not specified.')
     self.argparser.add_argument('--db', dest='connection_string',
         help='If present, a sqlalchemy connection string to use to directly execute generated SQL on a database.')
     self.argparser.add_argument('--insert', dest='insert', action='store_true',
         help='In addition to creating the table, also insert the data into the table. Only valid when --db is specified.')
     self.argparser.add_argument('--table', dest='table_name',
         help='Specify a name for the table to be created. If omitted, the filename (minus extension) will be used.')
     self.argparser.add_argument('--no-constraints', dest='no_constraints', action='store_true',
         help='Generate a schema without length limits or null checks. Useful when sampling big tables.')
     self.argparser.add_argument('--no-create', dest='no_create', action='store_true',
         help='Skip creating a table. Only valid when --insert is specified.')
     self.argparser.add_argument('--blanks', dest='blanks', action='store_true',
         help='Do not coerce empty strings to NULL values.')
     self.argparser.add_argument('--no-infer', dest='no_infer',
         help='A comma separated list of column indices or names to skip type inference. Specified columns will be treated as strings.')
Example #8
0
 def add_arguments(self):
     self.argparser.add_argument(
         'files',
         metavar="FILE",
         nargs='*',
         type=CSVFileType(),
         default=[sys.stdin],
         help=
         'The CSV file(s) to operate on. If omitted, will accept input on STDIN.'
     )
     self.argparser.add_argument(
         '-y',
         '--snifflimit',
         dest='snifflimit',
         type=int,
         help=
         'Limit CSV dialect sniffing to the specified number of bytes. Specify "0" to disable sniffing entirely.'
     )
     self.argparser.add_argument(
         '-i',
         '--dialect',
         dest='dialect',
         choices=sql.DIALECTS,
         help=
         'Dialect of SQL to generate. Only valid when --db is not specified.'
     )
     self.argparser.add_argument(
         '--db',
         dest='connection_string',
         help=
         'If present, a sqlalchemy connection string to use to directly execute generated SQL on a database.'
     )
     self.argparser.add_argument(
         '--query',
         default=None,
         help=
         'Execute one or more SQL queries delimited by ";" and output the result of the last query as CSV.'
     )
     self.argparser.add_argument(
         '--insert',
         dest='insert',
         action='store_true',
         help=
         'In addition to creating the table, also insert the data into the table. Only valid when --db is specified.'
     )
     self.argparser.add_argument(
         '--tables',
         dest='table_names',
         help=
         'Specify one or more names for the tables to be created. If omitted, the filename (minus extension) or "stdin" will be used.'
     )
     self.argparser.add_argument(
         '--no-constraints',
         dest='no_constraints',
         action='store_true',
         help=
         'Generate a schema without length limits or null checks. Useful when sampling big tables.'
     )
     self.argparser.add_argument(
         '--no-create',
         dest='no_create',
         action='store_true',
         help='Skip creating a table. Only valid when --insert is specified.'
     )
     self.argparser.add_argument(
         '--blanks',
         dest='blanks',
         action='store_true',
         help='Do not coerce empty strings to NULL values.')
     self.argparser.add_argument(
         '--no-inference',
         dest='no_inference',
         action='store_true',
         help='Disable type inference when parsing the input.')
     self.argparser.add_argument(
         '--db-schema',
         dest='db_schema',
         help='Optional name of database schema to create table(s) in.')