-
Notifications
You must be signed in to change notification settings - Fork 1
/
people.py
75 lines (62 loc) · 2.37 KB
/
people.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import ldap
import orgchartwriter
class Person(object):
managerattr = None
def __init__(self, res, l):
# res = ldap search result tuple
self.dn = res[0]
self.uid = res[1]['uid'][0]
self.manager = None
self.res = res
# No children by default
self.children = []
self.l = l
self.filterchildren = "(%s=%s)" % (self.managerattr, self.dn)
self._print_node()
self.ex_contract = self.res[1]['rhatPersonType'][0] == 'Ex-contingent Worker'
def log(self, msg):
o = orgchartwriter.OrgChartWriter()
o.dot(msg)
def _print_node(self):
pass
def find_children(self):
pass
def has_children(self):
# Do a search for potential children, return that
return self.l.search(filterstr=self.filterchildren)
class Employee(Person):
def _print_node(self):
shape="ellipse"
self.log("node [shape=%s]; \"%s\";" % (shape, self.uid))
class Manager(Person):
def _print_node(self):
shape="triangle"
self.log("node [shape=%s]; \"%s\";" % (shape, self.uid))
def find_children(self):
# self.log("finding children")
children = self.has_children()
if children:
# self.log("I have children")
# Any results returned?
for child in children:
child_name = child[1]['uid'][0]
# self.log("Inspecting child: %s" % child_name)
# Check if they have children themselves
c = Person(child, self.l)
if c.ex_contract:
# This is an ex-contractor account, don't show it
continue
if c.has_children():
# self.log("%s has children" % c.uid)
# OK, they do, so they're a manager
m = Manager(child, self.l)
self.children.append(m)
# self.log("Calling %s's find_children() method" % child_name)
m.find_children()
else:
# Nope, they're just a leaf-node
self.children.append(Employee(child, self.l))
self.print_dot()
def print_dot(self):
children_names = [ c.uid for c in self.children]
self.log("\"%s\" -> {%s};" % (self.uid, '"{0}"'.format('" "'.join(children_names))))