annotate getan/project.py @ 311:349b4571e120

Fix codingstyle for pep8
author Björn Ricks <bjoern.ricks@intevation.de>
date Fri, 11 Oct 2013 12:06:42 +0200
parents 700fc5416c32
children 2e7885dc6669
rev   line source
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
1 #!/usr/bin/env python
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
3 #
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
4 # (c) 2008, 2009, 2010 by
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
5 # Sascha L. Teichmann <sascha.teichmann@intevation.de>
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
6 # Ingo Weinzierl <ingo.weinzierl@intevation.de>
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
7 #
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
8 # This is Free Software licensed unter the terms of GPLv3 or later.
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
9 # For details see LICENSE coming with the source of 'getan'.
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
10
145
ccd47a2d37a6 Carefully handle non unicode strings for urwid
Björn Ricks <bjoern.ricks@intevation.de>
parents: 137
diff changeset
11 import locale
ccd47a2d37a6 Carefully handle non unicode strings for urwid
Björn Ricks <bjoern.ricks@intevation.de>
parents: 137
diff changeset
12
293
700fc5416c32 Remove obsolete import
Björn Ricks <bjoern.ricks@intevation.de>
parents: 147
diff changeset
13 from datetime import datetime
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
14
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
15
136
92b7582b8f44 Use new style classes
Björn Ricks <bjoern.ricks@intevation.de>
parents: 135
diff changeset
16 class Project(object):
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
17
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
18 def __init__(self, id, key, desc, total):
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
19 self.id = id
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
20 self.key = key
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
21 self.desc = desc
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
22 self.entries = []
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
23 self.total = total
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
24 self.start = None
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
25 self.stop = None
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
26
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
27 def year(self):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
28 total = 0
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
29 now = datetime.now()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
30 for entry in self.entries:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
31 start = entry.start
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
32 if start.year == now.year:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
33 total += (entry.end - start).seconds
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
34 return total
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
35
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
36 def month(self):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
37 total = 0
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
38 now = datetime.now()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
39 for entry in self.entries:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
40 start = entry.start
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
41 if start.month == now.month and start.year == now.year:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
42 total += (entry.end - start).seconds
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
43 return total
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
44
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
45 def week(self):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
46 total = 0
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
47 now = datetime.now()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
48 tweek = now.strftime('%W')
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
49 for entry in self.entries:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
50 start = entry.start
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
51 if start.strftime('%W') == tweek and start.year == now.year:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
52 total += (entry.end - start).seconds
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
53 return total
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
54
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
55 def day(self):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
56 total = 0
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
57 now = datetime.now()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
58 for entry in self.entries:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
59 start = entry.start
135
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 23
diff changeset
60 if start.month == now.month and start.year == now.year \
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
61 and start.day == now.day:
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
62 total += (entry.end - start).seconds
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
63 return total
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
64
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
65
136
92b7582b8f44 Use new style classes
Björn Ricks <bjoern.ricks@intevation.de>
parents: 135
diff changeset
66 class Entry(object):
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
67
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
68 def __init__(self, id, project_id, start, end, desc):
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
69 self.id = id
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
70 self.project_id = project_id
311
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
71 self.start = start
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
72 self.end = end
349b4571e120 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 293
diff changeset
73 self.desc = desc
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
74
145
ccd47a2d37a6 Carefully handle non unicode strings for urwid
Björn Ricks <bjoern.ricks@intevation.de>
parents: 137
diff changeset
75 # carefully handle non unicode string
ccd47a2d37a6 Carefully handle non unicode strings for urwid
Björn Ricks <bjoern.ricks@intevation.de>
parents: 137
diff changeset
76 # urwid seems to have some issue with plain str
147
8cc1f83d32ee Description may be not set
Björn Ricks <bjoern.ricks@intevation.de>
parents: 145
diff changeset
77 if self.desc and not isinstance(self.desc, unicode):
145
ccd47a2d37a6 Carefully handle non unicode strings for urwid
Björn Ricks <bjoern.ricks@intevation.de>
parents: 137
diff changeset
78 self.desc = unicode(self.desc, locale.getpreferredencoding())
ccd47a2d37a6 Carefully handle non unicode strings for urwid
Björn Ricks <bjoern.ricks@intevation.de>
parents: 137
diff changeset
79
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
80 def duration(self):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
81 return (self.end - self.start)
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
82
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
83 def __str__(self):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
84 return ("[%s | %s | %s | %s | %s]" %
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
85 (self.id, self.project_id, self.start, self.end, self.desc))
137
5a4946fd9e6d Update whitespace
Björn Ricks <bjoern.ricks@intevation.de>
parents: 136
diff changeset
86
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
87 # 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)