Mercurial > pyarq-presupuestos
comparison Generic/fiebdc.py @ 25:189f8274aecd
gui. switch navigation menu on switch page
author | Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es> |
---|---|
date | Mon, 20 May 2019 13:18:33 +0200 |
parents | 65e7ae0d0e63 |
children | 16f91684686b |
comparison
equal
deleted
inserted
replaced
24:2b393934f1db | 25:189f8274aecd |
---|---|
145 | 145 |
146 Test if the code have invalid characters and try to erase it, | 146 Test if the code have invalid characters and try to erase it, |
147 if it is posible return a valid code else return a empty string. | 147 if it is posible return a valid code else return a empty string. |
148 """ | 148 """ |
149 if not isinstance(code, unicode): | 149 if not isinstance(code, unicode): |
150 print(_("Invalid code, it must be a unicode string") ) | 150 _str = _("Invalid code, it must be a unicode string") |
151 print(_str.encode("utf-8") ) | |
151 return u"" | 152 return u"" |
152 # Valid chararcter: A-Z a-z 0-9 ñ Ñ . $ # % & _ | 153 # Valid chararcter: A-Z a-z 0-9 ñ Ñ . $ # % & _ |
153 # "valid_code" : "[^A-Za-z0-9ñÑ.$#%&_]" | 154 # "valid_code" : "[^A-Za-z0-9ñÑ.$#%&_]" |
154 _ucode = self.__pattern["valid_code"].sub(u"_", code) | 155 _ucode = self.__pattern["valid_code"].sub(u"_", code) |
155 if _ucode != code: | 156 if _ucode != code: |
156 try: | 157 try: |
157 print(utils.mapping(_("The code '$1' have invalid characters, replaced by '$2'."), | 158 _tstr = _("The code '$1' have invalid characters," \ |
158 (code.encode("utf8"),_ucode.encode("utf8"))) ) | 159 " replaced by '$2'.") |
160 print(utils.mapping(_tstr, (code.encode("utf8"), | |
161 _ucode.encode("utf8"))) ) | |
159 except: | 162 except: |
160 print(utils.mapping(_("The code '$1' have invalid characters and can not be encoded in utf8."), (code,)) ) | 163 _tstr = _("The code '$1' have invalid characters and can not" \ |
164 " be encoded in utf8.") | |
165 print(utils.mapping(_tstr, (code,)).encode("utf-8") ) | |
161 | 166 |
162 if len(_ucode) == 0: | 167 if len(_ucode) == 0: |
163 _normalize_code = ''.join((c for c in unicodedata.normalize('NFD', _ucode) if unicodedata.category(c) != 'Mn')) | 168 _normalize_code = "" |
164 # from http://www.leccionespracticas.com/uncategorized/eliminar-tildes-con-python-solucionado/ | 169 for c in unicodedata.normalize('NFD', _ucode): |
170 if unicodedata.category(c) != 'Mn': | |
171 _normalize_code.join(c) | |
172 #_normalize_code = ''.join((c for c in unicodedata.normalize( | |
173 # 'NFD', _ucode) if unicodedata.category(c) != 'Mn')) | |
174 # from http://www.leccionespracticas.com/uncategorized/ | |
175 # eliminar-tildes-con-python-solucionado/ | |
165 _ucode = self.__pattern["valid_code"].sub(u"", _normalize_code) | 176 _ucode = self.__pattern["valid_code"].sub(u"", _normalize_code) |
166 if len(_ucode) == 0: | 177 if len(_ucode) == 0: |
167 _hash_code = hashlib.sha256() | 178 _hash_code = hashlib.sha256() |
168 _hash_code.update(code.encode('utf-8')) | 179 _hash_code.update(code.encode('utf-8')) |
169 _hexdigest_code = _hash_code.hexdigest() | 180 _hexdigest_code = _hash_code.hexdigest() |
170 _ucode = self.__pattern["valid_code"].sub(u"", _hexdigest_code) | 181 _p_valid_code = self.__pattern["valid_code"] |
182 _ucode = _p_valid_code.sub(u"", _hexdigest_code) | |
171 code = _ucode | 183 code = _ucode |
172 if code == u"##": | 184 if code == u"##": |
173 # root code is an empty code : set to ROOT | 185 # root code is an empty code : set to ROOT |
174 return u"ROOT" | 186 return u"ROOT" |
175 # the lasts characters can not be <#> or <##> | 187 # the lasts characters can not be <#> or <##> |
183 if len(code) > 20: | 195 if len(code) > 20: |
184 code = code[:20] | 196 code = code[:20] |
185 # only one charecter # % or & | 197 # only one charecter # % or & |
186 if sum([code.count(c) for c in u'#%&']) > 1: | 198 if sum([code.count(c) for c in u'#%&']) > 1: |
187 print(utils.mapping(_("The code '$1' contains special "\ | 199 print(utils.mapping(_("The code '$1' contains special "\ |
188 "characters repeated."),(code.encode("utf8"),)) ) | 200 "characters repeated."), |
201 (code.encode("utf8"),)).encode("utf-8") ) | |
189 _i = min([code.find(c) for c in u'#%&']) | 202 _i = min([code.find(c) for c in u'#%&']) |
190 code = code[:_i+1] + \ | 203 code = code[:_i+1] + \ |
191 self.__pattern["special_char"].sub(u"", code[_i+1:]) | 204 self.__pattern["special_char"].sub(u"", code[_i+1:]) |
192 return code | 205 return code |
193 | 206 |
386 self._parseF(_field_list) | 399 self._parseF(_field_list) |
387 elif _field_list[0] == u"A": | 400 elif _field_list[0] == u"A": |
388 self.__statistics.A += 1 | 401 self.__statistics.A += 1 |
389 self._parseA(_field_list) | 402 self._parseA(_field_list) |
390 else: | 403 else: |
391 print(utils.mapping(_("FIEBDC. Unknow record: $1"),(record[:100],))) | 404 print(utils.mapping(_("FIEBDC. Unknow record: $1"), |
405 (record[:100],)).encode("utf-8")) | |
392 self.__statistics.unknow += 1 | 406 self.__statistics.unknow += 1 |
393 | 407 |
394 def _parseV(self, field_list): | 408 def _parseV(self, field_list): |
395 """_parseV(field_list) | 409 """_parseV(field_list) |
396 | 410 |
407 9- [Date budget certificate] | 421 9- [Date budget certificate] |
408 """ | 422 """ |
409 if self.__statistics.records != 1: | 423 if self.__statistics.records != 1: |
410 print(utils.mapping(_("The 'V' record (Property and Version) "\ | 424 print(utils.mapping(_("The 'V' record (Property and Version) "\ |
411 "must be the first record in the file but it is the "\ | 425 "must be the first record in the file but it is the "\ |
412 "number: $1"), (str(self.__statistics.records),)) ) | 426 "number: $1"), |
427 (str(self.__statistics.records),)).encode("utf-8") ) | |
413 print(_("The default values were taken and this V record is "\ | 428 print(_("The default values were taken and this V record is "\ |
414 "ignored") ) | 429 "ignored").encode("utf-8") ) |
415 return | 430 return |
416 # _____number of fields_____ | 431 # _____number of fields_____ |
417 # Any INFORMATION after last field separator is ignored | 432 # Any INFORMATION after last field separator is ignored |
418 if len(field_list) > 10: | 433 if len(field_list) > 10: |
419 field_list = field_list[:10] | 434 field_list = field_list[:10] |
442 # _____Version-Date_____ | 457 # _____Version-Date_____ |
443 _version_date = _version_date.split(u"\\") | 458 _version_date = _version_date.split(u"\\") |
444 _file_format = _version_date[0] | 459 _file_format = _version_date[0] |
445 if _file_format in self.__format_list: | 460 if _file_format in self.__format_list: |
446 self.__file_format = _file_format | 461 self.__file_format = _file_format |
447 print(utils.mapping(_("FIEBDC format: $1"),(_file_format,)) ) | 462 print(utils.mapping(_("FIEBDC format: $1"), |
463 (_file_format,)).encode("utf-8") ) | |
448 | 464 |
449 if len(_version_date) > 1: | 465 if len(_version_date) > 1: |
450 _date = _version_date[1] | 466 _date = _version_date[1] |
451 if _date != u"": | 467 if _date != u"": |
452 _parsed_date = self.parseDate(_date) | 468 _parsed_date = self.parseDate(_date) |
453 if _parsed_date is not None: | 469 if _parsed_date is not None: |
454 self.__budget.setDate(_parsed_date) | 470 self.__budget.setDate(_parsed_date) |
455 # _____Generator_____ | 471 # _____Generator_____ |
456 # ignored field | 472 # ignored field |
457 print(utils.mapping(_("FIEBDC file generated by $1"),(_generator,)) ) | 473 print(utils.mapping(_("FIEBDC file generated by $1"), |
474 (_generator,)).encode("utf-8") ) | |
458 # _____Header_Title_____ | 475 # _____Header_Title_____ |
459 _header_title = _header_title.split(u"\\") | 476 _header_title = _header_title.split(u"\\") |
460 _header_title = [_title.strip() for _title in _header_title] | 477 _header_title = [_title.strip() for _title in _header_title] |
461 _header = _header_title.pop(0) | 478 _header = _header_title.pop(0) |
462 _header = [_item.encode("utf8") for _item in _header] | 479 _header = [_item.encode("utf8") for _item in _header] |
793 if len(_codes) > 0: | 810 if len(_codes) > 0: |
794 #TODO: test this | 811 #TODO: test this |
795 _code = _codes[0] | 812 _code = _codes[0] |
796 _synonyms = [synonym.encode("utf8") for synonym in _codes] | 813 _synonyms = [synonym.encode("utf8") for synonym in _codes] |
797 else: | 814 else: |
798 print(_("Record C without a valid code") ) | 815 print(_("Record C without a valid code").encode("utf-8") ) |
799 return | 816 return |
800 # _____Unit_____ | 817 # _____Unit_____ |
801 # nothing to do | 818 # nothing to do |
802 # _____Summary_____ | 819 # _____Summary_____ |
803 # nothing to do | 820 # nothing to do |
872 elif _type == u"0" or _type == u"": | 889 elif _type == u"0" or _type == u"": |
873 _subtype = u"" | 890 _subtype = u"" |
874 _type = 0 | 891 _type = 0 |
875 else: | 892 else: |
876 print(utils.mapping(_("Incorrect type ($1) in the code $2"), | 893 print(utils.mapping(_("Incorrect type ($1) in the code $2"), |
877 (_type.encode("utf8"), _code.encode("utf8"))) ) | 894 (_type.encode("utf8"), |
895 _code.encode("utf8"))).encode("utf-8") ) | |
878 _type = 0 | 896 _type = 0 |
879 _subtype = u"" | 897 _subtype = u"" |
880 elif _hierarchy == 1: | 898 elif _hierarchy == 1: |
881 if _type == u"PU": | 899 if _type == u"PU": |
882 _subtype = _type | 900 _subtype = _type |
884 elif _type == u"0" or _type == u"": | 902 elif _type == u"0" or _type == u"": |
885 _subtype = u"" | 903 _subtype = u"" |
886 _type = 0 | 904 _type = 0 |
887 else: | 905 else: |
888 print(utils.mapping(_("Incorrect type ($1) in the code $2"), | 906 print(utils.mapping(_("Incorrect type ($1) in the code $2"), |
889 (_type.encode("utf8"), _code.encode("utf8"))) ) | 907 (_type.encode("utf8"), |
908 _code.encode("utf8"))).encode("utf-8") ) | |
890 _type = 0 | 909 _type = 0 |
891 _subtype = u"" | 910 _subtype = u"" |
892 else: | 911 else: |
893 if _type == u"EA" or _type == u"EU" or _type == u"EC" or \ | 912 if _type == u"EA" or _type == u"EU" or _type == u"EC" or \ |
894 _type == u"EF" or _type == u"PA": | 913 _type == u"EF" or _type == u"PA": |
912 elif _type == u"": | 931 elif _type == u"": |
913 _subtype = u"" | 932 _subtype = u"" |
914 _type = 0 | 933 _type = 0 |
915 else: | 934 else: |
916 print(utils.mapping(_("Incorrect type ($1) in the code $2"), | 935 print(utils.mapping(_("Incorrect type ($1) in the code $2"), |
917 (_type.encode("utf8"), _code.encode("utf8"))) ) | 936 (_type.encode("utf8"), |
937 _code.encode("utf8"))).encode("utf-8") ) | |
918 _type = 0 | 938 _type = 0 |
919 _subtype = u"" | 939 _subtype = u"" |
920 self.__budget.setRecord(_code.encode("utf8"), _synonyms, _hierarchy, | 940 self.__budget.setRecord(_code.encode("utf8"), _synonyms, _hierarchy, |
921 _unit.encode("utf8"), _summary.encode("utf8"), | 941 _unit.encode("utf8"), _summary.encode("utf8"), |
922 _prices, _dates, _type, _subtype.encode("utf8")) | 942 _prices, _dates, _type, _subtype.encode("utf8")) |
969 except ValueError: | 989 except ValueError: |
970 print(utils.mapping(_("ValueError loadig the "\ | 990 print(utils.mapping(_("ValueError loadig the "\ |
971 "descomposition of the record $1, the factor "\ | 991 "descomposition of the record $1, the factor "\ |
972 "of the child $2 must be a float number and "\ | 992 "of the child $2 must be a float number and "\ |
973 "can not be $3, seted default value 1.0"), | 993 "can not be $3, seted default value 1.0"), |
974 (_code.encode("utf8"), _child_code.encode("utf8"), _factor.encode("utf8"))) ) | 994 (_code.encode("utf8"), _child_code.encode("utf8"), |
995 _factor.encode("utf8"))).encode("utf-8") ) | |
975 _factor = 1.0 | 996 _factor = 1.0 |
976 #____yield___ | 997 #____yield___ |
977 if _yield != u"": | 998 if _yield != u"": |
978 try: | 999 try: |
979 _yield = float(_yield) | 1000 _yield = float(_yield) |
980 except ValueError: | 1001 except ValueError: |
981 print(utils.mapping(_("ValueError loading the "\ | 1002 print(utils.mapping(_("ValueError loading the "\ |
982 "descomposition of the record $1, the yield of "\ | 1003 "descomposition of the record $1, the yield of "\ |
983 "the child $2, must be a float number and can"\ | 1004 "the child $2, must be a float number and can"\ |
984 "not be $3, seted default value 1.0"), | 1005 "not be $3, seted default value 1.0"), |
985 (_code.encode("utf8"), _child_code.encode("utf8"), _factor.encode("utf8"))) ) | 1006 (_code.encode("utf8"), _child_code.encode("utf8"), |
1007 _factor.encode("utf8"))).encode("utf-8") ) | |
986 _yield = 1.0 | 1008 _yield = 1.0 |
987 if _child_code != u"" and _code != u"": | 1009 if _child_code != u"" and _code != u"": |
988 _children_list.append([_child_code, _factor, _yield ]) | 1010 _children_list.append([_child_code, _factor, _yield ]) |
989 if _record_type == u"D": | 1011 if _record_type == u"D": |
990 _position = _child_index / 3 | 1012 _position = _child_index / 3 |
991 else: #_record_type == "Y" | 1013 else: #_record_type == "Y" |
992 _position = -1 | 1014 _position = -1 |
993 self.__budget.setTree(_code.encode("utf8"), _child_code.encode("utf8"), _position, _factor, | 1015 self.__budget.setTree(_code.encode("utf8"), |
1016 _child_code.encode("utf8"), _position, _factor, | |
994 _yield, "", "", "", "") | 1017 _yield, "", "", "", "") |
995 _child_index = _child_index + 3 | 1018 _child_index = _child_index + 3 |
996 interface.updateGui() | 1019 interface.updateGui() |
997 self.__statistics.valid = self.__statistics.valid +1 | 1020 self.__statistics.valid = self.__statistics.valid +1 |
998 | 1021 |
1066 elif len(_code_list) == 1: | 1089 elif len(_code_list) == 1: |
1067 _child_code = self.validateCode(_code_list[0]) | 1090 _child_code = self.validateCode(_code_list[0]) |
1068 _parent_code = None | 1091 _parent_code = None |
1069 else: | 1092 else: |
1070 print(utils.mapping(_("Invalid codes in $1 record, codes $2"), | 1093 print(utils.mapping(_("Invalid codes in $1 record, codes $2"), |
1071 (_record_type.encode("utf8"), _codes.encode("utf8"))) ) | 1094 (_record_type.encode("utf8"), |
1095 _codes.encode("utf8"))).encode("utf-8") ) | |
1072 return | 1096 return |
1073 if _child_code == u"": | 1097 if _child_code == u"": |
1074 print(utils.mapping(_("Empty child code in $1 record, codes: "\ | 1098 print(utils.mapping(_("Empty child code in $1 record, codes: "\ |
1075 "$2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) ) | 1099 "$2"), (_record_type.encode("utf8"), |
1100 _codes.encode("utf8"))).encode("utf-8") ) | |
1076 return | 1101 return |
1077 if _parent_code == None: | 1102 if _parent_code == None: |
1078 # Empty parent code. No-estructured measures. | 1103 # Empty parent code. No-estructured measures. |
1079 pass | 1104 pass |
1080 | 1105 |
1090 _path = _path_list[-1] | 1115 _path = _path_list[-1] |
1091 try: | 1116 try: |
1092 _path = int(_path) | 1117 _path = int(_path) |
1093 except ValueError: | 1118 except ValueError: |
1094 print(utils.mapping(_("Invalid path in $1 record, "\ | 1119 print(utils.mapping(_("Invalid path in $1 record, "\ |
1095 "codes $2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) ) | 1120 "codes $2"), (_record_type.encode("utf8"), |
1121 _codes.encode("utf8"))).encode("utf-8") ) | |
1096 return | 1122 return |
1097 if _path > 0: | 1123 if _path > 0: |
1098 _path -= 1 | 1124 _path -= 1 |
1099 else: | 1125 else: |
1100 _path = -2 | 1126 _path = -2 |
1102 try: | 1128 try: |
1103 _total = float(_total) | 1129 _total = float(_total) |
1104 except ValueError: | 1130 except ValueError: |
1105 print(utils.mapping(_("Invalid Total Measure value in $1 "\ | 1131 print(utils.mapping(_("Invalid Total Measure value in $1 "\ |
1106 "record, codes $2. Total fixed to 0."), | 1132 "record, codes $2. Total fixed to 0."), |
1107 (_record_type.encode("utf8"), _codes.encode("utf8"))) ) | 1133 (_record_type.encode("utf8"), |
1134 _codes.encode("utf8"))).encode("utf-8") ) | |
1108 _total = 0 | 1135 _total = 0 |
1109 # _____Measure lines_____ | 1136 # _____Measure lines_____ |
1110 _lines = _lines.split(u"\\") | 1137 _lines = _lines.split(u"\\") |
1111 _line_index = 0 | 1138 _line_index = 0 |
1112 _line_list = [ ] | 1139 _line_list = [ ] |
1123 if _linetype == 3: | 1150 if _linetype == 3: |
1124 # "formula": ".*[^0123456789\.()\+\-\*/\^abcdp ].*" | 1151 # "formula": ".*[^0123456789\.()\+\-\*/\^abcdp ].*" |
1125 if self.__pattern["formula"].match(_comment): | 1152 if self.__pattern["formula"].match(_comment): |
1126 print(utils.mapping(_("The comment is not a formula or "\ | 1153 print(utils.mapping(_("The comment is not a formula or "\ |
1127 "its have invalid characters, in the $1 record, "\ | 1154 "its have invalid characters, in the $1 record, "\ |
1128 "codes $2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) ) | 1155 "codes $2"), (_record_type.encode("utf8"), |
1156 _codes.encode("utf8"))).encode("utf-8") ) | |
1129 return | 1157 return |
1130 else: | 1158 else: |
1131 _formula = _comment.encode("utf8") | 1159 _formula = _comment.encode("utf8") |
1132 _comment = "" | 1160 _comment = "" |
1133 else: | 1161 else: |
1148 if _length != u"": _length = float(_length) | 1176 if _length != u"": _length = float(_length) |
1149 if _width != u"": _width = float(_width) | 1177 if _width != u"": _width = float(_width) |
1150 if _height != u"": _height = float(_height) | 1178 if _height != u"": _height = float(_height) |
1151 except ValueError: | 1179 except ValueError: |
1152 print(utils.mapping(_("The measure values are not float "\ | 1180 print(utils.mapping(_("The measure values are not float "\ |
1153 "numbers, code $1"), (_codes.encode("utf8"),)) ) | 1181 "numbers, code $1"), |
1182 (_codes.encode("utf8"),)).encode("utf-8") ) | |
1154 return | 1183 return |
1155 # Prevent subfield units remains empty. | 1184 # Prevent subfield units remains empty. |
1156 if (_units == u"" and (_length != u"" or _width != u"" | 1185 if (_units == u"" and (_length != u"" or _width != u"" |
1157 or _height != u"")): | 1186 or _height != u"")): |
1158 _units = 1.0 | 1187 _units = 1.0 |
1159 _line_list.append([_linetype, _comment, _units, | 1188 _line_list.append([_linetype, _comment, _units, |
1160 _length, _width, _height, _formula]) | 1189 _length, _width, _height, _formula]) |
1161 _line_index = _line_index + 6 | 1190 _line_index = _line_index + 6 |
1162 self.__budget.setTree(_parent_code, _child_code.encode("utf8"), _path, "", "", | 1191 self.__budget.setTree(_parent_code, _child_code.encode("utf8"), _path, "", "", |
1163 _total, _line_list, _label.encode("utf8"), _record_type.encode("utf8")) | 1192 _total, _line_list, _label.encode("utf8"), |
1193 _record_type.encode("utf8")) | |
1164 self.__statistics.valid = self.__statistics.valid + 1 | 1194 self.__statistics.valid = self.__statistics.valid + 1 |
1165 | 1195 |
1166 def _parseW(self, field_list): | 1196 def _parseW(self, field_list): |
1167 """_parseW(field_list) | 1197 """_parseW(field_list) |
1168 | 1198 |
1195 # _____section_code_____ | 1225 # _____section_code_____ |
1196 #"control": "[\t \n\r]" | 1226 #"control": "[\t \n\r]" |
1197 _field_code = self.delete_control_space(_field_code) | 1227 _field_code = self.delete_control_space(_field_code) |
1198 # _____section_title_____ | 1228 # _____section_title_____ |
1199 if _field_code != u"": | 1229 if _field_code != u"": |
1200 _field_dict[_field_code.encode("utf8")] = _field_title.encode("utf8") | 1230 _e_field_code = _field_code.encode("utf8") |
1231 _e_field_title = _field_title.encode("utf8") | |
1232 _field_dict[_e_field_code] = _e_field_title | |
1201 _field_index = _field_index + 2 | 1233 _field_index = _field_index + 2 |
1202 self.__budget.setSheetFields(_field_dict) | 1234 self.__budget.setSheetFields(_field_dict) |
1203 self.__statistics.valid = self.__statistics.valid +1 | 1235 self.__statistics.valid = self.__statistics.valid +1 |
1204 | 1236 |
1205 def _parseL(self, field_list): | 1237 def _parseL(self, field_list): |
1245 # _____section_code_____ | 1277 # _____section_code_____ |
1246 _section_code = self.delete_control_space(_section_code) | 1278 _section_code = self.delete_control_space(_section_code) |
1247 # _____section_title_____ | 1279 # _____section_title_____ |
1248 _section_title = self.delete_control_space(_section_title) | 1280 _section_title = self.delete_control_space(_section_title) |
1249 if _section_code != u"": | 1281 if _section_code != u"": |
1250 _section_dict[_section_code.encode("utf8")] = _section_title.encode("utf8") | 1282 _e_section_code = _section_code.encode("utf8") |
1283 _e_section_title = _section_title.encode("utf8") | |
1284 _section_dict[_e_section_code] = _e_section_title | |
1251 _section_index = _section_index + 2 | 1285 _section_index = _section_index + 2 |
1252 self.__budget.setSheetSections(_section_dict) | 1286 self.__budget.setSheetSections(_section_dict) |
1253 self.__statistics.valid = self.__statistics.valid +1 | 1287 self.__statistics.valid = self.__statistics.valid +1 |
1254 | 1288 |
1255 else: | 1289 else: |
1265 # invalid characters are also erased | 1299 # invalid characters are also erased |
1266 _record_code = self.validateCode(_record_code) | 1300 _record_code = self.validateCode(_record_code) |
1267 _scodes_text = field_list[1] | 1301 _scodes_text = field_list[1] |
1268 if _scodes_text == u"": | 1302 if _scodes_text == u"": |
1269 # TODO: rtf and html files | 1303 # TODO: rtf and html files |
1270 print("Html and rtf files not yet implemented in ~L record" ) | 1304 _str = "Html and rtf files not yet implemented in ~L record" |
1305 print(_str.encode("utf-8") ) | |
1271 else: | 1306 else: |
1272 # _____Section-code_Section-text_____ | 1307 # _____Section-code_Section-text_____ |
1273 # last \ is erased | 1308 # last \ is erased |
1274 if len(_scodes_text) and _scodes_text[-1] == u"\\": | 1309 if len(_scodes_text) and _scodes_text[-1] == u"\\": |
1275 _scodes_text = _scodes_text[:-1] | 1310 _scodes_text = _scodes_text[:-1] |
1286 _section_code = self.delete_control_space(_section_code) | 1321 _section_code = self.delete_control_space(_section_code) |
1287 # _____section_text_____ | 1322 # _____section_text_____ |
1288 if _section_code != u"" and _section_text != u"": | 1323 if _section_code != u"" and _section_text != u"": |
1289 #-# paragraph #-# | 1324 #-# paragraph #-# |
1290 _paragraph_code = _record_code + _section_code + u"*" | 1325 _paragraph_code = _record_code + _section_code + u"*" |
1291 _paragraph_dict[ _paragraph_code.encode("utf8") ] = _section_text.encode("utf8") | 1326 _e_paragraph_code = _paragraph_code.encode("utf8") |
1292 _section_dict[_section_code.encode("utf8")] = _paragraph_code.encode("utf8") | 1327 _e_section_text = _section_text.encode("utf8") |
1328 _paragraph_dict[_e_paragraph_code] = _e_section_text | |
1329 _e_section_code = _section_code.encode("utf8") | |
1330 _section_dict[_e_section_code] = _e_paragraph_code | |
1293 _section_index = _section_index + 2 | 1331 _section_index = _section_index + 2 |
1294 self.__budget.setSheetParagraphs(_paragraph_dict) | 1332 self.__budget.setSheetParagraphs(_paragraph_dict) |
1295 self.__budget.setSheetRecord(_record_code.encode("utf8"), "*", _section_dict) | 1333 self.__budget.setSheetRecord(_record_code.encode("utf8"), "*", |
1334 _section_dict) | |
1296 self.__statistics.valid = self.__statistics.valid +1 | 1335 self.__statistics.valid = self.__statistics.valid +1 |
1297 | 1336 |
1298 def _parseQ(self, field_list): | 1337 def _parseQ(self, field_list): |
1299 """_parseQ(field_list) | 1338 """_parseQ(field_list) |
1300 | 1339 |
1348 if _field_key in _field_dict: | 1387 if _field_key in _field_dict: |
1349 _section_dict = _field_dict[_field_key] | 1388 _section_dict = _field_dict[_field_key] |
1350 else: | 1389 else: |
1351 _section_dict = {} | 1390 _section_dict = {} |
1352 _field_dict[_field_key] = _section_dict | 1391 _field_dict[_field_key] = _section_dict |
1353 _section_dict[_section_code.encode("utf8")] = _paragraph_code.encode("utf8") | 1392 _e_section_code = _section_code.encode("utf8") |
1393 _e_paragraph_code = _paragraph_code.encode("utf8") | |
1394 _section_dict[_e_section_code] = _e_paragraph_code | |
1354 _section_index = _section_index + 3 | 1395 _section_index = _section_index + 3 |
1355 for _field, _section_dict in _field_dict.iteritems(): | 1396 for _field, _section_dict in _field_dict.iteritems(): |
1356 self.__budget.setSheetRecord(_record_code.encode("utf8"), _field.encode("utf8"), _section_dict) | 1397 self.__budget.setSheetRecord(_record_code.encode("utf8"), |
1398 _field.encode("utf8"), _section_dict) | |
1357 self.__statistics.valid = self.__statistics.valid +1 | 1399 self.__statistics.valid = self.__statistics.valid +1 |
1358 | 1400 |
1359 def _parseJ(self, field_list): | 1401 def _parseJ(self, field_list): |
1360 """_parseJ(field_list) | 1402 """_parseJ(field_list) |
1361 | 1403 |
1380 _paragraph_code = self.delete_control_space(field_list[0]) | 1422 _paragraph_code = self.delete_control_space(field_list[0]) |
1381 # _____Paragraph text_____ | 1423 # _____Paragraph text_____ |
1382 _paragraph_text = field_list[1] | 1424 _paragraph_text = field_list[1] |
1383 if _paragraph_text == u"": | 1425 if _paragraph_text == u"": |
1384 # TODO: rtf and html files | 1426 # TODO: rtf and html files |
1385 print("Html and rtf files not yet implemented in ~J record" ) | 1427 _str = "Html and rtf files not yet implemented in ~J record" |
1428 print(_str.encode("utf-8") ) | |
1386 else: | 1429 else: |
1387 self.__budget.setSheetParagraph(paragraph_code.encode("utf8"), paragraph_text.encode("utf8")) | 1430 self.__budget.setSheetParagraph(paragraph_code.encode("utf8"), |
1431 paragraph_text.encode("utf8")) | |
1388 self.__statistics.valid = self.__statistics.valid +1 | 1432 self.__statistics.valid = self.__statistics.valid +1 |
1389 | 1433 |
1390 def _parseG(self, field_list): | 1434 def _parseG(self, field_list): |
1391 """_parseG(field_list) | 1435 """_parseG(field_list) |
1392 | 1436 |
1448 _tested_grafic_file_list.append(_grafic_file_path_lu) | 1492 _tested_grafic_file_list.append(_grafic_file_path_lu) |
1449 elif os.path.exists(_grafic_file_path_ll): | 1493 elif os.path.exists(_grafic_file_path_ll): |
1450 _tested_grafic_file_list.append(_grafic_file_path_ll) | 1494 _tested_grafic_file_list.append(_grafic_file_path_ll) |
1451 else: | 1495 else: |
1452 print(utils.mapping(_("The file $1 do not exist"), | 1496 print(utils.mapping(_("The file $1 do not exist"), |
1453 (_grafic_file_path.decode("utf8"),)) ) | 1497 (_grafic_file_path.decode("utf8"),)).encode("utf-8") ) |
1454 if len(_grafic_file_list) > 0: | 1498 if len(_grafic_file_list) > 0: |
1455 for _grafic_file in _tested_grafic_file_list: | 1499 for _grafic_file in _tested_grafic_file_list: |
1456 self.__budget.addFile(_record_code.encode("utf8"), _grafic_file, "img", "") | 1500 self.__budget.addFile(_record_code.encode("utf8"), |
1501 _grafic_file, "img", "") | |
1457 self.__statistics.valid = self.__statistics.valid +1 | 1502 self.__statistics.valid = self.__statistics.valid +1 |
1458 | 1503 |
1459 def _parseE(self, field_list): | 1504 def _parseE(self, field_list): |
1460 """_parseE(field_list) | 1505 """_parseE(field_list) |
1461 | 1506 |
1528 _contact_person = _local_offices_list[_local_offices_index+9] | 1573 _contact_person = _local_offices_list[_local_offices_index+9] |
1529 if _type != u"" or _subname != u"" or _address != u"" or \ | 1574 if _type != u"" or _subname != u"" or _address != u"" or \ |
1530 _postal_code != u"" or _town != u"" or _province != u"" or \ | 1575 _postal_code != u"" or _town != u"" or _province != u"" or \ |
1531 _country != u"" or _phone != u"" or _fax != u"" or \ | 1576 _country != u"" or _phone != u"" or _fax != u"" or \ |
1532 _contact_person != u"": | 1577 _contact_person != u"": |
1533 _local_offices.append([_type.encode("utf8"), _subname.encode("utf8"), | 1578 _local_offices.append([_type.encode("utf8"), |
1534 _address.encode("utf8"), _postal_code.encode("utf8"), | 1579 _subname.encode("utf8"), |
1535 _town.encode("utf8"), _province.encode("utf8"), | 1580 _address.encode("utf8"), |
1536 _country.encode("utf8"), _phone_list, | 1581 _postal_code.encode("utf8"), |
1537 _fax_list, _contact_person.encode("utf8")]) | 1582 _town.encode("utf8"), |
1583 _province.encode("utf8"), | |
1584 _country.encode("utf8"), | |
1585 _phone_list, | |
1586 _fax_list, | |
1587 _contact_person.encode("utf8")]) | |
1538 _local_offices_index = _local_offices_index + 10 | 1588 _local_offices_index = _local_offices_index + 10 |
1539 # _____cif web email_____ | 1589 # _____cif web email_____ |
1540 _c_w_e = self.delete_control_space(field_list[4]) | 1590 _c_w_e = self.delete_control_space(field_list[4]) |
1541 # last \ is erased | 1591 # last \ is erased |
1542 if len(_c_w_e) and _c_w_e[-1] == u"\\": | 1592 if len(_c_w_e) and _c_w_e[-1] == u"\\": |
1588 while _ti_index < len(_field_2_list)-3: | 1638 while _ti_index < len(_field_2_list)-3: |
1589 _ti_code = _field_2_list[_ti_index] | 1639 _ti_code = _field_2_list[_ti_index] |
1590 _ti_description = _field_2_list[_ti_index+1] | 1640 _ti_description = _field_2_list[_ti_index+1] |
1591 _ti_unit = _field_2_list[_ti_index+2] | 1641 _ti_unit = _field_2_list[_ti_index+2] |
1592 if _ti_code != "": | 1642 if _ti_code != "": |
1593 self.__budget.addTecInfo(_ti_code.encode("utf8"), _ti_description.encode("utf8"), | 1643 self.__budget.addTecInfo(_ti_code.encode("utf8"), |
1644 _ti_description.encode("utf8"), | |
1594 _ti_unit.encode("utf8")) | 1645 _ti_unit.encode("utf8")) |
1595 _ti_index = _ti_index + 3 | 1646 _ti_index = _ti_index + 3 |
1596 else: | 1647 else: |
1597 # B) | 1648 # B) |
1598 # "#" and "##" characters at the end of the code are erased | 1649 # "#" and "##" characters at the end of the code are erased |
1605 _ti_code = _field_2_list[_ti_index] | 1656 _ti_code = _field_2_list[_ti_index] |
1606 _ti_value = _field_2_list[_ti_index+1] | 1657 _ti_value = _field_2_list[_ti_index+1] |
1607 if _ti_code != u"" and _ti_value != u"": | 1658 if _ti_code != u"" and _ti_value != u"": |
1608 _ti_dict[_ti_code.encode("utf8")] = _ti_value.encode("utf8") | 1659 _ti_dict[_ti_code.encode("utf8")] = _ti_value.encode("utf8") |
1609 _ti_index = _ti_index + 2 | 1660 _ti_index = _ti_index + 2 |
1610 self.__budget.setTecnicalInformation(_record_code.encode("utf8"), _ti_dict) | 1661 self.__budget.setTecnicalInformation(_record_code.encode("utf8"), |
1662 _ti_dict) | |
1611 self.__statistics.valid = self.__statistics.valid +1 | 1663 self.__statistics.valid = self.__statistics.valid +1 |
1612 | 1664 |
1613 def _parseF(self, field_list): | 1665 def _parseF(self, field_list): |
1614 """_parseF(field_list) | 1666 """_parseF(field_list) |
1615 | 1667 |
1616 field_list: field list of the record | 1668 field_list: field list of the record |
1617 0- F: Files | 1669 0- F: Files |
1618 1- Record code | 1670 1- Record code |
1619 2- { Type \ { Filenames; } \ [Description] } | 1671 2- { Type \ { Filenames; } \ [Description] } |
1620 """ | 1672 """ |
1621 print("parseF") | |
1622 print(field_list) | |
1623 # _____Number of fields_____ | 1673 # _____Number of fields_____ |
1624 # The record must have at least 3 fields | 1674 # The record must have at least 3 fields |
1625 if len(field_list) < 3: | 1675 if len(field_list) < 3: |
1626 return | 1676 return |
1627 # Any INFORMATION after last field separator is ignored | 1677 # Any INFORMATION after last field separator is ignored |
1645 # adding empty subfiels if necesary | 1695 # adding empty subfiels if necesary |
1646 if len(_files_list)%3 > 0: | 1696 if len(_files_list)%3 > 0: |
1647 _files_list.extend[u""]*(3 - len(_files_list)%3) | 1697 _files_list.extend[u""]*(3 - len(_files_list)%3) |
1648 _file_index = 0 | 1698 _file_index = 0 |
1649 _tested_files_list = [] | 1699 _tested_files_list = [] |
1650 print(_files_list) | |
1651 while _file_index < len(_files_list)-3: | 1700 while _file_index < len(_files_list)-3: |
1652 _type = _files_list[_file_index].replace(u" ",u"") | 1701 _type = _files_list[_file_index].replace(u" ",u"") |
1653 ## _types = { | 1702 ## _types = { |
1654 ## "0": _("others"), | 1703 ## "0": _("others"), |
1655 ## "1": _("características técnicas y de fabricación"), | 1704 ## "1": _("características técnicas y de fabricación"), |
1663 ## "9": _("cálculo de elementos y sistemas"), | 1712 ## "9": _("cálculo de elementos y sistemas"), |
1664 ## "10": _("presentación, datos generales, objetivos, " \ | 1713 ## "10": _("presentación, datos generales, objetivos, " \ |
1665 ## "etc. de empresa"), | 1714 ## "etc. de empresa"), |
1666 ## "11": _("certificado/s de empresa"), | 1715 ## "11": _("certificado/s de empresa"), |
1667 ## "12": _("obras realizadas")} | 1716 ## "12": _("obras realizadas")} |
1668 _types = [u"0", u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10", | 1717 _types = [u"0", u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", |
1669 u"11", u"12"] | 1718 u"9", u"10", u"11", u"12"] |
1670 if not _type in _types: | 1719 if not _type in _types: |
1671 _type = u"0" | 1720 _type = u"0" |
1672 _filenames = _files_list[_file_index + 1] | 1721 _filenames = _files_list[_file_index + 1] |
1673 _description = _files_list[_file_index + 2] | 1722 _description = _files_list[_file_index + 2] |
1674 _file_index += 3 | 1723 _file_index += 3 |
1675 print(u"type: " + _type) | |
1676 print(u"filenames: " + _filenames) | |
1677 print(u"_description: " + _description) | |
1678 if len(_filenames) and _filenames[-1] == u";": | 1724 if len(_filenames) and _filenames[-1] == u";": |
1679 _files = _files[:-1] | 1725 _files = _files[:-1] |
1680 _filenames_list = _filenames.split(u";") | 1726 _filenames_list = _filenames.split(u";") |
1681 | 1727 |
1682 _path = os.path.dirname(self.__filename) | 1728 _path = os.path.dirname(self.__filename) |
1700 _file_path_uu = os.path.join(_path, _uu) | 1746 _file_path_uu = os.path.join(_path, _uu) |
1701 _file_path_ul = os.path.join(_path, _ul) | 1747 _file_path_ul = os.path.join(_path, _ul) |
1702 _file_path_lu = os.path.join(_path, _lu) | 1748 _file_path_lu = os.path.join(_path, _lu) |
1703 _file_path_ll = os.path.join(_path, _ll) | 1749 _file_path_ll = os.path.join(_path, _ll) |
1704 if os.path.exists(_file_path_uu): | 1750 if os.path.exists(_file_path_uu): |
1705 _tested_files_list.append([_file_path_uu, _type.encode("utf8"), | 1751 _tested_files_list.append([_file_path_uu, |
1752 _type.encode("utf8"), | |
1706 _description.encode("utf8")]) | 1753 _description.encode("utf8")]) |
1707 elif os.path.exists(_grafic_file_path_ul): | 1754 elif os.path.exists(_grafic_file_path_ul): |
1708 _tested_files_list.append([_file_path_ul, _type.encode("utf8"), | 1755 _tested_files_list.append([_file_path_ul, |
1756 _type.encode("utf8"), | |
1709 _description.encode("utf8")]) | 1757 _description.encode("utf8")]) |
1710 elif os.path.exists(_grafic_file_path_lu): | 1758 elif os.path.exists(_grafic_file_path_lu): |
1711 _tested_files_list.append([_file_path_lu, _type.encode("utf8"), | 1759 _tested_files_list.append([_file_path_lu, |
1760 _type.encode("utf8"), | |
1712 _description.encode("utf8")]) | 1761 _description.encode("utf8")]) |
1713 elif os.path.exists(_grafic_file_path_ll): | 1762 elif os.path.exists(_grafic_file_path_ll): |
1714 _tested_files_list.append([_file_path_ll, _type.encode("utf8"), | 1763 _tested_files_list.append([_file_path_ll, |
1764 _type.encode("utf8"), | |
1715 _description.encode("utf8")]) | 1765 _description.encode("utf8")]) |
1716 else: | 1766 else: |
1717 print(utils.mapping(_("The file $1 do not exist"), | 1767 print(utils.mapping(_("The file $1 do not exist"), |
1718 (_file_path,)) ) | 1768 (_file_path,)).encode("utf-8") ) |
1719 if len(_tested_files_list) > 0: | 1769 if len(_tested_files_list) > 0: |
1720 for _file in _tested_files_list: | 1770 for _file in _tested_files_list: |
1721 self.__budget.addFile(_record_code.encode("utf8"), _file[0], _file[1], _file[2]) | 1771 self.__budget.addFile(_record_code.encode("utf8"), _file[0], |
1772 _file[1], _file[2]) | |
1722 self.__statistics.valid = self.__statistics.valid +1 | 1773 self.__statistics.valid = self.__statistics.valid +1 |
1723 | 1774 |
1724 def _parseB(self, field_list): | 1775 def _parseB(self, field_list): |
1725 """_parseB(field_list) | 1776 """_parseB(field_list) |
1726 | 1777 |
1818 # The record must have 3 fields | 1869 # The record must have 3 fields |
1819 if len(field_list) > 3: | 1870 if len(field_list) > 3: |
1820 field_list = field_list[0:3] | 1871 field_list = field_list[0:3] |
1821 field_list = field_list[1:] | 1872 field_list = field_list[1:] |
1822 if len(field_list) != 2: | 1873 if len(field_list) != 2: |
1823 print(_("PyArq hates parametric DLLs") ) | 1874 print(_("PyArq hates parametric DLLs").encode("utf-8") ) |
1824 return | 1875 return |
1825 else: | 1876 else: |
1826 return | 1877 return |
1827 # _____Description_____ | 1878 # _____Description_____ |
1828 _description = field_list[1] | 1879 _description = field_list[1] |
1829 if _description == u"": | 1880 if _description == u"": |
1830 print(_("PyArq hates parametric DLLs") ) | 1881 print(_("PyArq hates parametric DLLs").encode("utf-8") ) |
1831 return | 1882 return |
1832 # Adding last end of line | 1883 # Adding last end of line |
1833 _description = _description + u"\r\n" | 1884 _description = _description + u"\r\n" |
1834 # Delete comments | 1885 # Delete comments |
1835 # "comment" : "#.*\r\n" | 1886 # "comment" : "#.*\r\n" |
1883 _final_line = u"" | 1934 _final_line = u"" |
1884 for index1 in range(len(_list)): | 1935 for index1 in range(len(_list)): |
1885 if index1 % 2 != 0: | 1936 if index1 % 2 != 0: |
1886 _parcial_line = u'"' + _list[index1] | 1937 _parcial_line = u'"' + _list[index1] |
1887 else: | 1938 else: |
1888 _parcial_line = u'"' + _list[index1].replace(u" ",u"") | 1939 _parcial_line = _list[index1].replace(u" ",u"") |
1940 _parcial_line = u'"' + _parcial_line | |
1889 _final_line = _final_line + _parcial_line | 1941 _final_line = _final_line + _parcial_line |
1890 _line = _final_line[1:] | 1942 _line = _final_line[1:] |
1891 _lines[index] = _line | 1943 _lines[index] = _line |
1892 # parse data | 1944 # parse data |
1893 if len(_line) > 2 and _line[:2] == u"::": | 1945 if len(_line) > 2 and _line[:2] == u"::": |
1909 index + _pass_line + 1 < len(_lines) -1: | 1961 index + _pass_line + 1 < len(_lines) -1: |
1910 _line = _line + _lines[index + _pass_line + 1] | 1962 _line = _line + _lines[index + _pass_line + 1] |
1911 _pass_line = _pass_line + 1 | 1963 _pass_line = _pass_line + 1 |
1912 _search = self.__pattern["var"].search(_line) | 1964 _search = self.__pattern["var"].search(_line) |
1913 if _search is not None: | 1965 if _search is not None: |
1914 _var = _search.groups()[0] + u" = " + _search.groups()[1] | 1966 _var0 = _search.groups()[0] |
1967 _var1 = _search.groups()[1] | |
1968 _var = _var0 + u" = " + _var1 | |
1915 #print("__VAR__" + str(_var) ) | 1969 #print("__VAR__" + str(_var) ) |
1916 pass | 1970 pass |
1917 else: | 1971 else: |
1918 #print( "no __VAR__", _line ) | 1972 #print( "no __VAR__", _line ) |
1919 pass | 1973 pass |
1920 elif self.__pattern["descomposition"].search(_line): | 1974 elif self.__pattern["descomposition"].search(_line): |
1921 # Delete spaces out " delimiter | 1975 # Delete spaces out " delimiter |
1922 #_patern = "(^[^:]*):(.*)$" | 1976 #_patern = "(^[^:]*):(.*)$" |
1923 _search = self.__pattern["descomposition"].search(_line) | 1977 _search = self.__pattern["descomposition"].search(_line) |
1924 if _search is not None: | 1978 if _search is not None: |
1925 _var = _search.groups()[0] + u":" + _search.groups()[1] | 1979 _var0 = _search.groups()[0] |
1980 _var1 = _search.groups()[1] | |
1981 _var = _var0 + u":" + _var1 | |
1926 #print( "__Descomposición__" + str(_var) ) | 1982 #print( "__Descomposición__" + str(_var) ) |
1927 pass | 1983 pass |
1928 else: | 1984 else: |
1929 #print("no __Descomposición__", _line ) | 1985 #print("no __Descomposición__", _line ) |
1930 pass | 1986 pass |
1931 else: | 1987 else: |
1932 print("Parametric: code: " + _family_code.encode("utf8") ) | 1988 _str = "Parametric: code: " + \ |
1933 print("******* Desconocido *** : " + _line ) | 1989 _family_code.encode("utf8") |
1934 if index-10 > 0: print("-11 : " + _lines[index-11].encode("utf8") ) | 1990 print(_str.encode("utf-8") ) |
1935 if index-10 > 0: print("-10 : " + _lines[index-10].encode("utf8") ) | 1991 _str = "******* Desconocido *** : " + _line |
1936 if index-9 > 0: print("-9 : " + _lines[index-9].encode("utf8") ) | 1992 print(_str.encode("utf-8") ) |
1937 if index-8 > 0: print("-8 : " + _lines[index-8].encode("utf8") ) | 1993 if index-10 > 0: |
1938 if index-7 > 0: print("-7 : " + _lines[index-7].encode("utf8") ) | 1994 print("-11 : " + _lines[index-11].encode("utf8") ) |
1939 if index-6 > 0: print("-6 : " + _lines[index-6].encode("utf8") ) | 1995 if index-10 > 0: |
1940 if index-5 > 0: print("-5 : " + _lines[index-5].encode("utf8") ) | 1996 print("-10 : " + _lines[index-10].encode("utf8") ) |
1941 if index-4 > 0: print("-4 : " + _lines[index-4].encode("utf8") ) | 1997 if index-9 > 0: |
1942 if index-3 > 0: print("-3 : " + _lines[index-3].encode("utf8") ) | 1998 print("-9 : " + _lines[index-9].encode("utf8") ) |
1943 if index-2 > 0: print("-2 : " + _lines[index-2].encode("utf8") ) | 1999 if index-8 > 0: |
1944 if index-1 > 0: print("-1 : " + _lines[index-1].encode("utf8") ) | 2000 print("-8 : " + _lines[index-8].encode("utf8") ) |
1945 print("-0 :" + _lines[index-0] ) | 2001 if index-7 > 0: |
2002 print("-7 : " + _lines[index-7].encode("utf8") ) | |
2003 if index-6 > 0: | |
2004 print("-6 : " + _lines[index-6].encode("utf8") ) | |
2005 if index-5 > 0: | |
2006 print("-5 : " + _lines[index-5].encode("utf8") ) | |
2007 if index-4 > 0: | |
2008 print("-4 : " + _lines[index-4].encode("utf8") ) | |
2009 if index-3 > 0: | |
2010 print("-3 : " + _lines[index-3].encode("utf8") ) | |
2011 if index-2 > 0: | |
2012 print("-2 : " + _lines[index-2].encode("utf8") ) | |
2013 if index-1 > 0: | |
2014 print("-1 : " + _lines[index-1].encode("utf8") ) | |
2015 print(("-0 :" + _lines[index-0]).encode("utf-8") ) | |
1946 pass | 2016 pass |
1947 else: | 2017 else: |
1948 _parameter_list = _line.split(u"\\")[1:-1] | 2018 _parameter_list = _line.split(u"\\")[1:-1] |
1949 if len(_parameter_list) >= 2: | 2019 if len(_parameter_list) >= 2: |
1950 if _parameter_list[0] == u"C" or \ | 2020 if _parameter_list[0] == u"C" or \ |
1951 _parameter_list[0] == u"COMENTARIO": | 2021 _parameter_list[0] == u"COMENTARIO": |
1952 #print( "__COMENTARIO__" + _parameter_list[1]) | 2022 #print( "__COMENTARIO__" + _parameter_list[1]) |
1953 self.__budget.setParametricSelectComment( | 2023 self.__budget.setParametricSelectComment( |
1954 _family_code.encode("utf8"), _parameter_list[1].encode("utf8")) | 2024 _family_code.encode("utf8"), |
2025 _parameter_list[1].encode("utf8")) | |
1955 elif _parameter_list[0] == u"R" or \ | 2026 elif _parameter_list[0] == u"R" or \ |
1956 _parameter_list[0] == u"RESUMEN": | 2027 _parameter_list[0] == u"RESUMEN": |
1957 #print( "__RESUMEN__" + _parameter_list[1]) | 2028 #print( "__RESUMEN__" + _parameter_list[1]) |
1958 self.__budget.setParametricSummary(_family_code.encode("utf8"), | 2029 self.__budget.setParametricSummary( |
2030 _family_code.encode("utf8"), | |
1959 _parameter_list[1].encode("utf8")) | 2031 _parameter_list[1].encode("utf8")) |
1960 elif _parameter_list[0] == u"T" or \ | 2032 elif _parameter_list[0] == u"T" or \ |
1961 _parameter_list[0] == u"TEXTO": | 2033 _parameter_list[0] == u"TEXTO": |
1962 #print( "__TEXTO__" + _parameter_list[1]) | 2034 #print( "__TEXTO__" + _parameter_list[1]) |
1963 self.__budget.setParametricText(_family_code.encode("utf8"), | 2035 self.__budget.setParametricText( |
2036 _family_code.encode("utf8"), | |
1964 _parameter_list[1].encode("utf8")) | 2037 _parameter_list[1].encode("utf8")) |
1965 elif _parameter_list[0] == u"P" or \ | 2038 elif _parameter_list[0] == u"P" or \ |
1966 _parameter_list[0] == u"PLIEGO": | 2039 _parameter_list[0] == u"PLIEGO": |
1967 #print( "__PLIEGO__" + str(_parameter_list[1:]) ) | 2040 #print( "__PLIEGO__" + str(_parameter_list[1:]) ) |
1968 pass | 2041 pass |
2015 interface.readFile_set_statistics(self.__statistics) | 2088 interface.readFile_set_statistics(self.__statistics) |
2016 _time = time.time() | 2089 _time = time.time() |
2017 try: | 2090 try: |
2018 _file = open(self.__filename, 'r') | 2091 _file = open(self.__filename, 'r') |
2019 except IOError: | 2092 except IOError: |
2020 print( utils.mapping("IOError: $1", (self.__filename,)) ) | 2093 _str = utils.mapping("IOError: $1", (self.__filename,)) |
2094 print( _str.encode("utf-8") ) | |
2021 return None | 2095 return None |
2022 _filesize = float(os.path.getsize(self.__filename)) | 2096 _filesize = float(os.path.getsize(self.__filename)) |
2023 if _filesize == 0.0: | 2097 if _filesize == 0.0: |
2024 print( utils.mapping("Empty File: $1", (self.__filename,)) ) | 2098 _str = utils.mapping("Empty File: $1", (self.__filename,)) |
2099 print( _str.encode("utf-8") ) | |
2025 # Todo: Create empty budget | 2100 # Todo: Create empty budget |
2026 return None | 2101 return None |
2027 self.__budget.filename = self.__filename | 2102 self.__budget.filename = self.__filename |
2028 interface.readFile_send_message(utils.mapping(_("Loading file $1"), | 2103 interface.readFile_send_message(utils.mapping(_("Loading file $1"), |
2029 (self.__filename,))) | 2104 (self.__filename,)).encode("utf-8")) |
2030 interface.readFile_progress(_file.tell() / _filesize) | 2105 interface.readFile_progress(_file.tell() / _filesize) |
2031 _buffer = _file.read(1000) | 2106 _buffer = _file.read(1000) |
2032 interface.updateGui() | 2107 interface.updateGui() |
2033 # set codepage from V record | 2108 # set codepage from V record |
2034 _record_list = _buffer.split("~") | 2109 _record_list = _buffer.split("~") |
2045 # remove leading spaces | 2120 # remove leading spaces |
2046 if _version in self.__character_sets_dict: | 2121 if _version in self.__character_sets_dict: |
2047 self.__character_set = self.__character_sets_dict[_version] | 2122 self.__character_set = self.__character_sets_dict[_version] |
2048 interface.readFile_send_message(utils.mapping( | 2123 interface.readFile_send_message(utils.mapping( |
2049 _("FIEBDC character encoding: $1"), | 2124 _("FIEBDC character encoding: $1"), |
2050 (self.__character_set,))) | 2125 (self.__character_set,)).encode("utf8")) |
2051 else: | 2126 else: |
2052 interface.readFile_send_message(utils.mapping( | 2127 interface.readFile_send_message(utils.mapping( |
2053 _("This Character encoding do not exist in "\ | 2128 _("This Character encoding do not exist in "\ |
2054 "FIEBDC3! Default Character encoding: $1"), | 2129 "FIEBDC3! Default Character encoding: $1"), |
2055 (self.__character_set,))) | 2130 (self.__character_set,)).encode("utf-8")) |
2056 else: | 2131 else: |
2057 interface.readFile_send_message(utils.mapping(_( | 2132 interface.readFile_send_message(utils.mapping(_( |
2058 "This V record dot have a character encoding! "\ | 2133 "This V record dot have a character encoding! "\ |
2059 "Default character encoding: $1"), | 2134 "Default character encoding: $1"), |
2060 (self.__character_set,))) | 2135 (self.__character_set,)).encode("utf-8")) |
2061 else: | 2136 else: |
2062 interface.readFile_send_message(utils.mapping(_( | 2137 interface.readFile_send_message(utils.mapping(_( |
2063 "Not 'V' record in File! Default character encoding: "\ | 2138 "Not 'V' record in File! Default character encoding: "\ |
2064 "$1"), (self.__character_set,))) | 2139 "$1"), (self.__character_set,)).encode("utf-8")) |
2065 _buffer = unicode(_buffer, self.__character_set) | 2140 _buffer = unicode(_buffer, self.__character_set) |
2066 interface.updateGui() | 2141 interface.updateGui() |
2067 # Any INFORMATION between the beginning of the file and the | 2142 # Any INFORMATION between the beginning of the file and the |
2068 # beginning of the first registry “~” is ignored | 2143 # beginning of the first registry “~” is ignored |
2069 #"after_first_tilde" : "^[^~]*~" | 2144 #"after_first_tilde" : "^[^~]*~" |
2105 interface.readFile_cancel() | 2180 interface.readFile_cancel() |
2106 return None | 2181 return None |
2107 else: | 2182 else: |
2108 self.__statistics.time = time.time()-_time | 2183 self.__statistics.time = time.time()-_time |
2109 if self.__statistics.O > 0: | 2184 if self.__statistics.O > 0: |
2110 interface.readFile_send_message( | 2185 _str = utils.mapping( |
2111 utils.mapping(_("$1 unsuported record type O: "\ | 2186 _("$1 unsuported record type O: Comercial Relationship"), |
2112 "Comercial Relationship"), (str(self.__statistics.O,)))) | 2187 (str(self.__statistics.O,))) |
2188 interface.readFile_send_message(_str.encode("utf-8")) | |
2113 if self.__statistics.valid == 0: | 2189 if self.__statistics.valid == 0: |
2114 interface.readFile_send_message(_("This file is not a valid FIBDC3 file")) | 2190 _str = _("This file is not a valid FIBDC3 file") |
2191 interface.readFile_send_message(_str.encode("utf-8")) | |
2115 return None | 2192 return None |
2116 interface.readFile_end() | 2193 interface.readFile_end() |
2117 self._testBudget(self.__budget, interface) | 2194 self._testBudget(self.__budget, interface) |
2118 return None | 2195 return None |
2119 | 2196 |
2122 | 2199 |
2123 budget: base.obra object | 2200 budget: base.obra object |
2124 Test and repair budget object after read it from bc3 file | 2201 Test and repair budget object after read it from bc3 file |
2125 """ | 2202 """ |
2126 # TODO: more to do here | 2203 # TODO: more to do here |
2127 print( _("Testing budget ...") ) | 2204 print( _("Testing budget ...").encode("utf-8") ) |
2128 # Add price to records without price | 2205 # Add price to records without price |
2129 _iter = budget.iter() | 2206 _iter = budget.iter() |
2130 _titlelist = budget.getTitleList()[1] | 2207 _titlelist = budget.getTitleList()[1] |
2131 if len(_titlelist) == 0: | 2208 if len(_titlelist) == 0: |
2132 _titlenum = 1 | 2209 _titlenum = 1 |
2141 for _index in range(0,_leftprices): | 2218 for _index in range(0,_leftprices): |
2142 _root = budget.getRecord(budget.getRoot()) | 2219 _root = budget.getRecord(budget.getRoot()) |
2143 _price = [0.0, _root.getDate(_len_prices + _index)] | 2220 _price = [0.0, _root.getDate(_len_prices + _index)] |
2144 budget.addPriceToRecord(_price,_record) | 2221 budget.addPriceToRecord(_price,_record) |
2145 interface.updateGui() | 2222 interface.updateGui() |
2146 print( _("End Test") ) | 2223 print(_("End Test").encode("utf-8")) |
2147 | 2224 |
2148 def delete_control_space(self, text): | 2225 def delete_control_space(self, text): |
2149 text = self.delete_control(text) | 2226 text = self.delete_control(text) |
2150 text = text.replace(u" ", u"") | 2227 text = text.replace(u" ", u"") |
2151 return text | 2228 return text |
2199 | 2276 |
2200 message: mesage from readFile method | 2277 message: mesage from readFile method |
2201 | 2278 |
2202 print( message ) | 2279 print( message ) |
2203 """ | 2280 """ |
2204 print( message ) | 2281 print( message.encode("utf-8") ) |
2205 | 2282 |
2206 def readFile_progress(self, percent): | 2283 def readFile_progress(self, percent): |
2207 """progress(percent) | 2284 """progress(percent) |
2208 | 2285 |
2209 percent: Percentage executed. | 2286 percent: Percentage executed. |
2216 """readFile_end() | 2293 """readFile_end() |
2217 | 2294 |
2218 The readFile method end successfully | 2295 The readFile method end successfully |
2219 """ | 2296 """ |
2220 self.endSuccessfully == True | 2297 self.endSuccessfully == True |
2221 print(self.__statistics) | 2298 print(self.__statistics.encode("utf-8")) |
2222 print("progreso = " + str(self.__progress)) | 2299 print(("progreso = " + str(self.__progress)).encode("utf-8")) |
2223 | 2300 |
2224 def readFile_cancel(self): | 2301 def readFile_cancel(self): |
2225 """readFile_cancel() | 2302 """readFile_cancel() |
2226 | 2303 |
2227 The readFile method is canceled | 2304 The readFile method is canceled |
2228 """ | 2305 """ |
2229 self.endSuccessfully == False | 2306 self.endSuccessfully == False |
2230 print( _("Process terminated") ) | 2307 print( _("Process terminated").encode("utf-8") ) |
2231 print("progreso = " + str(self.__progress)) | 2308 print(("progreso = " + str(self.__progress)).encode("utf-8")) |
2232 | 2309 |
2233 def updateGui(self): | 2310 def updateGui(self): |
2234 """updateGui(self) | 2311 """updateGui(self) |
2235 | 2312 |
2236 Some interfaces need update gui while doing some time intensive | 2313 Some interfaces need update gui while doing some time intensive |
2303 self.A = 0 | 2380 self.A = 0 |
2304 self.unknow = 0 | 2381 self.unknow = 0 |
2305 self.time = 0.0 | 2382 self.time = 0.0 |
2306 | 2383 |
2307 def __str__(self): | 2384 def __str__(self): |
2308 return self.str().encode("utf8") | 2385 return self.str() |
2309 | 2386 |
2310 def str(self): | 2387 def str(self): |
2311 | 2388 _str = utils.mapping(_("Time to load: $1 seconds"), |
2312 return utils.mapping(_("Time to load: $1 seconds"), | |
2313 (("%.2f" %(self.time)),)) + "\n" + \ | 2389 (("%.2f" %(self.time)),)) + "\n" + \ |
2314 utils.mapping(_("Records/Valid Records: $1/$2"), | 2390 utils.mapping(_("Records/Valid Records: $1/$2"), |
2315 (str(self.records), str(self.valid))) + "\n" +\ | 2391 (str(self.records), str(self.valid))) + "\n" +\ |
2316 "V: %s\n" %(self.V,) + \ | 2392 "V: %s\n" %(self.V,) + \ |
2317 "C: %s\n" %(self.C,) + \ | 2393 "C: %s\n" %(self.C,) + \ |
2332 "X: %s\n" %(self.X,) + \ | 2408 "X: %s\n" %(self.X,) + \ |
2333 "B: %s\n" %(self.B,) + \ | 2409 "B: %s\n" %(self.B,) + \ |
2334 "F: %s\n" %(self.F,) + \ | 2410 "F: %s\n" %(self.F,) + \ |
2335 "A: %s\n" %(self.A,) + \ | 2411 "A: %s\n" %(self.A,) + \ |
2336 "?: %s\n" %(self.unknow,) | 2412 "?: %s\n" %(self.unknow,) |
2337 | 2413 return _str.encode("utf8") |
2414 |