diff options
author | heather <unknown> | 2011-05-23 01:07:11 -0400 |
---|---|---|
committer | heather <unknown> | 2011-05-23 01:07:11 -0400 |
commit | 308102ac813d8da612405781abcc600c5166f6a4 (patch) | |
tree | db72ad4a004e51d15f54383d09413c2118430265 | |
parent | 2d6bc8dc37e2246f077a05391e51b26f6ce76ea3 (diff) | |
download | d2-308102ac813d8da612405781abcc600c5166f6a4.tar.bz2 d2-308102ac813d8da612405781abcc600c5166f6a4.tar.xz d2-308102ac813d8da612405781abcc600c5166f6a4.zip |
adding occupants that are not in LDAP in occupant table, still need to add them to detail table
-rw-r--r-- | lib/d2/bin/d2_agi_db_setup.py | 47 | ||||
-rw-r--r-- | lib/d2/bin/d2_db_setup.py | 6 |
2 files changed, 51 insertions, 2 deletions
diff --git a/lib/d2/bin/d2_agi_db_setup.py b/lib/d2/bin/d2_agi_db_setup.py index 4cf3602..2df60ef 100644 --- a/lib/d2/bin/d2_agi_db_setup.py +++ b/lib/d2/bin/d2_agi_db_setup.py | |||
@@ -1,4 +1,5 @@ | |||
1 | import argparse | 1 | import argparse |
2 | import hashlib | ||
2 | from d2.config import Config | 3 | from d2.config import Config |
3 | from d2.app.model.static import StaticData | 4 | from d2.app.model.static import StaticData |
4 | from d2.db import Base | 5 | from d2.db import Base |
@@ -6,6 +7,8 @@ from d2.db import Location | |||
6 | from d2.db import Map | 7 | from d2.db import Map |
7 | from d2.db import Room | 8 | from d2.db import Room |
8 | from d2.db import Floor | 9 | from d2.db import Floor |
10 | from d2.db import OccupantType | ||
11 | from d2.db import Occupant | ||
9 | 12 | ||
10 | class Args(object): | 13 | class Args(object): |
11 | 14 | ||
@@ -91,6 +94,47 @@ class PopulateMap(object): | |||
91 | return self._db.session.query(Map).filter('location_id=:location_id').params( | 94 | return self._db.session.query(Map).filter('location_id=:location_id').params( |
92 | location_id=map.get('location_id')).first() | 95 | location_id=map.get('location_id')).first() |
93 | 96 | ||
97 | class PopulateSpecialOccupants(object): | ||
98 | |||
99 | NAMES = {'person': [u'CSR', u'Temp'], | ||
100 | 'work area': [u'Cirith Ungol', u'Orodruin'], | ||
101 | 'restroom': [u"Men's Restroom", u"Women's Restroom"] | ||
102 | } | ||
103 | KEY = unicode(hashlib.md5(u'Temp').hexdigest()) | ||
104 | |||
105 | def __init__(self, config): | ||
106 | self._log = config.log | ||
107 | self._db = config.db | ||
108 | |||
109 | def __call__(self): | ||
110 | s = StaticData.load(self._db) | ||
111 | occupant_type_id_for_person = s().occupant_type.person | ||
112 | for type, names in self.NAMES.iteritems(): | ||
113 | if type == 'person': | ||
114 | type_id = s().occupant_type.person | ||
115 | elif type == 'work area': | ||
116 | type_id = s().occupant_type.work_area | ||
117 | elif type == 'restroom': | ||
118 | type_id = s().occupant_type.restroom | ||
119 | |||
120 | for name in names: | ||
121 | if not self._get(name): | ||
122 | data = dict(occupant_type_id = type_id, | ||
123 | key = self._get_key(name), | ||
124 | active = True) | ||
125 | obj = Occupant.from_dict(data) | ||
126 | self._db.session.add(obj) | ||
127 | self._db.session.commit() | ||
128 | message = "{0} occupant was added".format(name) | ||
129 | self._log.info(message) | ||
130 | |||
131 | def _get_key(self, name): | ||
132 | return unicode(hashlib.md5(unicode(name)).hexdigest()) | ||
133 | |||
134 | def _get(self, name): | ||
135 | return self._db.session.query(Occupant).filter( | ||
136 | 'key=:key').params( | ||
137 | key=self._get_key(name)).first() | ||
94 | 138 | ||
95 | class PopulateTables(object): | 139 | class PopulateTables(object): |
96 | 140 | ||
@@ -98,6 +142,7 @@ class PopulateTables(object): | |||
98 | self._chain = [ | 142 | self._chain = [ |
99 | PopulateLocation(config), | 143 | PopulateLocation(config), |
100 | PopulateMap(config), | 144 | PopulateMap(config), |
145 | PopulateSpecialOccupants(config) | ||
101 | ] | 146 | ] |
102 | 147 | ||
103 | def __call__(self): | 148 | def __call__(self): |
@@ -106,6 +151,6 @@ class PopulateTables(object): | |||
106 | 151 | ||
107 | 152 | ||
108 | def main(): | 153 | def main(): |
109 | config = Config()() | 154 | config = Config.load() |
110 | populate_tables = PopulateTables(config) | 155 | populate_tables = PopulateTables(config) |
111 | populate_tables() | 156 | populate_tables() |
diff --git a/lib/d2/bin/d2_db_setup.py b/lib/d2/bin/d2_db_setup.py index 511677e..5eb0cae 100644 --- a/lib/d2/bin/d2_db_setup.py +++ b/lib/d2/bin/d2_db_setup.py | |||
@@ -187,7 +187,11 @@ class PopulateDetailType(object): | |||
187 | 187 | ||
188 | class PopulateOccupantType(object): | 188 | class PopulateOccupantType(object): |
189 | 189 | ||
190 | NAMES = [u'Person', u'Conference Room', u'Work Area', u'Empty', | 190 | NAMES = [u'Person', |
191 | u'Conference Room', | ||
192 | u'Work Area', | ||
193 | u'Empty', | ||
194 | u'Restroom', | ||
191 | ] | 195 | ] |
192 | 196 | ||
193 | def __init__(self, config): | 197 | def __init__(self, config): |