-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBSample.py
More file actions
98 lines (79 loc) · 3.02 KB
/
Copy pathDBSample.py
File metadata and controls
98 lines (79 loc) · 3.02 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import create_session
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import contains_eager, joinedload
from sqlite3 import dbapi2 as sqlite
from datetime import datetime
dsn = '/home/aj/PycharmProjects/Lights/Lights/Lights.sqlite'
#Create and engine and get the metadata
Base = declarative_base()
engine = create_engine('sqlite:////{}'.format(dsn), module=sqlite)
metadata = MetaData(bind=engine)
class CtlrModel(Base):
__table__ = Table('CtlrModel', metadata, autoload=True)
class Controller(Base):
__table__ = Table('Controller', metadata, autoload=True)
model = relationship("CtlrModel", backref="controller")
class CtlrConnector(Base):
__table__ = Table('CtlrConnector', metadata, autoload=True)
controller = relationship("Controller", backref="connectors")
connection = relationship("Connection",
backref=backref("connector", uselist=False))
class Display(Base):
__table__ = Table('Display', metadata, autoload=True)
class Connection(Base):
__table__ = Table('Connection', metadata, autoload=True)
display = relationship("Display", backref="connection")
# propIn = relationship("Prop",
# foreign_keys="Connection.Input_PropID",
# backref=backref("input", uselist=False))
# propOut = relationship("Prop",
# foreign_keys="Connection.Output_PropID",
# backref=backref("output",uselist=False))
# connector = relationship("CtlrConnector",
# backref=backref("connection", uselist=False))
class Prop(Base):
__table__ = Table('Prop', metadata, autoload=True)
item = relationship("CatalogItem", backref="prop")
propIn = relationship("Connection",
foreign_keys="Connection.Input_PropID",
backref=backref("input", uselist=False))
propOut = relationship("Connection",
foreign_keys="Connection.Output_PropID",
backref=backref("output",uselist=False))
#keywords = association_proxy('kw', 'keyword')
class CatalogItem(Base):
__table__ = Table('CatalogItem', metadata, autoload=True)
if __name__ == '__main__':
msg = "Prop: {}-{}, Controller: {} {} - {}/{}"
#Create a session to use the tables
session = create_session(bind=engine)
controllers = session.query(Controller).filter(Connection.DisplayID == 1).all()
#props = session.query(Prop).filter(Connection.DisplayID == 1).all()
#q = session.query(Prop).all()
for item in q:
if item.PixelsAllocated:
allocated = item.Strings * item.PixelsAllocated
else:
allocated = item.Strings * item.Pixels
'''
if item.controllers:
for controller in item.controllers:
print msg.format(item.Name,
item.Version,
controller.controller.Name,
controller.controller.model.Model,
item.Strings,
allocated
)
else:
'''
print msg.format(item.Name,
item.Version,
"UNASSIGNED",
"",
item.Strings,
allocated
)