-
Notifications
You must be signed in to change notification settings - Fork 2
/
Views.py
69 lines (56 loc) · 2.48 KB
/
Views.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
# View Data Source diagram
# Standard python libraries
from contextlib import contextmanager #required for the cond function
# Local python libraries
import pydiagrams.Diagram as diagram
##########################################################################
# Item Classes
class DatabaseObjectItem(diagram.Item):
def __init__(self, label, shape, **attrs):
attrs.update({'shape':shape})
diagram.Item.__init__(self, label, **attrs)
# Stores the objects id's that SEND DATA to this instance
# eg: if this were a view, the sources would be the tables/views th
self.sources = []
def add_source(self, source_item):
#print 'add_source "{}" << "{}"'.format(self.Label,source_item.Label)
assert isinstance(source_item, DatabaseObjectItem), "source_item is not a DatabaseObjectItem"
self.sources.append(source_item)
source_item.link(self) # Create a link from the source_item to this
# << : Set sources for this item
def __lshift__(self, i2):
if type(i2) == list:
for i in i2:
self.add_source(i)
elif isinstance(i2, DatabaseObjectItem):
self.add_source(i2)
else:
raise ValueError
# ========================================================
class ViewDiagram(diagram.DiagramBase):
nodeTypes = {
'Table' : 'Table',
'View' : 'parallelogram',
'Package' : 'invhouse',
'File' : 'folder',
'Integration' : 'invtrapezium',
'System' : 'ellipse',
'Task' : 'cds'
}
def __init__(self, helper, filename=None, label=None, **attrs):
diagram.DiagramBase.__init__(self, helper, filename, label, **attrs)
def make_method(shape):
def make_item(self, label, **attrs):
return self.add_item(DatabaseObjectItem(label, shape, **attrs))
return make_item
# Dynamically create methods in ViewDiagram that create Item
for (method, shape) in list(ViewDiagram.nodeTypes.items()):
setattr(ViewDiagram, method, make_method(method))
# ========================================================
class ViewContext(diagram.Context):
def __init__(self, helper, filename=None, **attrs):
self.diagram = ViewDiagram(helper, filename, **attrs)
# ========================================================
class Items(diagram.Items):
def __init__(self, *items):
super(Items, self).__init__(*items)