1
|
|
|
# json parser implementation |
2
|
|
|
from juggler import * |
|
|
|
|
3
|
|
|
import json, re, math |
|
|
|
|
4
|
|
|
|
5
|
|
|
class DictJugglerTaskDepends(JugglerTaskDepends): |
|
|
|
|
6
|
|
|
def load_from_issue(self, issue): |
7
|
|
|
""" |
8
|
|
|
Args: |
9
|
|
|
issue["depends"] - a list of identifiers that this task depends on |
10
|
|
|
""" |
11
|
|
|
if "depends" in issue: |
|
|
|
|
12
|
|
|
if isinstance(issue["depends"], str): |
13
|
|
|
self.set_value([x for x in re.findall(r"[\w']+", issue["depends"])]) |
14
|
|
|
else: self.set_value([x for x in issue["depends"]]) |
15
|
|
|
|
16
|
|
|
class DictJugglerTaskEffort(JugglerTaskEffort): |
|
|
|
|
17
|
|
|
UNIT = "h" |
18
|
|
|
def load_from_issue(self, issue): |
19
|
|
|
if "effort" in issue: self.set_value(math.ceil(issue["effort"])) |
|
|
|
|
20
|
|
|
|
21
|
|
|
class DictJugglerTaskAllocate(JugglerTaskAllocate): |
|
|
|
|
22
|
|
|
def load_from_issue(self, issue): |
23
|
|
|
if "allocate" in issue: self.set_value(issue["allocate"]) |
|
|
|
|
24
|
|
|
else: self.set_value("me") # stub! |
25
|
|
|
|
26
|
|
|
class DictJugglerTask(JugglerTask): |
|
|
|
|
27
|
|
|
def load_default_properties(self, issue): |
28
|
|
|
self.set_property(DictJugglerTaskDepends(issue)) |
29
|
|
|
self.set_property(DictJugglerTaskEffort(issue)) |
30
|
|
|
self.set_property(DictJugglerTaskAllocate(issue)) |
31
|
|
|
def load_from_issue(self, issue): |
32
|
|
|
self.set_id(issue["id"]) |
33
|
|
|
if "summary" in issue: self.summary = issue["summary"] |
|
|
|
|
34
|
|
|
|
35
|
|
|
class DictJuggler(GenericJuggler): |
|
|
|
|
36
|
|
|
""" a simple dictionary based format parser """ |
37
|
|
|
def __init__(self, issues): |
38
|
|
|
self.issues = issues |
39
|
|
|
def load_issues(self): |
40
|
|
|
return self.issues |
41
|
|
|
def create_task_instance(self, issue): |
|
|
|
|
42
|
|
|
return DictJugglerTask(issue) |
43
|
|
|
|
44
|
|
|
class JsonJuggler(DictJuggler): |
45
|
|
|
def __init__(self, json_issues): |
|
|
|
|
46
|
|
|
self.issues = json.loads(json_issues) |
47
|
|
|
def toJSON(self): |
48
|
|
|
# TODO HERE: decode tasks back to JSON |
49
|
|
|
for t in self.walk(JugglerTask): |
|
|
|
|
50
|
|
|
for i in self.issues: |
51
|
|
|
if t.get_id() == i["id"]: |
52
|
|
|
i["booking"] = t.walk(JugglerBooking)[0].decode()[0].isoformat() |
|
|
|
|
53
|
|
|
return json.dumps(self.issues, sort_keys=True, indent=4, separators=(',', ': ')) |
54
|
|
|
|
|
|
|
|
55
|
|
|
|