Download:
child 140:fa50e7dd9d91
parent 138:0e226445b215
139:8155ebf7d128
Anton Shestakov <av6@dwimlabs.net>, Wed, 13 Jul 2016 18:25:43 +0800
incoming: support --help and --debug, and read from stdin by default

1 файлов изменено, 16 вставок(+), 5 удалений(-) [+]
incoming.py file | annotate | diff | comparison | revisions
--- a/incoming.py Wed Jul 13 16:54:30 2016 +0800
+++ b/incoming.py Wed Jul 13 18:25:43 2016 +0800
@@ -1,10 +1,11 @@
#!/usr/bin/env python
from __future__ import absolute_import
-import fileinput
import logging
import os
import re
+import sys
+from argparse import ArgumentParser, FileType
from datetime import datetime
from urlparse import urlparse
@@ -200,13 +201,23 @@
def main():
+ parser = ArgumentParser()
+ parser.add_argument(
+ 'file', type=FileType('r'), nargs='?', default=sys.stdin,
+ help='file to read from (if - or not specified, read from stdin)')
+ parser.add_argument(
+ '-d', '--debug', action='store_true',
+ help='enable debugging output')
+ args = parser.parse_args()
+
database.init(rel('database.sqlite'))
database.connect()
database.create_tables([Project, Change, Check], safe=True)
- logger = logging.getLogger('peewee')
- logger.setLevel(logging.DEBUG)
- logger.addHandler(logging.StreamHandler())
- insert_check(list(fileinput.input()))
+ if args.debug:
+ logger = logging.getLogger('peewee')
+ logger.setLevel(logging.DEBUG)
+ logger.addHandler(logging.StreamHandler())
+ insert_check(args.file)
database.close()