aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorheather <unknown>2011-05-11 00:25:36 -0400
committerheather <unknown>2011-05-11 00:25:36 -0400
commit6b527753a5a691c9daf52ded10cf4cf515d83f47 (patch)
tree57cd25030bd18b01de150b5cea59e111c3c380e1
parente140c61a5f743e90ff0120f942056dbac581394a (diff)
downloadd2-6b527753a5a691c9daf52ded10cf4cf515d83f47.tar.bz2
d2-6b527753a5a691c9daf52ded10cf4cf515d83f47.tar.xz
d2-6b527753a5a691c9daf52ded10cf4cf515d83f47.zip
more refactor
-rw-r--r--lib/d2/bin/d2_svg_processor.py78
1 files changed, 46 insertions, 32 deletions
diff --git a/lib/d2/bin/d2_svg_processor.py b/lib/d2/bin/d2_svg_processor.py
index c423ec6..3e59a4b 100644
--- a/lib/d2/bin/d2_svg_processor.py
+++ b/lib/d2/bin/d2_svg_processor.py
@@ -84,6 +84,15 @@ class Args(object):
84 DEFAULT_MASTER_SVG = 'combined_master_v6.svg' 84 DEFAULT_MASTER_SVG = 'combined_master_v6.svg'
85 DEFAULT_MASTER_SPREADSHEET = 'FloorPlan1.xls' 85 DEFAULT_MASTER_SPREADSHEET = 'FloorPlan1.xls'
86 86
87 MASTER_SVG_HELP = "The full path of the master svg file "\
88 "files: (default: {default})"
89
90 MASTER_XLS_HELP = "The full path of the master spreadsheet file "\
91 "files: (default: {default})"
92
93 MASTER_OUTPUT_DIR_HELP = "The full path of the output directory "\
94 ': (default: {default})'
95
87 def __init__(self, config): 96 def __init__(self, config):
88 self._config = config 97 self._config = config
89 self._parser_ = None 98 self._parser_ = None
@@ -128,8 +137,7 @@ class Args(object):
128 '--master-svg', 137 '--master-svg',
129 type=argparse.FileType('r'), 138 type=argparse.FileType('r'),
130 default=default_path, 139 default=default_path,
131 help='The full path of the master svg file' 140 help=self.MASTER_SVG_HELP.format(default=default_path)
132 'files: (default: %(default)s)'
133 ) 141 )
134 142
135 def _spread_sheet_file(self): 143 def _spread_sheet_file(self):
@@ -140,8 +148,7 @@ class Args(object):
140 '--master-spreadsheet', 148 '--master-spreadsheet',
141 type=str, 149 type=str,
142 default=default_path, 150 default=default_path,
143 help='The full path of the master spreadsheet file' 151 help=self.MASTER_XLS_HELP.format(default=default_path)
144 'files: (default: %(default)s)'
145 ) 152 )
146 153
147 def _output_directory(self): 154 def _output_directory(self):
@@ -152,13 +159,13 @@ class Args(object):
152 '--output-directory', 159 '--output-directory',
153 type=str, 160 type=str,
154 default=default_path, 161 default=default_path,
155 help='The full path of the master spreadsheet file' 162 help=self.MASTER_OUTPUT_DIR_HELP.format(default=default_path)
156 'files: (default: %(default)s)'
157 ) 163 )
158 164
159class ParseFloorPlanXLS(object): 165class ParseFloorPlanXLS(object):
160 166
161 MULTIPLE_RECORD_ERROR = "Data Error: multiple records for {0} in room {1}" 167 MULTIPLE_RECORD_ERROR = "Data Error: xls has multiple records for {0} "\
168 "in room {1}"
162 169
163 def __init__(self): 170 def __init__(self):
164 pass 171 pass
@@ -313,6 +320,13 @@ class PopulateTables(object):
313 TABLES = [u'forge', u'label_coordinate', u'plot'] 320 TABLES = [u'forge', u'label_coordinate', u'plot']
314 321
315 TRANSFORM_MATRIX_ERROR = "Error: transform matrix of {0} not implemented" 322 TRANSFORM_MATRIX_ERROR = "Error: transform matrix of {0} not implemented"
323 DUPLICATE_NTWK_LABEL_ERROR = "Data Error: master svg has duplicate "\
324 "network label in same room: {0}, {1}"
325 NO_CLOSEBY_NTWK_ID_ERROR = "Data Error: cannot find closest_ntwk_id "\
326 "in room_name: {0}, x: {1} y: {2}, current name shown {3}"
327 NO_AREA_INFO_ERROR = "Data Error: cannot find area info for {0} {1}"
328 NO_OCCUPANT_DETAIL = "Data Errot: cannot find {0} in occupant_detail"
329
316 330
317 def __init__(self): 331 def __init__(self):
318 self.input_svg = "" 332 self.input_svg = ""
@@ -377,7 +391,7 @@ class PopulateTables(object):
377 # Append group element with id to ntwk_id_svg 391 # Append group element with id to ntwk_id_svg
378 ntwk_group = etree.SubElement(parent_node, "g", 392 ntwk_group = etree.SubElement(parent_node, "g",
379 transform=node.attrib['transform'], 393 transform=node.attrib['transform'],
380 id="%s_NTWK_NUMBER" %room_name) 394 id="{0}_NTWK_NUMBER".format(room_name))
381 395
382 room_ntwk_id = NTWK_NUMBER_ID.get(room_name) 396 room_ntwk_id = NTWK_NUMBER_ID.get(room_name)
383 for el in node: 397 for el in node:
@@ -445,9 +459,9 @@ class PopulateTables(object):
445 if room_name not in ntwk_number_data: 459 if room_name not in ntwk_number_data:
446 ntwk_number_data[room_name] = {} 460 ntwk_number_data[room_name] = {}
447 if ntwk_id in ntwk_number_data[room_name]: 461 if ntwk_id in ntwk_number_data[room_name]:
448 self._log_obj.error(""" 462 self._log_obj.error(self.DUPLICATE_NTWK_LABEL_ERROR.format(
449 DATA ERROR: duplicate network label in same room: %s, %s 463 room_name,
450 """ %(room_name, ntwk_id)) 464 ntwk_id))
451 else: 465 else:
452 ntwk_number_data[room_name][ntwk_id] = {'x': x, 466 ntwk_number_data[room_name][ntwk_id] = {'x': x,
453 'y': y, 467 'y': y,
@@ -483,7 +497,7 @@ class PopulateTables(object):
483 map(float, re.split('\s+', view_box[:])) 497 map(float, re.split('\s+', view_box[:]))
484 498
485 for main_el in data: 499 for main_el in data:
486 if main_el.tag == '{%s}g' %NSMAP['svg']: 500 if main_el.tag == '{{{0}}}g'.format(NSMAP['svg']):
487 main_el_matrix = main_el.attrib['transform'] 501 main_el_matrix = main_el.attrib['transform']
488 group_node = etree.SubElement(ntwk_id_svg, main_el.tag, 502 group_node = etree.SubElement(ntwk_id_svg, main_el.tag,
489 main_el.attrib) 503 main_el.attrib)
@@ -503,8 +517,9 @@ class PopulateTables(object):
503 517
504 #create svg root element: 518 #create svg root element:
505 parser = etree.XMLParser() 519 parser = etree.XMLParser()
506 name_label_svg = parser.makeelement('{%s}' %NSMAP['svg'] + 'svg', 520 name_label_svg = parser.makeelement(
507 nsmap = NSMAP2) 521 '{{{0}}}{1}'.format(NSMAP['svg'], 'svg'),
522 nsmap = NSMAP2)
508 #copy the root element attributes to the newly created svgs: 523 #copy the root element attributes to the newly created svgs:
509 root = data.getroottree().getroot() 524 root = data.getroottree().getroot()
510 for key, value in root.attrib.iteritems(): 525 for key, value in root.attrib.iteritems():
@@ -515,7 +530,7 @@ class PopulateTables(object):
515 map(float, re.split('\s+', view_box[:])) 530 map(float, re.split('\s+', view_box[:]))
516 531
517 for main_el in data: 532 for main_el in data:
518 if main_el.tag == '{%s}g' %NSMAP['svg']: 533 if main_el.tag == '{{{0}}}g'.format(NSMAP['svg']):
519 main_el_matrix = main_el.attrib['transform'] 534 main_el_matrix = main_el.attrib['transform']
520 group_node = etree.SubElement(name_label_svg, main_el.tag, 535 group_node = etree.SubElement(name_label_svg, main_el.tag,
521 main_el.attrib) 536 main_el.attrib)
@@ -548,13 +563,13 @@ class PopulateTables(object):
548 563
549 name_label_group = etree.SubElement(parent_node, "g", 564 name_label_group = etree.SubElement(parent_node, "g",
550 transform=node.attrib['transform'], 565 transform=node.attrib['transform'],
551 id="%s_NAME_LABEL" %approx_room_name) 566 id="{0}_NAME_LABEL".format(approx_room_name))
552 567
553 room_name_label_id = NAME_LABEL_ID.get(approx_room_name) 568 room_name_label_id = NAME_LABEL_ID.get(approx_room_name)
554 for el in node: 569 for el in node:
555 if el.attrib['id'] == room_name_label_id: 570 if el.attrib['id'] == room_name_label_id:
556 for sub_el in el: 571 for sub_el in el:
557 if sub_el.tag == '{%s}text' %NSMAP['svg']: 572 if sub_el.tag == '{{{0}}}text'.format(NSMAP['svg']):
558 tspan_elem = sub_el.xpath('./svg:tspan', 573 tspan_elem = sub_el.xpath('./svg:tspan',
559 namespaces=NSMAP)[0] 574 namespaces=NSMAP)[0]
560 transform_matrix = sub_el.attrib['transform'] 575 transform_matrix = sub_el.attrib['transform']
@@ -584,14 +599,13 @@ class PopulateTables(object):
584 current_name_shown += " " + ts.text 599 current_name_shown += " " + ts.text
585 600
586 if not closest_ntwk_id: 601 if not closest_ntwk_id:
587 self._log_obj.error("""DATA ERROR: 602 self._log_obj.error(
588 cannot find closest_ntwk_id for room_name: 603 self.NO_CLOSEBY_NTWK_ID_ERROR.format(
589 %s x: %s y: %s, current name shown %s """ 604 room_name,
590 %(room_name, abs_x, abs_y, 605 abs_x,
591 current_name_shown)) 606 abs_y,
607 current_name_shown))
592 else: 608 else:
593 #print "room_name: %s x: %s y: %s" %(room_name, x, y)
594 #print "closest ntwk_id: %s" %closest_ntwk_id
595 info = self._get_area_info(room_name, 609 info = self._get_area_info(room_name,
596 closest_ntwk_id) 610 closest_ntwk_id)
597 if info: 611 if info:
@@ -708,9 +722,9 @@ class PopulateTables(object):
708 if normalized_id_IDF in floor_plan_data[room_name]: 722 if normalized_id_IDF in floor_plan_data[room_name]:
709 info = floor_plan_data[room_name][normalized_id_IDF] 723 info = floor_plan_data[room_name][normalized_id_IDF]
710 else: 724 else:
711 self._log_obj.error(""" 725 self._log_obj.error(self.NO_AREA_INFO_ERROR.format(
712 DATA ERROR: cannot find area info for %s %s 726 room_name,
713 """ %(room_name, ntwk_id)) 727 ntwk_id))
714 return info 728 return info
715 729
716 def _get_first_last_name(self, s): 730 def _get_first_last_name(self, s):
@@ -748,8 +762,8 @@ class PopulateTables(object):
748 break 762 break
749 763
750 if not occupant_id: 764 if not occupant_id:
751 self._log_obj.error(""" 765 self._log_obj.error(self.NO_OCCUPANT_DETAIL.format(info['name']))
752 DATA ERROR: cannot find %s in occupant_detail""" %info['name']) 766
753 return occupant_id 767 return occupant_id
754 768
755 def _add_ntwk_jacks(self, plot_id, info): 769 def _add_ntwk_jacks(self, plot_id, info):
@@ -809,7 +823,7 @@ class Util(object):
809 el.tag, 823 el.tag,
810 el.attrib) 824 el.attrib)
811 for sub_el in el: 825 for sub_el in el:
812 if sub_el.tag != '{%s}text' %NSMAP['svg']: 826 if sub_el.tag != '{{{0}}}text'.format(NSMAP['svg']):
813 el_wrapper_node.append(sub_el) 827 el_wrapper_node.append(sub_el)
814 828
815 829
@@ -819,9 +833,9 @@ class Util(object):
819 namespaces = NSMAP) 833 namespaces = NSMAP)
820 834
821 for el in use_nodes: 835 for el in use_nodes:
822 href = '{%s}href' %NSMAP['xlink'] 836 href = '{{{0}}}href'.format(NSMAP['xlink'])
823 if href in el.attrib: 837 if href in el.attrib:
824 el_href = el.attrib['{%s}href' %NSMAP['xlink']] 838 el_href = el.attrib['{{{0}}}href'.format(NSMAP['xlink'])]
825 if el_href == href_id: 839 if el_href == href_id:
826 el.getparent().remove(el) 840 el.getparent().remove(el)
827 841