comparison scripts/zeiterfassung.py @ 380:20fde79f8e12

Move all scripts in a common scripts directory Currently console scripts were kept in several directories. Now use a common directory for all scripts.
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 05 Jan 2015 10:54:20 +0100
parents getan/contrib/zeiterfassung.py@1b190fa27482
children b8cd8751cba0
comparison
equal deleted inserted replaced
379:47890f38e558 380:20fde79f8e12
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # zeiterfassung
5 # -------------
6 # (c) 2008 by Sascha L. Teichmann <sascha.teichmann@intevation.de>
7 # (c) 2011, 2012 by Björn Ricks <bjoern.ricks@intevation.de>
8 #
9 # Simple script which generates lines for zeiterfassung.txt files.
10 #
11 # This is Free Software licensed under the terms of GPLv3 or later.
12 # For details see LICENSE coming with the source of 'getan'.
13 #
14 import sys
15 import getopt
16 import codecs
17 import locale
18
19 from datetime import datetime, timedelta
20
21 from getan.template import render
22
23 DEFAULT_DATABASE = "time.db"
24
25 ZEITERFASSUNG_TEMPLATE = "zeiterfassung"
26
27 USAGE = '''usage: %s <options>
28 with <options>
29 [--user=|-u <user>] : Name of user, default: $USER
30 [--database=|-d <database>]: getan database, default: time.db
31 [--project=|-p <key>] : Key of output project, default: all
32 [--encoding=|-e encoding] : encoding of output, default: none
33 [--week=]|-w <week>] : week of year
34 [--year=]|-y <year>] : year
35 [--list|-l] : list all projects
36 [--help|-h] : This text
37 [--emtpy|-m] : show empty projects
38 [--lastweek|-c] : entries of last working week'''
39
40
41 def usage(exit_code=0):
42 print USAGE % sys.argv[0]
43 sys.exit(exit_code)
44
45
46 def main():
47
48 database = DEFAULT_DATABASE
49 user = None
50 list_projects = False
51 project = None
52 encoding = None
53 week = None
54 year = None
55 empty_proj = False
56 database = None
57 template = ZEITERFASSUNG_TEMPLATE
58
59 opts, args = getopt.getopt(
60 sys.argv[1:],
61 'd:u:p:e:hl:w:y:mc',
62 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=',
63 'year=', 'empty', 'lastweek'])
64
65 for opt, val in opts:
66 if opt in ("--database", "-d"):
67 database = val
68 elif opt in ("--user", "-u"):
69 user = val
70 elif opt in ("--project", "-p"):
71 project = val
72 elif opt in ("--encoding", "-e"):
73 encoding = val
74 elif opt in ("--help", "-h"):
75 usage()
76 elif opt in ("--list", "-l"):
77 list_projects = True
78 elif opt in ("--year", "-y"):
79 year = val
80 elif opt in ("--week", "-w"):
81 week = int(val)
82 elif opt in ("--lastweek", "-c") and not week:
83 week = (datetime.now() - timedelta(7)).isocalendar()[1]
84 elif opt in ("--empty", "-m"):
85 empty_proj = True
86
87 if not encoding:
88 encoding = locale.getdefaultlocale()[1]
89
90 Writer = codecs.getwriter(encoding)
91 sys.stdout = Writer(sys.stdout)
92
93 print render(user=user, database=database, week=week, year=year,
94 template=template, project=project, empty_projects=empty_proj)
95
96
97 if __name__ == '__main__':
98 main()
99
100 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)