easy-utils-dev 2.131__py3-none-any.whl → 2.133__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of easy-utils-dev might be problematic. Click here for more details.
- easy_utils_dev/ept.py +181 -35
- easy_utils_dev/ept_sql/create_ept_tables.sql +3020 -0
- easy_utils_dev/simple_sqlite.py +1 -1
- easy_utils_dev/wsnoclib.py +13 -2
- {easy_utils_dev-2.131.dist-info → easy_utils_dev-2.133.dist-info}/METADATA +1 -1
- {easy_utils_dev-2.131.dist-info → easy_utils_dev-2.133.dist-info}/RECORD +8 -7
- {easy_utils_dev-2.131.dist-info → easy_utils_dev-2.133.dist-info}/WHEEL +0 -0
- {easy_utils_dev-2.131.dist-info → easy_utils_dev-2.133.dist-info}/top_level.txt +0 -0
easy_utils_dev/ept.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import xml.etree.ElementTree as ET
|
|
2
2
|
from bs4 import BeautifulSoup
|
|
3
3
|
from easy_utils_dev.simple_sqlite import initDB
|
|
4
|
-
from easy_utils_dev.utils import getRandomKey , getTimestamp , lget , mkdirs
|
|
4
|
+
from easy_utils_dev.utils import getRandomKey , getTimestamp , lget , mkdirs , start_thread
|
|
5
5
|
import json , os , glob
|
|
6
6
|
from easy_utils_dev.FastQueue import FastQueue
|
|
7
7
|
from easy_utils_dev.debugger import DEBUGGER
|
|
8
8
|
import zipfile
|
|
9
9
|
import tempfile
|
|
10
|
+
from collections import defaultdict
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
__LIBPATH__ = os.path.dirname(os.path.abspath(__file__))
|
|
@@ -65,6 +66,13 @@ class EPTManager :
|
|
|
65
66
|
db = initDB()
|
|
66
67
|
db.config_database_path(self.ept_db_path)
|
|
67
68
|
return db
|
|
69
|
+
|
|
70
|
+
def create_ept_tables_from_sql(self) :
|
|
71
|
+
self.logger.info("Creating EPT Database Tables from SQL ...")
|
|
72
|
+
db = self.Database()
|
|
73
|
+
db.execute_script( f"{os.path.join(__LIBPATH__ , 'ept_sql' , 'create_ept_tables.sql')}")
|
|
74
|
+
self.logger.info("Creating EPT Database Tables from SQL completed")
|
|
75
|
+
|
|
68
76
|
|
|
69
77
|
def create_ept_columns(self , drop_cols=[]) :
|
|
70
78
|
self.logger.info("Creating EPT Database Tables ...")
|
|
@@ -119,41 +127,54 @@ class EPTManager :
|
|
|
119
127
|
|
|
120
128
|
def create_ept_rows(self) :
|
|
121
129
|
self.logger.info("Creating EPT Rows ...")
|
|
122
|
-
|
|
123
|
-
|
|
130
|
+
all_tags = list(self.root.find_all())
|
|
131
|
+
unique_table_names = list({str(tag.name) for tag in all_tags})
|
|
132
|
+
grouped_by_table = defaultdict(list)
|
|
133
|
+
for t in all_tags:
|
|
134
|
+
grouped_by_table[str(t.name)].append(t)
|
|
124
135
|
db = initDB()
|
|
125
136
|
db.config_database_path(self.ept_db_path)
|
|
126
|
-
|
|
127
|
-
|
|
137
|
+
table_columns_map = {}
|
|
138
|
+
for table_name in unique_table_names:
|
|
139
|
+
query = f"PRAGMA table_info({table_name})"
|
|
140
|
+
cols = db.execute_dict(query)
|
|
141
|
+
table_columns_map[table_name] = [c['name'] for c in cols]
|
|
142
|
+
for table_name in unique_table_names:
|
|
143
|
+
elements = grouped_by_table.get(table_name)
|
|
144
|
+
if not elements:
|
|
145
|
+
continue
|
|
146
|
+
column_names = table_columns_map[table_name]
|
|
128
147
|
rows = []
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
template = {}
|
|
133
|
-
for column in columns :
|
|
134
|
-
template[column['name']] = None
|
|
148
|
+
rows_append = rows.append
|
|
149
|
+
for tag in elements:
|
|
150
|
+
template = dict.fromkeys(column_names, None)
|
|
135
151
|
attrs = tag.attrs
|
|
136
|
-
if
|
|
137
|
-
for key
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
template['
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
if attrs:
|
|
153
|
+
for key in column_names:
|
|
154
|
+
if key in attrs:
|
|
155
|
+
template[key] = attrs[key]
|
|
156
|
+
parent = tag.parent
|
|
157
|
+
if parent is not None:
|
|
158
|
+
template['parentId'] = parent.attrs.get('id')
|
|
159
|
+
template['parentTag'] = parent.name
|
|
160
|
+
if self.include_parent_attrs:
|
|
161
|
+
template['parentAttrs'] = json.dumps(parent.attrs)
|
|
162
|
+
grandparent = getattr(parent, 'parent', None)
|
|
163
|
+
if grandparent is not None:
|
|
164
|
+
template['grandparentId'] = grandparent.attrs.get('id')
|
|
165
|
+
template['grandparentTag'] = grandparent.name
|
|
166
|
+
if self.include_grantparent_attrs:
|
|
167
|
+
template['grandparentAttrs'] = json.dumps(grandparent.attrs)
|
|
168
|
+
rows_append(template)
|
|
169
|
+
if rows:
|
|
170
|
+
db.insert_to_table_bulk(tableName=table_name , values=rows)
|
|
171
|
+
self.logger.info("Creating EPT Rows completed")
|
|
151
172
|
|
|
152
173
|
def parse(self) :
|
|
153
174
|
if self.design_path.endswith('.ept') :
|
|
154
175
|
self.extract_ept(self.design_path)
|
|
155
176
|
|
|
156
|
-
with open(self.design_path , 'r') as file :
|
|
177
|
+
with open(self.design_path , 'r' , encoding='utf-8') as file :
|
|
157
178
|
xml_content = file.read()
|
|
158
179
|
xml_content = self.fix_xml_file(xml_content)
|
|
159
180
|
self.root = BeautifulSoup( xml_content, 'xml')
|
|
@@ -174,7 +195,6 @@ class EPTManager :
|
|
|
174
195
|
def _create_v_dirs(self) :
|
|
175
196
|
db = self.Database()
|
|
176
197
|
dirs = self.get_all_dirs()
|
|
177
|
-
|
|
178
198
|
db.createTable(
|
|
179
199
|
'c_dirs' ,
|
|
180
200
|
data=[
|
|
@@ -256,7 +276,7 @@ class EPTManager :
|
|
|
256
276
|
|
|
257
277
|
def _create_crossconnections_table(self) :
|
|
258
278
|
query = f"""
|
|
259
|
-
CREATE
|
|
279
|
+
CREATE VIEW c_crossconnections AS
|
|
260
280
|
SELECT DISTINCT
|
|
261
281
|
p.owner as wdmdemand,
|
|
262
282
|
sh.number || '-' || sm.physicalslot || '-L' || p.portnumber as physicalslot ,
|
|
@@ -283,9 +303,96 @@ class EPTManager :
|
|
|
283
303
|
db = self.Database()
|
|
284
304
|
db.execute_dict(query)
|
|
285
305
|
|
|
306
|
+
def _create_ports_inventory(self) :
|
|
307
|
+
query = f"""
|
|
308
|
+
CREATE VIEW c_port_inventory AS
|
|
309
|
+
select
|
|
310
|
+
p.pluggable as moduletype,
|
|
311
|
+
p.pluggableapn as partnumber,
|
|
312
|
+
p.portnumber,
|
|
313
|
+
p.connectortype,
|
|
314
|
+
cp.slotid,
|
|
315
|
+
cp.id as eptpackid ,
|
|
316
|
+
p.id as eptpid ,
|
|
317
|
+
sh.id as eptshid ,
|
|
318
|
+
s.id as eptsid ,
|
|
319
|
+
sh.number as shelfid,
|
|
320
|
+
sm.physicalslot,
|
|
321
|
+
s.name as sitename,
|
|
322
|
+
CASE
|
|
323
|
+
WHEN p.connectortype LIKE 'Line%'
|
|
324
|
+
THEN sh.number || '-' || sm.physicalslot || '-L' || p.portnumber
|
|
325
|
+
WHEN p.connectortype LIKE 'Client%'
|
|
326
|
+
THEN sh.number || '-' || sm.physicalslot || '-C' || p.portnumber
|
|
327
|
+
WHEN p.connectortype LIKE '%VOA%'
|
|
328
|
+
THEN sh.number || '-' || sm.physicalslot || '-VA' || p.portnumber
|
|
329
|
+
ELSE NULL
|
|
330
|
+
END as custom_portname ,
|
|
331
|
+
CASE
|
|
332
|
+
WHEN p.pluggable IS NULL AND physicalslot IS NOT NULL AND p.pluggableapn is NULL
|
|
333
|
+
THEN 'free'
|
|
334
|
+
ELSE 'busy'
|
|
335
|
+
END as portstatus
|
|
336
|
+
from port p
|
|
337
|
+
JOIN circuitpack cp ON p.parentId = cp.id
|
|
338
|
+
JOIN shelf sh ON cp.parentId = sh.id
|
|
339
|
+
JOIN site s ON sh.grandparentId = s.id
|
|
340
|
+
JOIN slot_mapping sm ON sh.type = sm.shelfType AND cp.slotid = sm.logicalSlot
|
|
341
|
+
JOIN OTtype ot ON ot.OTtype = cp.type
|
|
342
|
+
WHERE ( p.connectortype IS NOT NULL ) ;
|
|
343
|
+
"""
|
|
344
|
+
db = self.Database()
|
|
345
|
+
db.execute_dict(query)
|
|
346
|
+
|
|
347
|
+
def _create_enhanced_dirs(self) :
|
|
348
|
+
query = f"""
|
|
349
|
+
CREATE VIEW c_enhanced_dirs AS
|
|
350
|
+
select DISTINCT
|
|
351
|
+
line.id as eptlineid ,
|
|
352
|
+
line.span as spanid ,
|
|
353
|
+
site.id as eptsitenameid ,
|
|
354
|
+
spn.name as eptsegementname ,
|
|
355
|
+
line.wdmlink as wdmlinkid ,
|
|
356
|
+
cp.type as boardtype ,
|
|
357
|
+
sh.type as shelftype,
|
|
358
|
+
sp.physicalslot as slot ,
|
|
359
|
+
sh.number as shelfid ,
|
|
360
|
+
site.name as sitename ,
|
|
361
|
+
segt.id as segementid ,
|
|
362
|
+
|
|
363
|
+
CASE
|
|
364
|
+
WHEN segt2.asite = site.id THEN site_b.name
|
|
365
|
+
WHEN segt2.bsite = site.id THEN site_a.name
|
|
366
|
+
END AS farsitename,
|
|
367
|
+
|
|
368
|
+
CASE
|
|
369
|
+
WHEN segtinfo.orient = 'AB' AND segt2.asite = site.id THEN segtinfo.dist
|
|
370
|
+
WHEN segtinfo.orient = 'AB' AND segt2.bsite = site.id THEN segtinfo.dist
|
|
371
|
+
WHEN segtinfo.orient = 'BA' AND segt2.asite = site.id THEN segtinfo.dist
|
|
372
|
+
WHEN segtinfo.orient = 'BA' AND segt2.bsite = site.id THEN segtinfo.dist
|
|
373
|
+
END AS distance ,
|
|
374
|
+
sh.number || "-" || sp.physicalSlot as fullslot
|
|
375
|
+
from line
|
|
376
|
+
JOIN circuitpack cp ON cp.wdmline = line.id AND ( cp.packIDRef IS NOT NULL OR cp.type = oa.OAtype )
|
|
377
|
+
JOIN site on site.id = sh.grandparentId
|
|
378
|
+
JOIN OAtype as oa
|
|
379
|
+
JOIN shelf sh ON sh.id = cp.parentId
|
|
380
|
+
JOIN slot_mapping sp on sp.logicalSlot = cp.slotid AND sh.type = sp.shelftype
|
|
381
|
+
JOIN span spn ON spn.id = line.span AND spn.ashelfset IS NOT NULL
|
|
382
|
+
JOIN segt ON segt.grandparentId = spn.id
|
|
383
|
+
JOIN segt segt2 ON segt.id = segt2.id AND segt2.asite IS NOT NULL
|
|
384
|
+
JOIN segtinfo ON segtinfo.parentId = segt.id
|
|
385
|
+
JOIN site AS site_a ON site_a.id = segt2.asite
|
|
386
|
+
JOIN site AS site_b ON site_b.id = segt2.bsite
|
|
387
|
+
GROUP BY line.id ;
|
|
388
|
+
|
|
389
|
+
"""
|
|
390
|
+
db = self.Database()
|
|
391
|
+
db.execute_dict(query)
|
|
392
|
+
|
|
286
393
|
def _create_card_inventory(self) :
|
|
287
394
|
query = f"""
|
|
288
|
-
CREATE
|
|
395
|
+
CREATE VIEW c_card_inventory AS
|
|
289
396
|
SELECT DISTINCT
|
|
290
397
|
sh.number || '-' || pack.physicalslot AS slot,
|
|
291
398
|
sh.number AS shelfid,
|
|
@@ -331,16 +438,55 @@ class EPTManager :
|
|
|
331
438
|
db = self.Database()
|
|
332
439
|
db.execute_dict(query)
|
|
333
440
|
|
|
441
|
+
def _create_shelf_inventory(self) :
|
|
442
|
+
query = f"""
|
|
443
|
+
CREATE VIEW c_shelf_info AS
|
|
444
|
+
SELECT
|
|
445
|
+
sh.type AS shelftype ,
|
|
446
|
+
sh.number AS shelfnumber,
|
|
447
|
+
sh.apn AS partnumber ,
|
|
448
|
+
st.name AS sitename
|
|
449
|
+
FROM shelf sh
|
|
450
|
+
JOIN site st ON st.id = sh.grandparentId
|
|
451
|
+
WHERE sh.number != 0
|
|
452
|
+
UNION ALL
|
|
453
|
+
SELECT
|
|
454
|
+
cp.type AS shelftype ,
|
|
455
|
+
cp.dcmpseudoshelf AS shelfnumber,
|
|
456
|
+
cp.apn AS partnumber ,
|
|
457
|
+
st.name as sitename
|
|
458
|
+
FROM circuitpack cp
|
|
459
|
+
JOIN shelf sh ON sh.id = cp.parentId
|
|
460
|
+
JOIN site st ON sh.grandparentId = st.id
|
|
461
|
+
WHERE cp.dcmpseudoshelf IS NOT NUll ;
|
|
462
|
+
"""
|
|
463
|
+
db = self.Database()
|
|
464
|
+
db.execute_dict(query)
|
|
465
|
+
|
|
466
|
+
def _create_site_tmp_table(self) :
|
|
467
|
+
query = f"""
|
|
468
|
+
CREATE TABLE c_tmp_site_view AS
|
|
469
|
+
SELECT * FROM site;
|
|
470
|
+
"""
|
|
471
|
+
db = self.Database()
|
|
472
|
+
db.execute_dict(query)
|
|
473
|
+
|
|
334
474
|
def convert_design(self , drop_cols=[] ) :
|
|
335
475
|
start = getTimestamp()
|
|
336
476
|
db = self.Database()
|
|
337
477
|
self.parse()
|
|
338
|
-
self.
|
|
478
|
+
self.create_ept_tables_from_sql()
|
|
339
479
|
self.create_ept_rows()
|
|
340
|
-
db.execute_script(f"{os.path.join(__LIBPATH__ , 'ept_sql' , 'create_dirs.sql')}")
|
|
341
|
-
self._create_v_dirs
|
|
342
|
-
self._create_crossconnections_table
|
|
343
|
-
self._create_card_inventory
|
|
480
|
+
# db.execute_script(f"{os.path.join(__LIBPATH__ , 'ept_sql' , 'create_dirs.sql')}")
|
|
481
|
+
a = start_thread(self._create_v_dirs , daemon=True)
|
|
482
|
+
b = start_thread(self._create_crossconnections_table , daemon=True)
|
|
483
|
+
c = start_thread(self._create_card_inventory , daemon=True)
|
|
484
|
+
d = start_thread(self._create_shelf_inventory , daemon=True)
|
|
485
|
+
s = start_thread(self._create_site_tmp_table , daemon=True)
|
|
486
|
+
s = start_thread(self._create_ports_inventory , daemon=True)
|
|
487
|
+
s = start_thread(self._create_enhanced_dirs , daemon=True)
|
|
488
|
+
a.join() ; b.join() ; c.join() ; d.join() ; s.join()
|
|
489
|
+
|
|
344
490
|
end = getTimestamp()
|
|
345
491
|
if os.path.exists(self.tmp_design_path) :
|
|
346
492
|
os.remove(self.tmp_design_path)
|