1 | # json parser implementation |
||
2 | from juggler import * |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | import json, re, math |
||
0 ignored issues
–
show
|
|||
4 | import dateutil.parser |
||
0 ignored issues
–
show
|
|||
5 | |||
6 | class DictJugglerTaskDepends(JugglerTaskDepends): |
||
7 | def load_from_issue(self, issue): |
||
8 | """ |
||
9 | Args: |
||
10 | issue["depends"] - a list of identifiers that this task depends on |
||
11 | """ |
||
12 | if "depends" in issue: |
||
0 ignored issues
–
show
|
|||
13 | # TODO HERE: remove ID normalization! |
||
14 | if isinstance(issue["depends"], str) or isinstance(issue['depends'], unicode): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
15 | self.set_value([int(x) for x in re.findall(r"[\w']+", issue["depends"])]) |
||
16 | # TODO check for list, else add idfr |
||
17 | else: self.set_value([int(x) for x in issue["depends"]]) |
||
18 | |||
19 | class DictJugglerTaskPriority(JugglerTaskPriority): |
||
20 | def load_from_issue(self, issue): |
||
21 | if "priority" in issue: self.set_value(int(issue["priority"])) |
||
0 ignored issues
–
show
|
|||
22 | |||
0 ignored issues
–
show
|
|||
23 | class DictJugglerTaskStart(JugglerTaskStart): |
||
24 | def load_from_issue(self, issue): |
||
25 | if "start" in issue: |
||
0 ignored issues
–
show
|
|||
26 | if isinstance(issue["start"], str) or isinstance(issue['start'], unicode): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
27 | self.set_value(dateutil.parser.parse(issue["start"])) |
||
28 | else: |
||
29 | self.set_value(issue["start"]) |
||
30 | |||
0 ignored issues
–
show
|
|||
31 | class DictJugglerTaskEffort(JugglerTaskEffort): |
||
32 | UNIT = "h" |
||
33 | def load_from_issue(self, issue): |
||
34 | if "effort" in issue: self.set_value(math.ceil(issue["effort"])) |
||
0 ignored issues
–
show
|
|||
35 | |||
36 | class DictJugglerTaskAllocate(JugglerTaskAllocate): |
||
37 | def load_from_issue(self, issue): |
||
0 ignored issues
–
show
Signature differs from overridden 'load_from_issue' method
It is generally a good practice to use signatures that are compatible with the Liskov substitution principle. This allows to pass instances of the child class anywhere where the instances of the super-class/interface would be acceptable. ![]() |
|||
38 | if "allocate" in issue: alloc = issue["allocate"] |
||
0 ignored issues
–
show
|
|||
39 | else: alloc = "me" # stub! |
||
40 | self.set_value(alloc) |
||
0 ignored issues
–
show
|
|||
41 | src.walk(JugglerSource)[0].set_property(DictJugglerResource(issue)) |
||
42 | |||
43 | class DictJugglerTask(JugglerTask): |
||
44 | def load_default_properties(self, issue): |
||
0 ignored issues
–
show
Signature differs from overridden 'load_default_properties' method
It is generally a good practice to use signatures that are compatible with the Liskov substitution principle. This allows to pass instances of the child class anywhere where the instances of the super-class/interface would be acceptable. ![]() |
|||
45 | self.set_property(DictJugglerTaskDepends(issue)) |
||
46 | self.set_property(DictJugglerTaskEffort(issue)) |
||
47 | self.set_property(DictJugglerTaskAllocate(issue)) |
||
48 | self.set_property(DictJugglerTaskStart(issue)) |
||
49 | self.set_property(DictJugglerTaskPriority(issue)) |
||
50 | def load_from_issue(self, issue): |
||
51 | self.set_id(issue["id"]) |
||
52 | if "summary" in issue: self.summary = issue["summary"] |
||
0 ignored issues
–
show
|
|||
53 | |||
54 | class DictJuggler(GenericJuggler): |
||
0 ignored issues
–
show
|
|||
55 | """ a simple dictionary based format parser """ |
||
56 | def __init__(self, issues): |
||
0 ignored issues
–
show
The
__init__ method of the super-class GenericJuggler is not called.
It is generally advisable to initialize the super-class by calling its class SomeParent:
def __init__(self):
self.x = 1
class SomeChild(SomeParent):
def __init__(self):
# Initialize the super class
SomeParent.__init__(self)
![]() |
|||
57 | self.issues = issues |
||
58 | def load_issues(self): |
||
59 | return self.issues |
||
60 | def create_task_instance(self, issue): |
||
61 | return DictJugglerTask(issue) |
||
62 | def create_jugglersource_instance(self): |
||
63 | global src |
||
0 ignored issues
–
show
|
|||
64 | src = DictJugglerSource() |
||
65 | return src |
||
66 | |||
67 | class DictJugglerSource(JugglerSource): |
||
68 | def load_default_properties(self, issue = None): |
||
0 ignored issues
–
show
|
|||
69 | self.set_property(JugglerProject()) |
||
70 | # self.set_property(DictJugglerResource()) # define no resource |
||
71 | self.set_property(JugglerIcalreport()) |
||
72 | |||
0 ignored issues
–
show
|
|||
73 | class DictJugglerResource(JugglerResource): |
||
74 | def load_from_issue(self, issue): |
||
75 | if "allocate" in issue: |
||
76 | self.set_id(issue["allocate"]) |
||
77 | self.set_value(issue["allocate"]) |
||
78 | |||
79 | class JsonJuggler(DictJuggler): |
||
0 ignored issues
–
show
|
|||
80 | def __init__(self, json_issues): |
||
0 ignored issues
–
show
The
__init__ method of the super-class DictJuggler is not called.
It is generally advisable to initialize the super-class by calling its class SomeParent:
def __init__(self):
self.x = 1
class SomeChild(SomeParent):
def __init__(self):
# Initialize the super class
SomeParent.__init__(self)
![]() |
|||
81 | self.issues = json.loads(json_issues) |
||
82 | def toJSON(self): |
||
83 | for t in self.walk(JugglerTask): |
||
84 | for i in self.issues: |
||
85 | if t.get_id() == i["id"]: |
||
86 | i["booking"] = t.walk(JugglerBooking)[0].decode()[0].isoformat() |
||
87 | return json.dumps(self.issues, sort_keys=True, indent=4, separators=(',', ': ')) |
||
88 | |||
0 ignored issues
–
show
|
|||
89 |