Mercurial > getan
changeset 355:bc12acbff143
Add methods to return a workpackage [wp] from a Entry description
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 03 Mar 2014 14:28:39 +0100 |
parents | 4f5094f3f615 |
children | 45d97d47a9fe |
files | getan/project.py |
diffstat | 1 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/getan/project.py Mon Mar 03 14:27:36 2014 +0100 +++ b/getan/project.py Mon Mar 03 14:28:39 2014 +0100 @@ -9,6 +9,7 @@ # For details see LICENSE coming with the source of 'getan'. import locale +import re from datetime import datetime, timedelta @@ -81,6 +82,8 @@ class Entry(object): + WORKPACKAGE = re.compile("^\[(\w*)(\s|\])") + def __init__(self, id, project_id, start, end, desc): self.id = id self.project_id = project_id @@ -93,9 +96,25 @@ if self.desc and not isinstance(self.desc, unicode): self.desc = unicode(self.desc, locale.getpreferredencoding()) - def duration(self): + c = self.desc + m = self.WORKPACKAGE.match(c) + if m: + self.workpackage = m.group(1) + c = c[m.end():].strip() + else: + self.workpackage = "----" + c = c.replace('\x1b', '') + self.comment = c + + def get_workpackage(self): + return self.workpackage + + def get_duration(self): return (self.end - self.start) + def get_comment(self): + return self.comment + def __str__(self): return ("[%s | %s | %s | %s | %s]" % (self.id, self.project_id, self.start, self.end, self.desc))