comparison scripts/getan-eval.py @ 463:24ccca2442b1

optparse to argparse Migration for scripts/getan-eval.py.
author Magnus Schieder <mschieder@intevation.de>
date Mon, 30 Apr 2018 12:13:35 +0200
parents 8d03d7ada7e1
children 59d9c5840273
comparison
equal deleted inserted replaced
462:52398469cacc 463:24ccca2442b1
9 import codecs 9 import codecs
10 import locale 10 import locale
11 import sys 11 import sys
12 12
13 from datetime import date, datetime, timedelta 13 from datetime import date, datetime, timedelta
14 from optparse import OptionParser 14 import argparse
15 15
16 from getan.template import render 16 from getan.template import render
17 17
18 18
19 def main(): 19 def main():
20 parser = OptionParser() 20 usage='getan-eval.py [options]'
21 parser.add_option("-d", "--database", dest="database", 21 parser = argparse.ArgumentParser(prog='getan', usage=usage)
22 help="getan database", metavar="DATABASE")
23 parser.add_option("-t", "--template", dest="template", metavar="TEMPLATE",
24 help="name of getan template")
25 parser.add_option("-u", "--user", dest="user", help="name of user")
26 parser.add_option("-p", "--project", dest="project",
27 help="key of output project")
28 parser.add_option("-w", "--week", type="int", dest="week",
29 help="week of year")
30 parser.add_option("-y", "--year", type="int", dest="year", help="year")
31 parser.add_option("-c", "--lastweek", dest="lastweek",
32 help="entries of last working week",
33 action="store_true")
34 parser.add_option("-m", "--empty", dest="empty",
35 help="show projects without an entries",
36 action="store_true")
37 parser.add_option("--encoding", dest="encoding",
38 help="encoding of output", metavar="ENCODING")
39 22
40 (options, args) = parser.parse_args() 23 parser.add_argument('-d', '--database', dest='database',metavar="DATABASE",
24 help='metavar="DATABASE')
25 parser.add_argument('-t', '--template', dest='template',
26 metavar='TEMPLATE', help='name of getan template')
27 parser.add_argument('-u', '--user', dest='user', help='name of user')
28 parser.add_argument('-p', '--project', dest='project',
29 help='key of output project')
30 parser.add_argument('-w', '--week', type=int, dest='week',
31 help='week of year')
32 parser.add_argument('-y', '--year', type=int, dest='year', help='year')
33 parser.add_argument('-c', '--lastweek', dest='lastweek',
34 help='entries of last working week',
35 action='store_true')
36 parser.add_argument('-m', '--empty', dest='empty',
37 help='show projects without an entries',
38 action="store_true")
39 parser.add_argument('--encoding', dest='encoding',
40 help='encoding of output', metavar='ENCODING')
41 41
42 if options.lastweek: 42 args = parser.parse_args()
43
44 if args.lastweek:
43 week = (datetime.now() - timedelta(7)).isocalendar()[1] 45 week = (datetime.now() - timedelta(7)).isocalendar()[1]
44 year = int(date.today().strftime("%Y")) 46 year = int(date.today().strftime("%Y"))
45 else: 47 else:
46 year = options.year 48 year = args.year
47 week = options.week 49 week = args.week
48 50
49 template_name = options.template or "wochenbericht" 51 template_name = args.template or "wochenbericht"
50 52
51 if not options.encoding: 53 if not args.encoding:
52 encoding = locale.getdefaultlocale()[1] or "utf-8" 54 encoding = locale.getdefaultlocale()[1] or "utf-8"
53 55
54 Writer = codecs.getwriter(encoding) 56 Writer = codecs.getwriter(encoding)
55 sys.stdout = Writer(sys.stdout) 57 sys.stdout = Writer(sys.stdout)
56 58
57 user = None 59 user = None
58 if options.user: 60 if args.user:
59 user = options.user.decode(encoding) 61 user = args.user.decode(encoding)
60 62
61 print render(database=options.database, user=user, 63 print render(database=args.database, user=user,
62 template=template_name, year=year, week=week, 64 template=template_name, year=year, week=week,
63 project=options.project, empty_projects=options.empty) 65 project=args.project, empty_projects=args.empty)
64 66
65 67
66 if __name__ == '__main__': 68 if __name__ == '__main__':
67 main() 69 main()
68 70
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)