-
Notifications
You must be signed in to change notification settings - Fork 1
/
orgchartwriter.py
42 lines (34 loc) · 988 Bytes
/
orgchartwriter.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
"""
Simple module for writing output to a specified location
"""
import sys
class OrgChartWriter(object):
OUTPUT="org_chart.dot"
WRITER=None
APPEND="\n"
def __init__(self):
if not OrgChartWriter.WRITER:
if OrgChartWriter.OUTPUT == '-':
OrgChartWriter.OUTPUT = sys.stdout
OrgChartWriter.WRITER = sys.stdout
else:
OrgChartWriter.WRITER = open(self.OUTPUT, 'w')
self.WRITER = OrgChartWriter.WRITER
def write(self, msg):
try:
self.WRITER.write(msg + self.APPEND)
except Exception, e:
print "Error in write():"
print str(e)
else:
self.flush()
def flush(self):
self.WRITER.flush()
def begin_output(self):
out = "digraph org_chart {"
self.write(out)
def dot(self, out):
self.write(" " + out)
def end_output(self):
out = "}"
self.write(out)