• R/O
  • SSH

xtab: 提交

Default repository for xtab.py


Commit MetaInfo

修訂540e3e292b79c48d37e4b99650f67ebc6fc6c8d7 (tree)
時間2019-03-20 13:39:47
作者Dreas Nielsen <dreas.nielsen@gmai...>
CommiterDreas Nielsen

Log Message

Modified to run under both Python 2 and Python 3.

Change Summary

差異

diff -r 96963d568dbc -r 540e3e292b79 CHANGELOG.rst
--- a/CHANGELOG.rst Sun Aug 26 14:07:00 2018 -0700
+++ b/CHANGELOG.rst Tue Mar 19 21:39:47 2019 -0700
@@ -1,6 +1,7 @@
11 ========== ========== =================================================================================
22 Date Version Features
33 ========== ========== =================================================================================
4+2019-03-19 1.0.0 Modified to run under both Python 2 and Python 3.
45 2018-08-26 0.10.2 Documentation revisions.
56 2018-08-21 0.10.1 Modified to delete the error message file if it was created but no errors occurred.
67 2018-03-05 0.10.0 Modified so that sorting is controlled by a new option, "-s".
diff -r 96963d568dbc -r 540e3e292b79 doc/source/conf.py
--- a/doc/source/conf.py Sun Aug 26 14:07:00 2018 -0700
+++ b/doc/source/conf.py Tue Mar 19 21:39:47 2019 -0700
@@ -54,9 +54,9 @@
5454 # built documents.
5555 #
5656 # The short X.Y version.
57-version = u'0.10.1'
57+version = u'1.0.0'
5858 # The full version, including alpha/beta/rc tags.
59-release = u'0.10.1'
59+release = u'1.0.0'
6060
6161 # The language for content autogenerated by Sphinx. Refer to documentation
6262 # for a list of supported languages.
diff -r 96963d568dbc -r 540e3e292b79 doc/source/copyright.rst
--- a/doc/source/copyright.rst Sun Aug 26 14:07:00 2018 -0700
+++ b/doc/source/copyright.rst Tue Mar 19 21:39:47 2019 -0700
@@ -3,7 +3,7 @@
33 Copyright and License
44 ================================
55
6-Copyright (c) 2008-2018 R.Dreas Nielsen
6+Copyright (c) 2008-2019 R.Dreas Nielsen
77
88 This program is free software: you can redistribute it and/or modify it
99 under the terms of the GNU General Public License as published by the
diff -r 96963d568dbc -r 540e3e292b79 setup.py
--- a/setup.py Sun Aug 26 14:07:00 2018 -0700
+++ b/setup.py Tue Mar 19 21:39:47 2019 -0700
@@ -1,20 +1,21 @@
11 from distutils.core import setup
22
33 setup(name='xtab',
4- version='0.10.2',
4+ version='1.0.0',
55 description="Crosstabulates data in a text file.",
66 author='Dreas Nielsen',
77 author_email='dreas.nielsen@gmail.com',
88 url='https://bitbucket.org/rdnielsen/xtab/',
99 scripts=['xtab/xtab.py'],
1010 license='GPL',
11- python_requires = '>=2.6, <3',
11+ python_requires = '>=2.7',
1212 classifiers=[
1313 'Environment :: Console',
1414 'Intended Audience :: End Users/Desktop',
1515 'License :: OSI Approved :: GNU General Public License (GPL)',
1616 'Operating System :: OS Independent',
1717 'Programming Language :: Python :: 2.7',
18+ 'Programming Language :: Python :: 3',
1819 'Topic :: Office/Business'
1920 ],
2021 keywords=['CSV', 'crosstab', 'normalized', 'SQLite', 'table', 'data'],
diff -r 96963d568dbc -r 540e3e292b79 xtab/xtab.py
--- a/xtab/xtab.py Sun Aug 26 14:07:00 2018 -0700
+++ b/xtab/xtab.py Tue Mar 19 21:39:47 2019 -0700
@@ -43,8 +43,8 @@
4343 #=====================================================================================
4444
4545
46-_version = "0.10.1"
47-_vdate = "2018-08-21"
46+_version = "1.0.0"
47+_vdate = "2019-03-19"
4848
4949 import sys
5050 import os
@@ -185,7 +185,10 @@
185185 any subsequent parsing to be done by other programs (e.g., R).
186186 """
187187 multiple_vals = False # A flag indicating whether or not multiple values were found for a single crosstab cell
188- outfile = open(outfilename, "wb") # The csv module adds an extra <CR> if "wt" is specified
188+ if sys.version_info < (3,0,0):
189+ outfile = open(outfilename, "wb") # The Py2 csv module adds an extra <CR> if "wt" is specified
190+ else:
191+ outfile = open(outfilename, "w")
189192 csvout = csv.writer(outfile)
190193 reportable_errors = 0
191194
@@ -304,10 +307,6 @@
304307 sqlcmd = "SELECT %s FROM %s WHERE %s" % (",".join(xtab_datanames), tablename, " AND ".join(selcond))
305308 if sql_reporter:
306309 sql_reporter.log(logging.INFO, "%s" % sqlcmd)
307- # <Debugging>
308- #print(sqlcmd)
309- #return
310- # </Debugging>
311310 data_vals = sqldb.execute(sqlcmd).fetchall()
312311 if sql_reporter:
313312 for r in data_vals:
@@ -397,7 +396,7 @@
397396 """
398397 dialect = csv.Sniffer().sniff(open(data_fn, "rt").readline())
399398 inf = csv.reader(open(data_fn, "rt"), dialect)
400- column_names = inf.next()
399+ column_names = next(inf)
401400 if sqlite_fn == None:
402401 conn = sqlite3.connect(":memory:")
403402 else:
@@ -423,8 +422,8 @@
423422
424423 def print_help():
425424 """Print a program description and brief usage instructions to the console."""
426- print "xtab %s %s -- Cross-tabulates data." % (_version, _vdate)
427- print __help_msg
425+ print("xtab %s %s -- Cross-tabulates data." % (_version, _vdate))
426+ print(__help_msg)
428427
429428
430429 def get_opts(arglist):
@@ -460,90 +459,90 @@
460459 """Read and interpret the command-line arguments and options, and carry out
461460 the appropriate actions."""
462461 args = get_opts(sys.argv)
463- if len(args) == 0 or args.has_key('-h') or args.has_key('--help'):
462+ if len(args) == 0 or '-h' in args or '--help' in args:
464463 print_help()
465464 sys.exit(0)
466465 badopts = [ o for o in args.keys() if o not in ['-i', '-o', '-r',
467466 '-c', '-v', '-d', '-d1', '-d2', '-d3', '-d4', '-f', '-k', '-s', '-t',
468467 '-n', '-e', '-q'] ]
469468 if len(badopts) > 0:
470- raise ValueError, "Unrecognized option(s): %s" % ", ".join(badopts)
471- if args.has_key('-i'):
469+ raise ValueError("Unrecognized option(s): %s" % ", ".join(badopts))
470+ if '-i' in args:
472471 if len(args['-i']) == 0:
473- raise ValueError, _errmsg_noinfile
472+ raise ValueError(_errmsg_noinfile)
474473 infilename = args['-i'][0]
475474 if not os.path.exists(infilename):
476- raise ValueError, "%s (%s)" % (_errmsg_badinfile, infilename)
475+ raise ValueError("%s (%s)" % (_errmsg_badinfile, infilename))
477476 else:
478- raise ValueError, _errmsg_noinfile
477+ raise ValueError(_errmsg_noinfile)
479478 #
480- if args.has_key('-o'):
479+ if '-o' in args:
481480 if len(args['-o']) == 0:
482- raise ValueError, _errmsg_nooutfile
481+ raise ValueError(_errmsg_nooutfile)
483482 outfilename = args['-o'][0]
484483 else:
485- raise ValueError, _errmsg_nooutfile
484+ raise ValueError(_errmsg_nooutfile)
486485 #
487- if args.has_key('-r'):
486+ if '-r' in args:
488487 if len(args['-r']) == 0:
489- raise ValueError, _errmsg_norowheaders
488+ raise ValueError(_errmsg_norowheaders)
490489 rowheaders = args['-r']
491490 else:
492- raise ValueError, _errmsg_norowheaders
491+ raise ValueError(_errmsg_norowheaders)
493492 #
494- if args.has_key('-c'):
493+ if '-c' in args:
495494 if len(args['-c']) == 0:
496- raise ValueError, _errmsg_nocolumheaders
495+ raise ValueError(_errmsg_nocolumheaders)
497496 columnheaders = args['-c']
498497 else:
499- raise ValueError, _errmsg_nocolumheaders
498+ raise ValueError(_errmsg_nocolumheaders)
500499 #
501- if args.has_key('-v'):
500+ if '-v' in args:
502501 if len(args['-v']) == 0:
503- raise ValueError, _errmsg_nocellcolumns
502+ raise ValueError(_errmsg_nocellcolumns)
504503 cellvalues = args['-v']
505504 else:
506- raise ValueError, _errmsg_nocellcolumns
505+ raise ValueError(_errmsg_nocellcolumns)
507506 #
508507 hdr_opt = hdrs_1
509- if args.has_key('-d') or args.has_key('-d2'):
508+ if '-d' in args or '-d2' in args:
510509 hdr_opt = hdrs_2
511- if args.has_key('-d3'):
510+ if '-d3' in args:
512511 hdr_opt = hdrs_many
513- if args.has_key('-d4'):
512+ if '-d4' in args:
514513 hdr_opt = hdrs_labeled
515- file_db = args.has_key('-f')
516- keep_file_db = args.has_key('-k')
514+ file_db = '-f' in args
515+ keep_file_db = '-k' in args
517516 tablename = 'src'
518- if args.has_key('-t'):
517+ if '-t' in args:
519518 if len(args['-t']) == 1:
520519 tablename = args['-t'][0]
521520 nullfill = None
522- if args.has_key('-n'):
521+ if '-n' in args:
523522 if len(args['-n']) == 1:
524523 nullfill = args['-n'][0]
525- sort_alpha = args.has_key('-s')
524+ sort_alpha = '-s' in args
526525 #
527526 # Set up logging
528527 #logging.basicConfig(level=logging.INFO, filemode="w", filename='')
529528 err_logger = None
530529 sql_logger = None
531530 error_file = None
532- if args.has_key('-e'):
531+ if '-e' in args:
533532 err_logger = logging.getLogger("err")
534533 err_logger.setLevel(logging.WARNING)
535534 if len(args['-e']) == 0:
536535 err_logger.addHandler(logging.StreamHandler())
537536 else:
538537 if len(args['-e']) > 1:
539- raise ValueError, _errmsg_baderrlogfile
538+ raise ValueError(_errmsg_baderrlogfile)
540539 error_file = args['-e'][0]
541540 del_file(error_file)
542541 file_logger = logging.FileHandler(error_file, "w")
543542 err_logger.addHandler(file_logger)
544- if args.has_key('-q'):
545- if len(args['-q']) <> 1:
546- raise ValueError, _errmsg_badsqllogfile
543+ if '-q' in args:
544+ if len(args['-q']) != 1:
545+ raise ValueError(_errmsg_badsqllogfile)
547546 sql_logger = logging.getLogger("sql")
548547 sql_logger.setLevel(logging.INFO)
549548 sql_logger.addHandler(logging.FileHandler(args['-q'][0], "w"))
@@ -561,9 +560,9 @@
561560 if __name__=='__main__':
562561 try:
563562 main()
564- except SystemExit, x:
563+ except SystemExit as x:
565564 sys.exit(x)
566- except ValueError, e:
565+ except ValueError as e:
567566 sys.stderr.write("%s\n" % str(e))
568567 sys.exit(1)
569568 except Exception:
Show on old repository browser