Mercurial > pyarq-presupuestos
comparison Generic/fiebdc.py @ 17:a7b9f7e7dfa4
Improvements importing FIEBDC files
| author | Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es> |
|---|---|
| date | Sat, 02 Nov 2013 19:26:09 +0100 |
| parents | 0359329a1c26 |
| children | 878159a13494 |
comparison
equal
deleted
inserted
replaced
| 16:60bc5117926c | 17:a7b9f7e7dfa4 |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
| 3 ## File fiebdc.py | 3 ## File fiebdc.py |
| 4 ## This file is part of pyArq-Presupuestos. | 4 ## This file is part of pyArq-Presupuestos. |
| 5 ## | 5 ## |
| 6 ## Copyright (C) 2010 Miguel Ángel Bárcena Rodríguez | 6 ## Copyright (C) 2010-2013 Miguel Ángel Bárcena Rodríguez |
| 7 ## <miguelangel@obraencurso.es> | 7 ## <miguelangel@obraencurso.es> |
| 8 ## | 8 ## |
| 9 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify | 9 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify |
| 10 ## it under the terms of the GNU General Public License as published by | 10 ## it under the terms of the GNU General Public License as published by |
| 11 ## the Free Software Foundation, either version 3 of the License, or | 11 ## the Free Software Foundation, either version 3 of the License, or |
| 24 # Modules | 24 # Modules |
| 25 import time | 25 import time |
| 26 import re | 26 import re |
| 27 import calendar | 27 import calendar |
| 28 import os.path | 28 import os.path |
| 29 | 29 import unicodedata |
| 30 import hashlib | |
| 30 # pyArq-Presupuestos modules | 31 # pyArq-Presupuestos modules |
| 31 import base | 32 import base |
| 32 from Generic import utils | 33 from Generic import utils |
| 33 from Generic import globalVars | 34 from Generic import globalVars |
| 34 | 35 |
| 95 "437" : "cp437"} | 96 "437" : "cp437"} |
| 96 self.__file_format = "FIEBDC-3/2007" | 97 self.__file_format = "FIEBDC-3/2007" |
| 97 self.__generator = globalVars.version | 98 self.__generator = globalVars.version |
| 98 self.__character_set = "850" | 99 self.__character_set = "850" |
| 99 self.__pattern = { | 100 self.__pattern = { |
| 100 "control_tilde" : re.compile("((\r\n)| |\t)+~"), | 101 "control_tilde" : re.compile(u"((\r\n)| |\t)+~"), |
| 101 "control_vbar" : re.compile("((\r\n)| |\t)+\|"), | 102 "control_vbar" : re.compile(u"((\r\n)| |\t)+\|"), |
| 102 "control_backslash" : re.compile(r"((\r\n)| |\t)+\\"), | 103 "control_backslash" : re.compile(ur"((\r\n)| |\t)+\\"), |
| 103 "valid_code" : re.compile("[^A-Za-z0-9ñÑ.$#%&_]"), | 104 "valid_code" : re.compile(u"[^A-Za-z0-9ñÑ.$#%&_]"), |
| 104 "special_char": re.compile("[#%&]"), | 105 "special_char": re.compile(u"[#%&]"), |
| 105 "no_float": re.compile("[^0-9.]"), | 106 "no_float": re.compile(u"[^0-9.]"), |
| 106 "formula" : re.compile(".*[^0123456789\.()\+\-\*/\^abcdp ].*"), | 107 "formula" : re.compile(u".*[^0123456789\.()\+\-\*/\^abcdp ].*"), |
| 107 "comment": re.compile("#.*\r\n"), | 108 "comment": re.compile(u"#.*\r\n"), |
| 108 "empty_line": re.compile(r"(\r\n) *\r\n"), | 109 "empty_line": re.compile(ur"(\r\n) *\r\n"), |
| 109 "space_before_backslash" : re.compile(r"( )+\\"), | 110 "space_before_backslash" : re.compile(ur"( )+\\"), |
| 110 "space_after_backslash" : re.compile(r"\\( )+"), | 111 "space_after_backslash" : re.compile(ur"\\( )+"), |
| 111 "start_noend_backslash" : re.compile("(\r\n\\\.*[^\\\])\r\n"), | 112 "start_noend_backslash" : re.compile(u"(\r\n\\\.*[^\\\])\r\n"), |
| 112 "end_oper": re.compile("(\+|-|\*|/|/^|@|&|<|>|<=|>=|=|!) *\r\n"), | 113 "end_oper": re.compile(u"(\+|-|\*|/|/^|@|&|<|>|<=|>=|=|!) *\r\n"), |
| 113 "matricial_var" : re.compile("(\r\n *[%|\$][A-ZÑ].*=.*,) *\r\n"), | 114 "matricial_var" : re.compile(u"(\r\n *[%|\$][A-ZÑ].*=.*,) *\r\n"), |
| 114 "descomposition" : re.compile("^([^:]+):(.*)$"), | 115 "descomposition" : re.compile(u"^([^:]+):(.*)$"), |
| 115 "var" : re.compile("^([$%][A-ZÑ][()0-9, ]*)=(.*)$"), | 116 "var" : re.compile(u"^([$%][A-ZÑ][()0-9, ]*)=(.*)$"), |
| 116 "after_first_tilde" : re.compile("^[^~]*~"), | 117 "after_first_tilde" : re.compile(u"^[^~]*~"), |
| 117 "end_control" : re.compile("((\r\n)| |\t)+$"), | 118 "end_control" : re.compile(u"((\r\n)| |\t)+$"), |
| 118 } | 119 } |
| 119 | 120 |
| 120 def cancel(self): | 121 def cancel(self): |
| 121 """def cancel(self) | 122 """def cancel(self) |
| 122 | 123 |
| 132 '~', '|' erased. | 133 '~', '|' erased. |
| 133 Before separator \ not deleted because it affects the reading of the | 134 Before separator \ not deleted because it affects the reading of the |
| 134 record ~P | 135 record ~P |
| 135 """ | 136 """ |
| 136 # "control_tilde" : "((\r\n)| |\t)+~" | 137 # "control_tilde" : "((\r\n)| |\t)+~" |
| 137 string = self.__pattern["control_tilde"].sub("~",string) | 138 string = self.__pattern["control_tilde"].sub(u"~",string) |
| 138 # "control_vbar" : "((\r\n)| |\t)+\|" | 139 # "control_vbar" : "((\r\n)| |\t)+\|" |
| 139 string = self.__pattern["control_vbar"].sub("|",string) | 140 string = self.__pattern["control_vbar"].sub(u"|",string) |
| 140 # "control_backslash" : r"((\r\n)| |\t)+\\" | 141 # "control_backslash" : r"((\r\n)| |\t)+\\" |
| 141 #string = self.__pattern["control_backslash"].sub(r"\\",string) | 142 #string = self.__pattern["control_backslash"].sub(r"\\",string) |
| 142 return string | 143 return string |
| 143 | 144 |
| 144 def validateCode(self, code): | 145 def validateCode(self, code): |
| 145 """validateCode(self, code) | 146 """validateCode(self, code) |
| 146 | 147 |
| 147 Test if the code have invalid characters and try to erase it, | 148 Test if the code have invalid characters and try to erase it, |
| 148 if it is posible return a valid code else return a empty string. | 149 if it is posible return a valid code else return a empty string. |
| 149 """ | 150 """ |
| 150 if not isinstance(code, str): | 151 if not isinstance(code, unicode): |
| 151 print _("Invalid code, it must be a string") | 152 print _("Invalid code, it must be a unicode string") |
| 152 return "" | 153 return u"" |
| 153 # Valid chararcter: A-Z a-z 0-9 ñ Ñ . $ # % & _ | 154 # Valid chararcter: A-Z a-z 0-9 ñ Ñ . $ # % & _ |
| 154 # "valid_code" : "[^A-Za-z0-9ñÑ.$#%&_]" | 155 # "valid_code" : "[^A-Za-z0-9ñÑ.$#%&_]" |
| 155 _code = self.__pattern["valid_code"].sub("", code) | 156 _ucode = self.__pattern["valid_code"].sub(u"", code) |
| 156 if _code != code: | 157 if _ucode != code: |
| 157 print utils.mapping(_("The code '$1' have invalid characters."), | 158 try: |
| 158 (code,)) | 159 print utils.mapping(_("The code '$1' have invalid characters."), |
| 159 code = _code | 160 (code.encode("utf8"),)) |
| 161 except: | |
| 162 print utils.mapping(_("The code '$1' have invalid characters and can not be encoded in utf8."), (code,)) | |
| 163 | |
| 164 if len(_ucode) == 0: | |
| 165 _normalize_code = ''.join((c for c in unicodedata.normalize('NFD', _ucode) if unicodedata.category(c) != 'Mn')) | |
| 166 # from http://www.leccionespracticas.com/uncategorized/eliminar-tildes-con-python-solucionado/ | |
| 167 _ucode = self.__pattern["valid_code"].sub(u"", _normalize_code) | |
| 168 if len(_ucode) == 0: | |
| 169 _hash_code = hashlib.sha256() | |
| 170 _hash_code.update(code.encode('utf-8')) | |
| 171 _hexdigest_code = _hash_code.hexdigest() | |
| 172 _ucode = self.__pattern["valid_code"].sub(u"", _hexdigest_code) | |
| 173 code = _ucode | |
| 160 # the lasts characters can not be <#> or <##> | 174 # the lasts characters can not be <#> or <##> |
| 161 # <##> -> root record in FIEFDC-3 | 175 # <##> -> root record in FIEFDC-3 |
| 162 # <#> -> chapter record in FIEFDC-3 | 176 # <#> -> chapter record in FIEFDC-3 |
| 163 if len(code) > 0: | 177 if len(code) > 0: |
| 164 while code[-1] == "#": | 178 while code[-1] == u"#": |
| 165 code = code[:-1] | 179 code = code[:-1] |
| 166 if len(code) > 20: | 180 if len(code) > 20: |
| 167 code = code[:20] | 181 code = code[:20] |
| 168 # only one charecter # % or & | 182 # only one charecter # % or & |
| 169 if sum([code.count(c) for c in '#%&']) > 1: | 183 if sum([code.count(c) for c in u'#%&']) > 1: |
| 170 print utils.mapping(_("The code '$1' contains special "\ | 184 print utils.mapping(_("The code '$1' contains special "\ |
| 171 "characters repeated."),(code,)) | 185 "characters repeated."),(code.encode("utf8"),)) |
| 172 _i = min([code.find(c) for c in '#%&']) | 186 _i = min([code.find(c) for c in u'#%&']) |
| 173 code = code[:_i+1] + \ | 187 code = code[:_i+1] + \ |
| 174 self.__pattern["special_char"].sub("", code[_i+1:]) | 188 self.__pattern["special_char"].sub(u"", code[_i+1:]) |
| 175 return code | 189 return code |
| 176 | 190 |
| 177 def parseDate(self, date): | 191 def parseDate(self, date): |
| 178 """parseDate(self, date) | 192 """parseDate(self, date) |
| 179 | 193 |
| 185 len < 3 YY | 199 len < 3 YY |
| 186 Test date string and return a tuple (YYYY, MM, DD) | 200 Test date string and return a tuple (YYYY, MM, DD) |
| 187 or None if the date format is invalid | 201 or None if the date format is invalid |
| 188 """ | 202 """ |
| 189 # All characters must be numbers, len <= 8 and not empty string | 203 # All characters must be numbers, len <= 8 and not empty string |
| 190 if not date.isdigit() or len(date) > 8 or date == "": | 204 if not date.isdigit() or len(date) > 8 or date == u"": |
| 191 return None | 205 return None |
| 192 else: | 206 else: |
| 193 if len(date)%2 == 1: # uneven len: add a leading 0 | 207 if len(date)%2 == 1: # uneven len: add a leading 0 |
| 194 date = "0" + date | 208 date = u"0" + date |
| 195 if len(date) == 8: | 209 if len(date) == 8: |
| 196 _d = int(date[:2]) | 210 _d = int(date[:2]) |
| 197 _m = int(date[2:4]) | 211 _m = int(date[2:4]) |
| 198 _y = int(date[4:8]) | 212 _y = int(date[4:8]) |
| 199 elif len(date) <= 6: | 213 elif len(date) <= 6: |
| 305 # TODO: ~L ~J RTF and HTML files | 319 # TODO: ~L ~J RTF and HTML files |
| 306 # TODO: test ~Q ~J ~G | 320 # TODO: test ~Q ~J ~G |
| 307 # TODO: ~P. Registro tipo Descripción Paramétrica. | 321 # TODO: ~P. Registro tipo Descripción Paramétrica. |
| 308 # TODO: ~O. Registro tipo Relación Comercial. | 322 # TODO: ~O. Registro tipo Relación Comercial. |
| 309 # TODO: test records | 323 # TODO: test records |
| 310 _field_list = record.split("|") | 324 _field_list = record.split(u"|") |
| 311 self._record_number = self._record_number +1 | 325 self._record_number = self._record_number +1 |
| 312 _budget = self.__budget | 326 _budget = self.__budget |
| 313 if _field_list[0] == "V": | 327 if _field_list[0] == u"V": |
| 314 self._record_V_number += 1 | 328 self._record_V_number += 1 |
| 315 self._parseV(_field_list) | 329 self._parseV(_field_list) |
| 316 elif _field_list[0] == "C": | 330 elif _field_list[0] == u"C": |
| 317 self._record_C_number += 1 | 331 self._record_C_number += 1 |
| 318 self._parseC(_field_list) | 332 self._parseC(_field_list) |
| 319 elif _field_list[0] == "D": | 333 elif _field_list[0] == u"D": |
| 320 self._record_D_number += 1 | 334 self._record_D_number += 1 |
| 321 self._parseDY(_field_list) | 335 self._parseDY(_field_list) |
| 322 elif _field_list[0] == "Y": | 336 elif _field_list[0] == u"Y": |
| 323 self._record_Y_number += 1 | 337 self._record_Y_number += 1 |
| 324 self._parseDY(_field_list) | 338 self._parseDY(_field_list) |
| 325 elif _field_list[0] == "M": | 339 elif _field_list[0] == u"M": |
| 326 self._record_M_number += 1 | 340 self._record_M_number += 1 |
| 327 self._parseMN(_field_list) | 341 self._parseMN(_field_list) |
| 328 elif _field_list[0] == "N": | 342 elif _field_list[0] == u"N": |
| 329 self._record_N_number += 1 | 343 self._record_N_number += 1 |
| 330 self._parseMN(_field_list) | 344 self._parseMN(_field_list) |
| 331 elif _field_list[0] == "T": | 345 elif _field_list[0] == u"T": |
| 332 self._record_T_number += 1 | 346 self._record_T_number += 1 |
| 333 self._parseT(_field_list) | 347 self._parseT(_field_list) |
| 334 elif _field_list[0] == "K": | 348 elif _field_list[0] == u"K": |
| 335 self._record_K_number += 1 | 349 self._record_K_number += 1 |
| 336 self._parseK(_field_list) | 350 self._parseK(_field_list) |
| 337 elif _field_list[0] == "W": | 351 elif _field_list[0] == u"W": |
| 338 self._record_W_number += 1 | 352 self._record_W_number += 1 |
| 339 self._parseW(_field_list) | 353 self._parseW(_field_list) |
| 340 elif _field_list[0] == "L": | 354 elif _field_list[0] == u"L": |
| 341 self._record_L_number += 1 | 355 self._record_L_number += 1 |
| 342 self._parseL(_field_list) | 356 self._parseL(_field_list) |
| 343 elif _field_list[0] == "Q": | 357 elif _field_list[0] == u"Q": |
| 344 self._record_Q_number += 1 | 358 self._record_Q_number += 1 |
| 345 self._parseQ(_field_list) | 359 self._parseQ(_field_list) |
| 346 elif _field_list[0] == "J": | 360 elif _field_list[0] == u"J": |
| 347 self._record_J_number += 1 | 361 self._record_J_number += 1 |
| 348 self._parseJ(_field_list) | 362 self._parseJ(_field_list) |
| 349 elif _field_list[0] == "G": | 363 elif _field_list[0] == u"G": |
| 350 self._record_G_number += 1 | 364 self._record_G_number += 1 |
| 351 self._parseG(_field_list) | 365 self._parseG(_field_list) |
| 352 elif _field_list[0] == "E": | 366 elif _field_list[0] == u"E": |
| 353 self._record_E_number += 1 | 367 self._record_E_number += 1 |
| 354 self._parseE(_field_list) | 368 self._parseE(_field_list) |
| 355 elif _field_list[0] == "O": | 369 elif _field_list[0] == "O": |
| 356 self._record_O_number += 1 | 370 self._record_O_number += 1 |
| 357 elif _field_list[0] == "P": | 371 elif _field_list[0] == u"P": |
| 358 self._record_P_number += 1 | 372 self._record_P_number += 1 |
| 359 self._parseP(_field_list) | 373 self._parseP(_field_list) |
| 360 elif _field_list[0] == "X": | 374 elif _field_list[0] == u"X": |
| 361 self._record_X_number += 1 | 375 self._record_X_number += 1 |
| 362 self._parseX(_field_list) | 376 self._parseX(_field_list) |
| 363 elif _field_list[0] == "B": | 377 elif _field_list[0] == u"B": |
| 364 self._record_B_number += 1 | 378 self._record_B_number += 1 |
| 365 self._parseB(_field_list) | 379 self._parseB(_field_list) |
| 366 elif _field_list[0] == "F": | 380 elif _field_list[0] == u"F": |
| 367 self._record_F_number += 1 | 381 self._record_F_number += 1 |
| 368 self._parseF(_field_list) | 382 self._parseF(_field_list) |
| 369 elif _field_list[0] == "A": | 383 elif _field_list[0] == u"A": |
| 370 self._record_A_number += 1 | 384 self._record_A_number += 1 |
| 371 self._parseA(_field_list) | 385 self._parseA(_field_list) |
| 372 else: | 386 else: |
| 373 self._record_Unknow_number += 1 | 387 self._record_Unknow_number += 1 |
| 374 | 388 |
| 399 if len(field_list) > 10: | 413 if len(field_list) > 10: |
| 400 field_list = field_list[:10] | 414 field_list = field_list[:10] |
| 401 # If there are no sufficient fields, the fields are added | 415 # If there are no sufficient fields, the fields are added |
| 402 # with empty value:"" | 416 # with empty value:"" |
| 403 else: | 417 else: |
| 404 field_list = field_list + [""]*(10-len(field_list)) | 418 field_list = field_list + [u""]*(10-len(field_list)) |
| 405 # control character are erased: end of line, tab, space | 419 # control character are erased: end of line, tab, space |
| 406 # only leading and trailing whitespace in owner, generator, comment | 420 # only leading and trailing whitespace in owner, generator, comment |
| 407 # _____Fields_____ | 421 # _____Fields_____ |
| 408 _record_type = self.delete_control_space(field_list[0]) | 422 _record_type = self.delete_control_space(field_list[0]) |
| 409 _owner = field_list[1].strip() | 423 _owner = field_list[1].strip() |
| 412 _generator = field_list[3].strip() | 426 _generator = field_list[3].strip() |
| 413 _generator = self.delete_control(_generator) | 427 _generator = self.delete_control(_generator) |
| 414 _header_title = field_list[4].strip() | 428 _header_title = field_list[4].strip() |
| 415 _header_title = self.delete_control(_header_title) | 429 _header_title = self.delete_control(_header_title) |
| 416 _character_set = self.delete_control_space(field_list[5]) | 430 _character_set = self.delete_control_space(field_list[5]) |
| 417 _comment = field_list[6].strip("\t \n\r") | 431 _comment = field_list[6].strip(u"\t \n\r") |
| 418 _data_type = self.delete_control_space(field_list[7]) | 432 _data_type = self.delete_control_space(field_list[7]) |
| 419 _number_certificate = self.delete_control_space(field_list[8]) | 433 _number_certificate = self.delete_control_space(field_list[8]) |
| 420 __date_certificate = self.delete_control_space(field_list[9]) | 434 __date_certificate = self.delete_control_space(field_list[9]) |
| 421 # _____Owner_____ | 435 # _____Owner_____ |
| 422 self.__budget.setOwner(_owner) | 436 self.__budget.setOwner(_owner) |
| 423 # _____Version-Date_____ | 437 # _____Version-Date_____ |
| 424 _version_date = _version_date.split("\\") | 438 _version_date = _version_date.split(u"\\") |
| 425 _file_format = _version_date[0] | 439 _file_format = _version_date[0] |
| 426 if _file_format in self.__format_list: | 440 if _file_format in self.__format_list: |
| 427 self.__file_format = _file_format | 441 self.__file_format = _file_format |
| 428 print _("FIEBDC format: %s" % _file_format) | 442 print utils.mapping(_("FIEBDC format: $1"),(_file_format,)) |
| 443 | |
| 429 if len(_version_date) > 1: | 444 if len(_version_date) > 1: |
| 430 _date = _version_date[1] | 445 _date = _version_date[1] |
| 431 if _date != "": | 446 if _date != u"": |
| 432 _parsed_date = self.parseDate(_date) | 447 _parsed_date = self.parseDate(_date) |
| 433 if _parsed_date is not None: | 448 if _parsed_date is not None: |
| 434 self.__budget.setDate(_parsed_date) | 449 self.__budget.setDate(_parsed_date) |
| 435 # _____Generator_____ | 450 # _____Generator_____ |
| 436 # ignored field | 451 # ignored field |
| 437 print _("FIEBDC file generated by %s" % _generator) | 452 print utils.mapping(_("FIEBDC file generated by $1"),(_generator,)) |
| 438 # _____Header_Title_____ | 453 # _____Header_Title_____ |
| 439 _header_title = _header_title.split("\\") | 454 _header_title = _header_title.split(u"\\") |
| 440 _header_title = [_title.strip() for _title in _header_title] | 455 _header_title = [_title.strip() for _title in _header_title] |
| 441 _header = _header_title.pop(0) | 456 _header = _header_title.pop(0) |
| 457 _header = [_item.encode("utf8") for _item in _header] | |
| 442 _title = [ ] | 458 _title = [ ] |
| 443 for _title_index in _header_title: | 459 for _title_index in _header_title: |
| 444 if _title_index != "": | 460 if _title_index != u"": |
| 445 _title.append(_title_index) | 461 _title.append(_title_index) |
| 446 if _header != "": | 462 _title = [_item.encode("utf8") for _item in _title] |
| 447 self.__budget.setTitleList([ _header, _title ]) | 463 if _header != u"": |
| 464 self.__budget.setTitleList([ _header, _title]) | |
| 448 # _____Characters_set_____ | 465 # _____Characters_set_____ |
| 449 # field parsed in readFile method | 466 # field parsed in readFile method |
| 450 # _____Comment_____ | 467 # _____Comment_____ |
| 451 if _comment != "": | 468 if _comment != u"": |
| 452 self.__budget.setComment(_comment) | 469 self.__budget.setComment(_comment.encode("utf8")) |
| 453 # _____Data type_____ | 470 # _____Data type_____ |
| 454 # 1 -> Base data. | 471 # 1 -> Base data. |
| 455 # 2 -> Budget. | 472 # 2 -> Budget. |
| 456 # 3 -> Budget certificate. | 473 # 3 -> Budget certificate. |
| 457 # 4 -> Base date update. | 474 # 4 -> Base date update. |
| 506 # _____Fields_____ | 523 # _____Fields_____ |
| 507 _field0 = self.delete_control_space(field_list[0]) | 524 _field0 = self.delete_control_space(field_list[0]) |
| 508 _field1 = self.delete_control_space(field_list[1]) | 525 _field1 = self.delete_control_space(field_list[1]) |
| 509 _field2 = self.delete_control_space(field_list[2]) | 526 _field2 = self.delete_control_space(field_list[2]) |
| 510 # _____Field 1_____ | 527 # _____Field 1_____ |
| 511 if len(_field1) > 0 and _field1[-1] == "\\": | 528 if len(_field1) > 0 and _field1[-1] == u"\\": |
| 512 _field1 = _field1[:-1] | 529 _field1 = _field1[:-1] |
| 513 # if there are a \ character at the end it must be erased | 530 # if there are a \ character at the end it must be erased |
| 514 _percentages = _field1.split("\\") | 531 _percentages = _field1.split(u"\\") |
| 515 if len(_percentages) > 5: | 532 if len(_percentages) > 5: |
| 516 _percentages = _percentages[:5] | 533 _percentages = _percentages[:5] |
| 517 # If there are no sufficient subfields, the subfields are added | 534 # If there are no sufficient subfields, the subfields are added |
| 518 # with empty value:"" | 535 # with empty value:"" |
| 519 else: | 536 else: |
| 520 _percentages = _percentages + [""]*(5-len(_percentages)) | 537 _percentages = _percentages + [u""]*(5-len(_percentages)) |
| 521 _percentage_titles = [ "CI", "GG", "BI", "BAJA", "IVA" ] | 538 _percentage_titles = [ "CI", "GG", "BI", "BAJA", "IVA" ] |
| 522 _percentage_dict = {} | 539 _percentage_dict = {} |
| 523 for _percentage_index in range(len(_percentages)): | 540 for _percentage_index in range(len(_percentages)): |
| 524 try: | 541 try: |
| 525 _percentage = int(_percentages[_percentage_index]) | 542 _percentage = int(_percentages[_percentage_index]) |
| 532 # Default number of decimal places | 549 # Default number of decimal places |
| 533 # Number of titles in ~V record | 550 # Number of titles in ~V record |
| 534 _title_num = len(self.__budget.getTitleList()[1]) | 551 _title_num = len(self.__budget.getTitleList()[1]) |
| 535 if _title_num == 0: _title_num = 1 | 552 if _title_num == 0: _title_num = 1 |
| 536 # If the field 2 is empty, the field 0 is readed | 553 # If the field 2 is empty, the field 0 is readed |
| 537 if _field2 == "": | 554 if _field2 == u"": |
| 538 # _____Field 0_____ | 555 # _____Field 0_____ |
| 539 if _field0[-1] == "\\": | 556 if _field0[-1] == u"\\": |
| 540 _field0 = _field0[:-1] | 557 _field0 = _field0[:-1] |
| 541 # if there are a \ character at the end it must be erased | 558 # if there are a \ character at the end it must be erased |
| 542 _decimal_list = _field0.split("\\") | 559 _decimal_list = _field0.split(u"\\") |
| 543 _decimal_index = 0 | 560 _decimal_index = 0 |
| 544 if len(_decimal_list)%9 != 0: | 561 if len(_decimal_list)%9 != 0: |
| 545 # if it is not multiple of 9, empty subfield are added | 562 # if it is not multiple of 9, empty subfield are added |
| 546 _decimal_list = _decimal_list + [""]*(9 - \ | 563 _decimal_list = _decimal_list + [""]*(9 - \ |
| 547 len(_decimal_list)%9) | 564 len(_decimal_list)%9) |
| 738 if len(field_list) > 7: | 755 if len(field_list) > 7: |
| 739 field_list = field_list[:7] | 756 field_list = field_list[:7] |
| 740 # If there are no sufficient fields, the fields are added | 757 # If there are no sufficient fields, the fields are added |
| 741 # with empty value:"" | 758 # with empty value:"" |
| 742 else: | 759 else: |
| 743 field_list = field_list + [""]*(7-len(field_list)) | 760 field_list = field_list + [u""]*(7-len(field_list)) |
| 744 # control character are erased: en of line, tab, space | 761 # control character are erased: en of line, tab, space |
| 745 # _____Fields_____ | 762 # _____Fields_____ |
| 746 _record_type = field_list[0] | 763 _record_type = field_list[0] |
| 747 _codes = self.delete_control_space(field_list[1]) | 764 _codes = self.delete_control_space(field_list[1]) |
| 748 _unit = self.delete_control_space(field_list[2]) | 765 _unit = self.delete_control_space(field_list[2]) |
| 749 _summary = self.delete_control(field_list[3]) | 766 _summary = self.delete_control(field_list[3]) |
| 750 _prices = self.delete_control_space(field_list[4]) | 767 _prices = self.delete_control_space(field_list[4]) |
| 751 _dates = self.delete_control_space(field_list[5]) | 768 _dates = self.delete_control_space(field_list[5]) |
| 752 _type = self.delete_control_space(field_list[6]) | 769 _type = self.delete_control_space(field_list[6]) |
| 753 # _____Code_____ | 770 # _____Code_____ |
| 754 _codes = _codes.split("\\") | 771 _codes = _codes.split(u"\\") |
| 755 if len(_codes) > 0: | 772 if len(_codes) > 0: |
| 756 # parse the hierarchy of the first code | 773 # parse the hierarchy of the first code |
| 757 # hierarchy: 0->root, 1->Chapter/subchapter, 2->other | 774 # hierarchy: 0->root, 1->Chapter/subchapter, 2->other |
| 758 if len(_codes[0]) > 2 and _codes[0][-2:] == "##": | 775 if len(_codes[0]) > 2 and _codes[0][-2:] == u"##": |
| 759 _hierarchy = 0 | 776 _hierarchy = 0 |
| 760 elif len(_codes[0]) > 1 and _codes[0][-1:] == "#": | 777 elif len(_codes[0]) > 1 and _codes[0][-1:] == u"#": |
| 761 _hierarchy = 1 | 778 _hierarchy = 1 |
| 762 else: | 779 else: |
| 763 _hierarchy = 2 | 780 _hierarchy = 2 |
| 764 # "#" and "##" characters at the end of the code are erased | 781 # "#" and "##" characters at the end of the code are erased |
| 765 # invalid characters are also erased | 782 # invalid characters are also erased |
| 766 # maximun len 20 characters | 783 # maximun len 20 characters |
| 767 _codes = [self.validateCode(_code) for _code in _codes] | 784 _codes = [self.validateCode(_code) for _code in _codes] |
| 768 # empty codes are ignored | 785 # empty codes are ignored |
| 769 while "" in _codes: | 786 while u"" in _codes: |
| 770 _codes.remove("") | 787 _codes.remove(u"") |
| 771 if len(_codes) > 0: | 788 if len(_codes) > 0: |
| 772 #TODO: test this | 789 #TODO: test this |
| 773 _code = _codes[0] | 790 _code = _codes[0] |
| 774 _synonyms = _codes | 791 _synonyms = [synonym.encode("utf8") for synonym in _codes] |
| 775 else: | 792 else: |
| 776 print _("Record C without a valid code") | 793 print _("Record C without a valid code") |
| 777 return | 794 return |
| 778 # _____Unit_____ | 795 # _____Unit_____ |
| 779 # nothing to do | 796 # nothing to do |
| 780 # _____Summary_____ | 797 # _____Summary_____ |
| 781 # nothing to do | 798 # nothing to do |
| 782 # _____Price_____ and _____Dates_____ | 799 # _____Price_____ and _____Dates_____ |
| 783 # last \ is erased | 800 # last \ is erased |
| 784 if len(_dates) > 0 and _dates[-1] == "\\": | 801 if len(_dates) > 0 and _dates[-1] == u"\\": |
| 785 _dates = _dates[:-1] | 802 _dates = _dates[:-1] |
| 786 if len(_prices) > 0 and _prices[-1] == "\\": | 803 if len(_prices) > 0 and _prices[-1] == u"\\": |
| 787 _prices = _prices[:-1] | 804 _prices = _prices[:-1] |
| 788 _dates = _dates.split("\\") | 805 _dates = _dates.split(u"\\") |
| 789 _prices = _prices.split("\\") | 806 _prices = _prices.split(u"\\") |
| 790 # number of prices = number of titles in "V" line | 807 # number of prices = number of titles in "V" line |
| 791 # if there are no sufficient prices it takes the last price defined | 808 # if there are no sufficient prices it takes the last price defined |
| 792 _title_num = len(self.__budget.getTitleList()[1]) | 809 _title_num = len(self.__budget.getTitleList()[1]) |
| 793 if _title_num == 0: _title_num = 1 | 810 if _title_num == 0: _title_num = 1 |
| 794 if len(_prices) > _title_num: _prices = _prices[:_title_num] | 811 if len(_prices) > _title_num: _prices = _prices[:_title_num] |
| 840 # 2->Other -> 0 -> None,EA,EU,EC,EF,PA | 857 # 2->Other -> 0 -> None,EA,EU,EC,EF,PA |
| 841 # 1 -> None,H | 858 # 1 -> None,H |
| 842 # 2 -> None,Q,% | 859 # 2 -> None,Q,% |
| 843 # 3 -> None,MC,MCr,MM,MS,ME,MCu,Mal,ML,M | 860 # 3 -> None,MC,MCr,MM,MS,ME,MCu,Mal,ML,M |
| 844 if _hierarchy == 0: | 861 if _hierarchy == 0: |
| 845 if _type == "OB": | 862 if _type == u"OB": |
| 846 _subtype = _type | 863 _subtype = _type |
| 847 _type = 0 | 864 _type = 0 |
| 848 elif _type == "0" or _type == "": | 865 elif _type == u"0" or _type == u"": |
| 849 _subtype = "" | 866 _subtype = u"" |
| 850 _type = 0 | 867 _type = 0 |
| 851 else: | 868 else: |
| 852 print utils.mapping(_("Incorrect type ($1) in the code $2"), | 869 print utils.mapping(_("Incorrect type ($1) in the code $2"), |
| 853 (str(_type), _code)) | 870 (_type.encode("utf8"), _code.encode("utf8"))) |
| 854 _type = 0 | 871 _type = 0 |
| 855 _subtype = "" | 872 _subtype = u"" |
| 856 elif _hierarchy == 1: | 873 elif _hierarchy == 1: |
| 857 if _type == "PU": | 874 if _type == u"PU": |
| 858 _subtype = _type | 875 _subtype = _type |
| 859 _type = 0 | 876 _type = 0 |
| 860 elif _type == "0" or _type == "": | 877 elif _type == u"0" or _type == u"": |
| 861 _subtype = "" | 878 _subtype = u"" |
| 862 _type = 0 | 879 _type = 0 |
| 863 else: | 880 else: |
| 864 print utils.mapping(_("Incorrect type ($1) in the code $2"), | 881 print utils.mapping(_("Incorrect type ($1) in the code $2"), |
| 865 (str(_type), _code)) | 882 (_type.encode("utf8"), _code.encode("utf8"))) |
| 866 _type = 0 | 883 _type = 0 |
| 867 _subtype = "" | 884 _subtype = u"" |
| 868 else: | 885 else: |
| 869 if _type == "EA" or _type == "EU" or _type == "EC" or \ | 886 if _type == u"EA" or _type == u"EU" or _type == u"EC" or \ |
| 870 _type == "EF" or _type == "PA": | 887 _type == u"EF" or _type == u"PA": |
| 871 _subtype = _type | 888 _subtype = _type |
| 872 _type = 0 | 889 _type = 0 |
| 873 elif _type == "H": | 890 elif _type == u"H": |
| 874 _subtype = _type | 891 _subtype = _type |
| 875 _type = 1 | 892 _type = 1 |
| 876 elif _type == "Q" or _type == "%": | 893 elif _type == u"Q" or _type == u"%": |
| 877 _subtype = _type | 894 _subtype = _type |
| 878 _type = 2 | 895 _type = 2 |
| 879 elif _type == "MC" or _type == "MCr" or _type == "MM" or \ | 896 elif _type == u"MC" or _type == u"MCr" or _type == u"MM" or \ |
| 880 _type == "MS" or _type == "ME" or _type == "MCu" or \ | 897 _type == u"MS" or _type == u"ME" or _type == u"MCu" or \ |
| 881 _type == "Mal" or _type == "ML" or _type == "M": | 898 _type == u"Mal" or _type == u"ML" or _type == u"M": |
| 882 _subtype = _type | 899 _subtype = _type |
| 883 _type = 3 | 900 _type = 3 |
| 884 elif _type == "0" or _type == "1" or _type == "2" or \ | 901 elif _type == u"0" or _type == u"1" or _type == u"2" or \ |
| 885 _type == "3": | 902 _type == u"3": |
| 886 _subtype = "" | 903 _subtype = u"" |
| 887 _type = int(_type) | 904 _type = int(_type) |
| 888 elif _type == "": | 905 elif _type == u"": |
| 889 _subtype = "" | 906 _subtype = u"" |
| 890 _type = 0 | 907 _type = 0 |
| 891 else: | 908 else: |
| 892 print utils.mapping(_("Incorrect type ($1) in the code $2"), | 909 print utils.mapping(_("Incorrect type ($1) in the code $2"), |
| 893 (str(_type), _code)) | 910 (_type.encode("utf8"), _code.encode("utf8"))) |
| 894 _type = 0 | 911 _type = 0 |
| 895 _subtype = "" | 912 _subtype = u"" |
| 896 self.__budget.setRecord(_code, _synonyms, _hierarchy, | 913 self.__budget.setRecord(_code.encode("utf8"), _synonyms, _hierarchy, |
| 897 _unit, _summary, _prices, _dates, _type, _subtype) | 914 _unit.encode("utf8"), _summary.encode("utf8"), |
| 915 _prices, _dates, _type, _subtype.encode("utf8")) | |
| 898 self.num_valid_record = self.num_valid_record + 1 | 916 self.num_valid_record = self.num_valid_record + 1 |
| 899 | 917 |
| 900 def _parseDY(self, field_list): | 918 def _parseDY(self, field_list): |
| 901 """_parseDY(self, field_list) | 919 """_parseDY(self, field_list) |
| 902 | 920 |
| 911 if len(field_list) > 3: | 929 if len(field_list) > 3: |
| 912 field_list = field_list[:3] | 930 field_list = field_list[:3] |
| 913 # If there are no sufficient fields, the fields are added | 931 # If there are no sufficient fields, the fields are added |
| 914 # with empty value:"" | 932 # with empty value:"" |
| 915 else: | 933 else: |
| 916 field_list = field_list + [""]*(3-len(field_list)) | 934 field_list = field_list + [u""]*(3-len(field_list)) |
| 917 # control character are erased: end of line, tab, space | 935 # control character are erased: end of line, tab, space |
| 918 # _____Fields_____ | 936 # _____Fields_____ |
| 919 _record_type = field_list[0] | 937 _record_type = field_list[0] |
| 920 _code = self.delete_control_space(field_list[1]) | 938 _code = self.delete_control_space(field_list[1]) |
| 921 _children = self.delete_control_space(field_list[2]) | 939 _children = self.delete_control_space(field_list[2]) |
| 922 # _____Code_____ | 940 # _____Code_____ |
| 923 # "#" and "##" characters at the end of the code are erased | 941 # "#" and "##" characters at the end of the code are erased |
| 924 # invalid characters are also erased | 942 # invalid characters are also erased |
| 925 _code = self.validateCode(_code) | 943 _code = self.validateCode(_code) |
| 926 # _____children_____ | 944 # _____children_____ |
| 927 # TODO: test the number of decimals in factor an yield values | 945 # TODO: test the number of decimals in factor an yield values |
| 928 _children = _children.split( "\\" ) | 946 _children = _children.split(u"\\") |
| 929 _children_list = [ ] | 947 _children_list = [ ] |
| 930 _child_index = 0 | 948 _child_index = 0 |
| 931 while _child_index < len(_children)-3: | 949 while _child_index < len(_children)-3: |
| 932 # _____subfields_____ | 950 # _____subfields_____ |
| 933 _child_code = _children[_child_index] | 951 _child_code = _children[_child_index] |
| 934 _factor = _children[_child_index+1] | 952 _factor = _children[_child_index+1] |
| 935 _yield = _children[_child_index+2] | 953 _yield = _children[_child_index+2] |
| 936 # _____child_code_____ | 954 # _____child_code_____ |
| 937 _child_code = self.validateCode(_child_code) | 955 _child_code = self.validateCode(_child_code) |
| 938 # _____factor_____ | 956 # _____factor_____ |
| 939 if _factor != "": | 957 if _factor != u"": |
| 940 try: | 958 try: |
| 941 _factor = float(_factor) | 959 _factor = float(_factor) |
| 942 except ValueError: | 960 except ValueError: |
| 943 print utils.mapping(_("ValueError loadig the "\ | 961 print utils.mapping(_("ValueError loadig the "\ |
| 944 "descomposition of the record $1, the factor "\ | 962 "descomposition of the record $1, the factor "\ |
| 945 "of the child $2 must be a float number and "\ | 963 "of the child $2 must be a float number and "\ |
| 946 "can not be $3, seted default value 1.0"), | 964 "can not be $3, seted default value 1.0"), |
| 947 (_code, _child_code, _factor)) | 965 (_code.encode("utf8"), _child_code.encode("utf8"), _factor.encode("utf8"))) |
| 948 _factor = 1.0 | 966 _factor = 1.0 |
| 949 #____yield___ | 967 #____yield___ |
| 950 if _yield != "": | 968 if _yield != u"": |
| 951 try: | 969 try: |
| 952 _yield = float(_yield) | 970 _yield = float(_yield) |
| 953 except ValueError: | 971 except ValueError: |
| 954 print utils.mapping(_("ValueError loading the "\ | 972 print utils.mapping(_("ValueError loading the "\ |
| 955 "descomposition of the record $1, the yield of "\ | 973 "descomposition of the record $1, the yield of "\ |
| 956 "the child $2, must be a float number and can"\ | 974 "the child $2, must be a float number and can"\ |
| 957 "not be $3, seted default value 1.0"), | 975 "not be $3, seted default value 1.0"), |
| 958 (_code, _child_code, _factor)) | 976 (_code.encode("utf8"), _child_code.encode("utf8"), _factor.encode("utf8"))) |
| 959 _yield = 1.0 | 977 _yield = 1.0 |
| 960 if _child_code != "" and _code != "": | 978 if _child_code != u"" and _code != u"": |
| 961 _children_list.append([_child_code, _factor, _yield ]) | 979 _children_list.append([_child_code, _factor, _yield ]) |
| 962 if _record_type == "D": | 980 if _record_type == u"D": |
| 963 _position = _child_index / 3 | 981 _position = _child_index / 3 |
| 964 else: #_record_type == "Y" | 982 else: #_record_type == "Y" |
| 965 _position = -1 | 983 _position = -1 |
| 966 self.__budget.setTree(_code, _child_code, _position, _factor, | 984 self.__budget.setTree(_code.encode("utf8"), _child_code.encode("utf8"), _position, _factor, |
| 967 _yield, "", "", "", "") | 985 _yield, "", "", "", "") |
| 968 _child_index = _child_index + 3 | 986 _child_index = _child_index + 3 |
| 969 self.num_valid_record = self.num_valid_record +1 | 987 self.num_valid_record = self.num_valid_record +1 |
| 970 | 988 |
| 971 def _parseT(self, field_list): | 989 def _parseT(self, field_list): |
| 991 # _____Code_____ | 1009 # _____Code_____ |
| 992 # "#" and "##" characters at the end of the code are erased | 1010 # "#" and "##" characters at the end of the code are erased |
| 993 # invalid characters are also erased | 1011 # invalid characters are also erased |
| 994 _code = self.validateCode(_code) | 1012 _code = self.validateCode(_code) |
| 995 # _____Text_____ | 1013 # _____Text_____ |
| 996 self.__budget.setText(_code, _text) | 1014 self.__budget.setText(_code.encode("utf8"), _text.encode("utf8")) |
| 997 self.num_valid_record = self.num_valid_record + 1 | 1015 self.num_valid_record = self.num_valid_record + 1 |
| 998 | 1016 |
| 999 def _parseMN(self, field_list): | 1017 def _parseMN(self, field_list): |
| 1000 """_parseMN(self, field_list) | 1018 """_parseMN(self, field_list) |
| 1001 | 1019 |
| 1005 2- {Path\} | 1023 2- {Path\} |
| 1006 3- TOTAL MEASURE | 1024 3- TOTAL MEASURE |
| 1007 4- {Type\Comment\Unit\Length\Width\Height\} | 1025 4- {Type\Comment\Unit\Length\Width\Height\} |
| 1008 5- [Label] | 1026 5- [Label] |
| 1009 """ | 1027 """ |
| 1010 | |
| 1011 # _____Number of fields_____ | 1028 # _____Number of fields_____ |
| 1012 # Any INFORMATION after last field separator is ignored | 1029 # Any INFORMATION after last field separator is ignored |
| 1013 # The record must have 6 fields | 1030 # The record must have 6 fields |
| 1014 if len(field_list) > 6: | 1031 if len(field_list) > 6: |
| 1015 field_list = field_list[:6] | 1032 field_list = field_list[:6] |
| 1016 # If there are no sufficient fields, the fields are added | 1033 # If there are no sufficient fields, the fields are added |
| 1017 # with empty value:"" | 1034 # with empty value:"" |
| 1018 else: | 1035 else: |
| 1019 field_list = field_list + [""]*(6-len(field_list)) | 1036 field_list = field_list + [u""]*(6-len(field_list)) |
| 1020 # control character are erased: end of line, tab, space | 1037 # control character are erased: end of line, tab, space |
| 1021 # _____Fields_____ | 1038 # _____Fields_____ |
| 1022 _record_type = field_list[0] | 1039 _record_type = field_list[0] |
| 1023 _codes = self.delete_control_space(field_list[1]) | 1040 _codes = self.delete_control_space(field_list[1]) |
| 1024 _path = self.delete_control_space(field_list[2]) | 1041 _path = self.delete_control_space(field_list[2]) |
| 1025 _total = self.delete_control_space(field_list[3]) | 1042 _total = self.delete_control_space(field_list[3]) |
| 1026 _lines = self.delete_control(field_list[4]) | 1043 _lines = self.delete_control(field_list[4]) |
| 1027 _label = self.delete_control_space(field_list[5]) | 1044 _label = self.delete_control_space(field_list[5]) |
| 1028 # _____Codes_____ | 1045 # _____Codes_____ |
| 1029 _code_list = _codes.split( "\\" ) | 1046 _code_list = _codes.split(u"\\") |
| 1030 # "#" and "##" characters at the end of the code are erased | 1047 # "#" and "##" characters at the end of the code are erased |
| 1031 # invalid characters are also erased | 1048 # invalid characters are also erased |
| 1032 if len(_code_list) == 2: | 1049 if len(_code_list) == 2: |
| 1033 _parent_code = self.validateCode(_code_list[0]) | 1050 _parent_code = self.validateCode(_code_list[0]) |
| 1034 if _parent_code == "": | 1051 if _parent_code == u"": |
| 1035 _parent_code = None | 1052 _parent_code = None |
| 1053 else: | |
| 1054 _parent_code = _parent_code.encode("utf8") | |
| 1036 _child_code = self.validateCode(_code_list[1]) | 1055 _child_code = self.validateCode(_code_list[1]) |
| 1037 elif len(_code_list) == 1: | 1056 elif len(_code_list) == 1: |
| 1038 _child_code = self.validateCode(_code_list[0]) | 1057 _child_code = self.validateCode(_code_list[0]) |
| 1039 _parent_code = None | 1058 _parent_code = None |
| 1040 else: | 1059 else: |
| 1041 print utils.mapping(_("Invalid codes in $1 record, codes $2"), | 1060 print utils.mapping(_("Invalid codes in $1 record, codes $2"), |
| 1042 (_record_type, _codes)) | 1061 (_record_type.encode("utf8"), _codes.encode("utf8"))) |
| 1043 return | 1062 return |
| 1044 if _child_code == "": | 1063 if _child_code == u"": |
| 1045 print utils.mapping(_("Empty child code in $1 record, codes: "\ | 1064 print utils.mapping(_("Empty child code in $1 record, codes: "\ |
| 1046 "$2"), (_record_type, _codes)) | 1065 "$2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) |
| 1047 return | 1066 return |
| 1067 if _parent_code == None: | |
| 1068 # Empty parent code. No-estructured measures. | |
| 1069 pass | |
| 1070 | |
| 1048 # _____Path_____ | 1071 # _____Path_____ |
| 1049 # TODO: path=0, no-estructured measures | 1072 _path_list = _path.split( u"\\" ) |
| 1050 _path_list = _path.split( "\\" ) | |
| 1051 if len(_path_list) > 0: | 1073 if len(_path_list) > 0: |
| 1052 while _path_list[-1] == "": | 1074 while len(_path_list) > 0 and _path_list[-1] == u"": |
| 1053 _path_list = _path_list[:-1] | 1075 _path_list = _path_list[:-1] |
| 1054 _path = _path_list[-1] | 1076 if len(_path_list) == 0: |
| 1077 # Empty path. No-estructured measures. Path fixed to -2 | |
| 1078 _path = -2 | |
| 1079 else: | |
| 1080 _path = _path_list[-1] | |
| 1055 try: | 1081 try: |
| 1056 _path = int(_path) | 1082 _path = int(_path) |
| 1057 except ValueError: | 1083 except ValueError: |
| 1058 print utils.mapping(_("Invalid path in $1 record, "\ | 1084 print utils.mapping(_("Invalid path in $1 record, "\ |
| 1059 "codes $2"), (_record_type, _codes)) | 1085 "codes $2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) |
| 1060 return | 1086 return |
| 1061 if _path > 0: | 1087 if _path > 0: |
| 1062 _path -= 1 | 1088 _path -= 1 |
| 1063 else: | 1089 else: |
| 1064 _path = 0 | 1090 _path = -2 |
| 1065 # _____Total_____ | 1091 # _____Total_____ |
| 1066 try: | 1092 try: |
| 1067 _total = float(_total) | 1093 _total = float(_total) |
| 1068 except ValueError: | 1094 except ValueError: |
| 1069 print utils.mapping(_("Invalid Total Measure value in $1 "\ | 1095 print utils.mapping(_("Invalid Total Measure value in $1 "\ |
| 1070 "record, codes $2"), (_record_type, _codes)) | 1096 "record, codes $2. Total fixed to 0."), |
| 1071 return | 1097 (_record_type.encode("utf8"), _codes.encode("utf8"))) |
| 1098 _total = 0 | |
| 1072 # _____Measure lines_____ | 1099 # _____Measure lines_____ |
| 1073 _lines = _lines.split( "\\" ) | 1100 _lines = _lines.split(u"\\") |
| 1074 _line_index = 0 | 1101 _line_index = 0 |
| 1075 _line_list = [ ] | 1102 _line_list = [ ] |
| 1076 while _line_index < len(_lines)-6: | 1103 while _line_index < len(_lines)-6: |
| 1077 _linetype = _lines[_line_index] | 1104 _linetype = _lines[_line_index] |
| 1078 if _linetype == "": | 1105 if _linetype == u"": |
| 1079 _linetype = 0 | 1106 _linetype = 0 |
| 1080 elif _linetype == "1" or _linetype == "2" or \ | 1107 elif _linetype == u"1" or _linetype == u"2" or \ |
| 1081 _linetype == "3": | 1108 _linetype == u"3": |
| 1082 _linetype = int(_linetype) | 1109 _linetype = int(_linetype) |
| 1083 else: | 1110 else: |
| 1084 _linetype = 0 | 1111 _linetype = 0 |
| 1085 _comment= _lines[_line_index + 1] | 1112 _comment= _lines[_line_index + 1] |
| 1086 if _linetype == 3: | 1113 if _linetype == 3: |
| 1087 # "formula": ".*[^0123456789\.()\+\-\*/\^abcdp ].*" | 1114 # "formula": ".*[^0123456789\.()\+\-\*/\^abcdp ].*" |
| 1088 if self.__pattern["formula"].match(_comment): | 1115 if self.__pattern["formula"].match(_comment): |
| 1089 print utils.mapping(_("The comment is not a formula or "\ | 1116 print utils.mapping(_("The comment is not a formula or "\ |
| 1090 "its have invalid characters, in the $1 record, "\ | 1117 "its have invalid characters, in the $1 record, "\ |
| 1091 "codes $2"), (_record_type, _codes)) | 1118 "codes $2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) |
| 1092 return | 1119 return |
| 1093 else: | 1120 else: |
| 1094 _formula = _comment | 1121 _formula = _comment.encode("utf8") |
| 1095 _comment = "" | 1122 _comment = "" |
| 1096 else: | 1123 else: |
| 1097 _formula = "" | 1124 _formula = "" |
| 1125 _comment = _comment.encode("utf8") | |
| 1098 _units = _lines[_line_index + 2] | 1126 _units = _lines[_line_index + 2] |
| 1127 _units = self.__pattern["no_float"].sub(u"", _units) | |
| 1099 _length = _lines[_line_index + 3] | 1128 _length = _lines[_line_index + 3] |
| 1129 _length = self.__pattern["no_float"].sub(u"", _length) | |
| 1100 _width = _lines[_line_index + 4] | 1130 _width = _lines[_line_index + 4] |
| 1131 _width = self.__pattern["no_float"].sub(u"", _width) | |
| 1101 _height = _lines[_line_index + 5] | 1132 _height = _lines[_line_index + 5] |
| 1133 _height = self.__pattern["no_float"].sub(u"", _height) | |
| 1134 | |
| 1102 try: | 1135 try: |
| 1103 if _units != "": _units = float(_units) | 1136 if _units != u"": |
| 1104 if _length != "": _length = float(_length) | 1137 _units = float(_units) |
| 1105 if _width != "": _width = float(_width) | 1138 if _length != u"": _length = float(_length) |
| 1106 if _height != "": _height = float(_height) | 1139 if _width != u"": _width = float(_width) |
| 1140 if _height != u"": _height = float(_height) | |
| 1107 except ValueError: | 1141 except ValueError: |
| 1108 print utils.mapping("The measure values are not float "\ | 1142 print utils.mapping(_("The measure values are not float "\ |
| 1109 "numbers, code $1", (_codes,)) | 1143 "numbers, code $1"), (_codes.encode("utf8"),)) |
| 1110 return | 1144 return |
| 1111 _line_list.append([_linetype, _comment, _units, | 1145 _line_list.append([_linetype, _comment, _units, |
| 1112 _length, _width, _height, _formula]) | 1146 _length, _width, _height, _formula]) |
| 1113 _line_index = _line_index + 6 | 1147 _line_index = _line_index + 6 |
| 1114 self.__budget.setTree(_parent_code, _child_code, _path, "", "", | 1148 self.__budget.setTree(_parent_code, _child_code.encode("utf8"), _path, "", "", |
| 1115 _total, _line_list, _label, _record_type) | 1149 _total, _line_list, _label.encode("utf8"), _record_type.encode("utf8")) |
| 1116 self.num_valid_record = self.num_valid_record + 1 | 1150 self.num_valid_record = self.num_valid_record + 1 |
| 1117 | 1151 |
| 1118 def _parseW(self, field_list): | 1152 def _parseW(self, field_list): |
| 1119 """_parseW(self, field_list) | 1153 """_parseW(self, field_list) |
| 1120 | 1154 |
| 1132 return | 1166 return |
| 1133 # control character are erased: end of line, tab, space | 1167 # control character are erased: end of line, tab, space |
| 1134 # _____Fields_____ | 1168 # _____Fields_____ |
| 1135 _code_fields = field_list[0] | 1169 _code_fields = field_list[0] |
| 1136 # last \ is erased | 1170 # last \ is erased |
| 1137 if len(_code_fields) and _code_fields[-1] == "\\": | 1171 if len(_code_fields) and _code_fields[-1] == u"\\": |
| 1138 _code_fields = _code_fields[:-1] | 1172 _code_fields = _code_fields[:-1] |
| 1139 _code_fields = _code_fields.split("\\") | 1173 _code_fields = _code_fields.split(u"\\") |
| 1140 _field_dict = {} | 1174 _field_dict = {} |
| 1141 _field_index = 0 | 1175 _field_index = 0 |
| 1142 while _field_index < len(_code_fields)-1: | 1176 while _field_index < len(_code_fields)-1: |
| 1143 # _____subfields_____ | 1177 # _____subfields_____ |
| 1144 _field_code = _code_fields[_field_index] | 1178 _field_code = _code_fields[_field_index] |
| 1146 # control character are erased: end of line, tab, space | 1180 # control character are erased: end of line, tab, space |
| 1147 # _____section_code_____ | 1181 # _____section_code_____ |
| 1148 #"control": "[\t \n\r]" | 1182 #"control": "[\t \n\r]" |
| 1149 _field_code = self.delete_control_space(_field_code) | 1183 _field_code = self.delete_control_space(_field_code) |
| 1150 # _____section_title_____ | 1184 # _____section_title_____ |
| 1151 if _field_code != "": | 1185 if _field_code != u"": |
| 1152 _field_dict[_field_code] = _field_title | 1186 _field_dict[_field_code.encode("utf8")] = _field_title.encode("utf8") |
| 1153 _field_index = _field_index + 2 | 1187 _field_index = _field_index + 2 |
| 1154 self.__budget.setSheetFields(_field_dict) | 1188 self.__budget.setSheetFields(_field_dict) |
| 1155 self.num_valid_record = self.num_valid_record +1 | 1189 self.num_valid_record = self.num_valid_record +1 |
| 1156 | 1190 |
| 1157 def _parseL(self, field_list): | 1191 def _parseL(self, field_list): |
| 1171 # _____Number of fields_____ | 1205 # _____Number of fields_____ |
| 1172 # The record must have at least 3 fields | 1206 # The record must have at least 3 fields |
| 1173 if len(field_list) < 3: | 1207 if len(field_list) < 3: |
| 1174 return | 1208 return |
| 1175 _code = field_list[1] | 1209 _code = field_list[1] |
| 1176 if _code == "": | 1210 if _code == u"": |
| 1177 # A: Section Titles | 1211 # A: Section Titles |
| 1178 # Any INFORMATION after last field separator is ignored | 1212 # Any INFORMATION after last field separator is ignored |
| 1179 # The record must have 3 fields | 1213 # The record must have 3 fields |
| 1180 if len(field_list) > 3: | 1214 if len(field_list) > 3: |
| 1181 field_list = field_list[0:3] | 1215 field_list = field_list[0:3] |
| 1182 field_list = field_list[1:3] | 1216 field_list = field_list[1:3] |
| 1183 # _____Fields_____ | 1217 # _____Fields_____ |
| 1184 _section_codes = field_list[1] | 1218 _section_codes = field_list[1] |
| 1185 # last \ is erased | 1219 # last \ is erased |
| 1186 if len(_section_codes) and _section_codes[-1] == "\\": | 1220 if len(_section_codes) and _section_codes[-1] == u"\\": |
| 1187 _section_codes = _section_codes[:-1] | 1221 _section_codes = _section_codes[:-1] |
| 1188 _section_codes = _section_codes.split("\\") | 1222 _section_codes = _section_codes.split(u"\\") |
| 1189 _section_dict = {} | 1223 _section_dict = {} |
| 1190 _section_index = 0 | 1224 _section_index = 0 |
| 1191 while _section_index < len(_section_codes)-1: | 1225 while _section_index < len(_section_codes)-1: |
| 1192 # _____subfields_____ | 1226 # _____subfields_____ |
| 1193 _section_code = _section_codes[_section_index] | 1227 _section_code = _section_codes[_section_index] |
| 1196 # control character are erased: end of line, tab, space | 1230 # control character are erased: end of line, tab, space |
| 1197 # _____section_code_____ | 1231 # _____section_code_____ |
| 1198 _section_code = self.delete_control_space(_section_code) | 1232 _section_code = self.delete_control_space(_section_code) |
| 1199 # _____section_title_____ | 1233 # _____section_title_____ |
| 1200 _section_title = self.delete_control_space(_section_title) | 1234 _section_title = self.delete_control_space(_section_title) |
| 1201 if _section_code != "": | 1235 if _section_code != u"": |
| 1202 _section_dict[_section_code] = _section_title | 1236 _section_dict[_section_code.encode("utf8")] = _section_title.encode("utf8") |
| 1203 _section_index = _section_index + 2 | 1237 _section_index = _section_index + 2 |
| 1204 self.__budget.setSheetSections(_section_dict) | 1238 self.__budget.setSheetSections(_section_dict) |
| 1205 self.num_valid_record = self.num_valid_record +1 | 1239 self.num_valid_record = self.num_valid_record +1 |
| 1206 | 1240 |
| 1207 else: | 1241 else: |
| 1215 _record_code = self.delete_control_space(field_list[0]) | 1249 _record_code = self.delete_control_space(field_list[0]) |
| 1216 # "#" and "##" characters at the end of the code are erased | 1250 # "#" and "##" characters at the end of the code are erased |
| 1217 # invalid characters are also erased | 1251 # invalid characters are also erased |
| 1218 _record_code = self.validateCode(_record_code) | 1252 _record_code = self.validateCode(_record_code) |
| 1219 _scodes_text = field_list[1] | 1253 _scodes_text = field_list[1] |
| 1220 if _scodes_text == "": | 1254 if _scodes_text == u"": |
| 1221 # TODO: rtf and html files | 1255 # TODO: rtf and html files |
| 1222 print "Html and rtf files not implemented in ~L record" | 1256 print "Html and rtf files not yet implemented in ~L record" |
| 1223 else: | 1257 else: |
| 1224 # _____Section-code_Section-text_____ | 1258 # _____Section-code_Section-text_____ |
| 1225 # last \ is erased | 1259 # last \ is erased |
| 1226 if len(_scodes_text) and _scodes_text[-1] == "\\": | 1260 if len(_scodes_text) and _scodes_text[-1] == u"\\": |
| 1227 _scodes_text = _scodes_text[:-1] | 1261 _scodes_text = _scodes_text[:-1] |
| 1228 _scodes_text = _scodes_text.split("\\") | 1262 _scodes_text = _scodes_text.split(u"\\") |
| 1229 _paragraph_dict = {} | 1263 _paragraph_dict = {} |
| 1230 _section_dict = {} | 1264 _section_dict = {} |
| 1231 _section_index = 0 | 1265 _section_index = 0 |
| 1232 while _section_index < len(_scodes_text)-1: | 1266 while _section_index < len(_scodes_text)-1: |
| 1233 # _____subfields_____ | 1267 # _____subfields_____ |
| 1235 _section_text = _scodes_text[_section_index+1] | 1269 _section_text = _scodes_text[_section_index+1] |
| 1236 # control character are erased: end of line, tab, space | 1270 # control character are erased: end of line, tab, space |
| 1237 # _____section_code_____ | 1271 # _____section_code_____ |
| 1238 _section_code = self.delete_control_space(_section_code) | 1272 _section_code = self.delete_control_space(_section_code) |
| 1239 # _____section_text_____ | 1273 # _____section_text_____ |
| 1240 if _section_code != "" and _section_text != "": | 1274 if _section_code != u"" and _section_text != u"": |
| 1241 #-# paragraph #-# | 1275 #-# paragraph #-# |
| 1242 _paragraph_code = _record_code + _section_code + "*" | 1276 _paragraph_code = _record_code + _section_code + u"*" |
| 1243 _paragraph_dict[ _paragraph_code ] = _section_text | 1277 _paragraph_dict[ _paragraph_code.encode("utf8") ] = _section_text.encode("utf8") |
| 1244 _section_dict[_section_code] = _paragraph_code | 1278 _section_dict[_section_code.encode("utf8")] = _paragraph_code.encode("utf8") |
| 1245 _section_index = _section_index + 2 | 1279 _section_index = _section_index + 2 |
| 1246 self.__budget.setSheetParagraphs(_paragraph_dict) | 1280 self.__budget.setSheetParagraphs(_paragraph_dict) |
| 1247 self.__budget.setSheetRecord(_record_code, "*", _section_dict) | 1281 self.__budget.setSheetRecord(_record_code.encode("utf8"), "*", _section_dict) |
| 1248 self.num_valid_record = self.num_valid_record +1 | 1282 self.num_valid_record = self.num_valid_record +1 |
| 1249 | 1283 |
| 1250 def _parseQ(self, field_list): | 1284 def _parseQ(self, field_list): |
| 1251 """_parseQ(self, field_list) | 1285 """_parseQ(self, field_list) |
| 1252 | 1286 |
| 1271 # "#" and "##" characters at the end of the code are erased | 1305 # "#" and "##" characters at the end of the code are erased |
| 1272 # invalid characters are also erased | 1306 # invalid characters are also erased |
| 1273 _record_code = self.validateCode(_record_code) | 1307 _record_code = self.validateCode(_record_code) |
| 1274 _scodes_pkey = field_list[1] | 1308 _scodes_pkey = field_list[1] |
| 1275 # last \ is erased | 1309 # last \ is erased |
| 1276 if len(_scodes_pkey) and _scodes_pkey[-1] == "\\": | 1310 if len(_scodes_pkey) and _scodes_pkey[-1] == u"\\": |
| 1277 _scodes_pkey = _scodes_pkey[:-1] | 1311 _scodes_pkey = _scodes_pkey[:-1] |
| 1278 _scodes_pkey = _scodes_pkey.split("\\") | 1312 _scodes_pkey = _scodes_pkey.split(u"\\") |
| 1279 _field_dict = {} | 1313 _field_dict = {} |
| 1280 _section_index = 0 | 1314 _section_index = 0 |
| 1281 while _section_index < len(_scodes_pkey) -1: | 1315 while _section_index < len(_scodes_pkey) -1: |
| 1282 # _____subfields_____ | 1316 # _____subfields_____ |
| 1283 _section_code = _scodes_pkey[_section_index] | 1317 _section_code = _scodes_pkey[_section_index] |
| 1289 # _____section_text_____ | 1323 # _____section_text_____ |
| 1290 _paragraph_key = self.delete_control_space(_paragraph_key) | 1324 _paragraph_key = self.delete_control_space(_paragraph_key) |
| 1291 # _____Fields keys_____ | 1325 # _____Fields keys_____ |
| 1292 _field_keys = self.delete_control_space(_field_keys) | 1326 _field_keys = self.delete_control_space(_field_keys) |
| 1293 # last ; is erased | 1327 # last ; is erased |
| 1294 if len(_field_keys) and _field_keys[-1] == ";": | 1328 if len(_field_keys) and _field_keys[-1] == u";": |
| 1295 _field_keys = _field_keys[:-1] | 1329 _field_keys = _field_keys[:-1] |
| 1296 _field_keys_list = _scodes_pkey.split(";") | 1330 _field_keys_list = _scodes_pkey.split(u";") |
| 1297 for _field_key in _field_keys_list: | 1331 for _field_key in _field_keys_list: |
| 1298 if _field_key != "" and _section_code != "" and \ | 1332 if _field_key != u"" and _section_code != u"" and \ |
| 1299 _paragraph_key != "": | 1333 _paragraph_key != u"": |
| 1300 if _field_key in _field_dict: | 1334 if _field_key in _field_dict: |
| 1301 _section_dict = _field_dict[_field_key] | 1335 _section_dict = _field_dict[_field_key] |
| 1302 else: | 1336 else: |
| 1303 _section_dict = {} | 1337 _section_dict = {} |
| 1304 _field_dict[_field_key] = _section_dict | 1338 _field_dict[_field_key] = _section_dict |
| 1305 _section_dict[_section_code] = _paragraph_code | 1339 _section_dict[_section_code.encode("utf8")] = _paragraph_code.encode("utf8") |
| 1306 _section_index = _section_index + 3 | 1340 _section_index = _section_index + 3 |
| 1307 for _field, _section_dict in _field_dict.iteritems(): | 1341 for _field, _section_dict in _field_dict.iteritems(): |
| 1308 self.__budget.setSheetRecord(_record_code, _field, _section_dict) | 1342 self.__budget.setSheetRecord(_record_code.encode("utf8"), _field.encode("utf8"), _section_dict) |
| 1309 self.num_valid_record = self.num_valid_record +1 | 1343 self.num_valid_record = self.num_valid_record +1 |
| 1310 | 1344 |
| 1311 def _parseJ(self, field_list): | 1345 def _parseJ(self, field_list): |
| 1312 """_parseJ(self, field_list) | 1346 """_parseJ(self, field_list) |
| 1313 | 1347 |
| 1330 # _____Fields_____ | 1364 # _____Fields_____ |
| 1331 # _____Paragraph code_____ | 1365 # _____Paragraph code_____ |
| 1332 _paragraph_code = self.delete_control_space(field_list[0]) | 1366 _paragraph_code = self.delete_control_space(field_list[0]) |
| 1333 # _____Paragraph text_____ | 1367 # _____Paragraph text_____ |
| 1334 _paragraph_text = field_list[1] | 1368 _paragraph_text = field_list[1] |
| 1335 if _paragraph_text == "": | 1369 if _paragraph_text == u"": |
| 1336 # TODO: rtf and html files | 1370 # TODO: rtf and html files |
| 1337 print "Html and rtf files not implemented in ~J record" | 1371 print "Html and rtf files not yet implemented in ~J record" |
| 1338 else: | 1372 else: |
| 1339 self.__budget.setSheetParagraph(paragraph_code, paragraph_text) | 1373 self.__budget.setSheetParagraph(paragraph_code.encode("utf8"), paragraph_text.encode("utf8")) |
| 1340 self.num_valid_record = self.num_valid_record +1 | 1374 self.num_valid_record = self.num_valid_record +1 |
| 1341 | 1375 |
| 1342 def _parseG(self, field_list): | 1376 def _parseG(self, field_list): |
| 1343 """_parseG(self, field_list) | 1377 """_parseG(self, field_list) |
| 1344 | 1378 |
| 1364 _record_code = self.validateCode(_record_code) | 1398 _record_code = self.validateCode(_record_code) |
| 1365 # _____Grafic files_____ | 1399 # _____Grafic files_____ |
| 1366 _grafic_files = self.delete_control(field_list[1]) | 1400 _grafic_files = self.delete_control(field_list[1]) |
| 1367 # _____subfields_____ | 1401 # _____subfields_____ |
| 1368 # last \ is erased | 1402 # last \ is erased |
| 1369 if len(_grafic_files) and _grafic_files[-1] == "\\": | 1403 if len(_grafic_files) and _grafic_files[-1] == u"\\": |
| 1370 _grafic_files = _grafic_files[:-1] | 1404 _grafic_files = _grafic_files[:-1] |
| 1371 _grafic_file_list = _grafic_files.split("\\") | 1405 _grafic_file_list = _grafic_files.split(u"\\") |
| 1372 _tested_grafic_file_list = [] | 1406 _tested_grafic_file_list = [] |
| 1373 for _grafic_file in _grafic_file_list: | 1407 for _grafic_file in _grafic_file_list: |
| 1408 _str_grafic_file = _grafic_file.encode("utf8") | |
| 1374 _path = os.path.dirname(self.__filename) | 1409 _path = os.path.dirname(self.__filename) |
| 1375 _grafic_file_path = os.path.join(_path, _grafic_file) | 1410 _grafic_file_path = os.path.join(_path, _str_grafic_file) |
| 1376 if os.path.exists(_grafic_file_path): | 1411 if os.path.exists(_grafic_file_path): |
| 1377 _tested_grafic_file_list.append(_grafic_file_path) | 1412 _tested_grafic_file_list.append(_grafic_file_path) |
| 1378 else: | 1413 else: |
| 1379 _name_ext = os.path.splitext(_grafic_file) | 1414 _name_ext = os.path.splitext(_str_grafic_file) |
| 1380 _grafic_file_name = _name_ext[0] | 1415 _grafic_file_name = _name_ext[0] |
| 1381 _grafic_file_ext = _name_ext[1] | 1416 _grafic_file_ext = _name_ext[1] |
| 1382 _grafic_file_name_u = _grafic_file_name.upper() | 1417 _grafic_file_name_u = _grafic_file_name.upper() |
| 1383 _grafic_file_name_l = _grafic_file_name.lower() | 1418 _grafic_file_name_l = _grafic_file_name.lower() |
| 1384 _grafic_file_ext_u = _grafic_file_ext.upper() | 1419 _grafic_file_ext_u = _grafic_file_ext.upper() |
| 1402 else: | 1437 else: |
| 1403 print utils.mapping(_("The file $1 do not exist"), | 1438 print utils.mapping(_("The file $1 do not exist"), |
| 1404 (_grafic_file_path,)) | 1439 (_grafic_file_path,)) |
| 1405 if len(_grafic_file_list) > 0: | 1440 if len(_grafic_file_list) > 0: |
| 1406 for _grafic_file in _tested_grafic_file_list: | 1441 for _grafic_file in _tested_grafic_file_list: |
| 1407 self.__budget.addFile(_record_code, _grafic_file, "img", "") | 1442 self.__budget.addFile(_record_code.encode("utf8"), _grafic_file, "img", "") |
| 1408 self.num_valid_record = self.num_valid_record +1 | 1443 self.num_valid_record = self.num_valid_record +1 |
| 1409 | 1444 |
| 1410 def _parseE(self, field_list): | 1445 def _parseE(self, field_list): |
| 1411 """_parseE(self, field_list) | 1446 """_parseE(self, field_list) |
| 1412 | 1447 |
| 1427 if len(field_list) > 6: | 1462 if len(field_list) > 6: |
| 1428 field_list = field_list[1:6] | 1463 field_list = field_list[1:6] |
| 1429 # If there are no sufficient fields, the fields are added | 1464 # If there are no sufficient fields, the fields are added |
| 1430 # with empty value:"" | 1465 # with empty value:"" |
| 1431 else: | 1466 else: |
| 1432 field_list = field_list[1:] + [""]*(6-len(field_list)) | 1467 field_list = field_list[1:] + [u""]*(6-len(field_list)) |
| 1433 # _____Fields_____ | 1468 # _____Fields_____ |
| 1434 # _____company Code_____ | 1469 # _____company Code_____ |
| 1435 _company_code = self.delete_control_space(field_list[0]) | 1470 _company_code = self.delete_control_space(field_list[0]) |
| 1436 if _company_code == "": | 1471 if _company_code == u"": |
| 1437 return | 1472 return |
| 1438 # _____Summary_____ | 1473 # _____Summary_____ |
| 1439 | 1474 |
| 1440 _sumamary = self.delete_control(field_list[1]) | 1475 _sumamary = self.delete_control(field_list[1]) |
| 1441 # _____Name_____ | 1476 # _____Name_____ |
| 1442 _name = self.delete_control(field_list[2]) | 1477 _name = self.delete_control(field_list[2]) |
| 1443 # _____local_offices_____ | 1478 # _____local_offices_____ |
| 1444 _local_offices = self.delete_control(field_list[3]) | 1479 _local_offices = self.delete_control(field_list[3]) |
| 1445 # _____subfields of local_offices_____ | 1480 # _____subfields of local_offices_____ |
| 1446 # last \ is erased | 1481 # last \ is erased |
| 1447 if len(_local_offices) and _local_offices[-1] == "\\": | 1482 if len(_local_offices) and _local_offices[-1] == u"\\": |
| 1448 _local_offices = _local_offices[:-1] | 1483 _local_offices = _local_offices[:-1] |
| 1449 _local_offices_list = _local_offices.split("\\") | 1484 _local_offices_list = _local_offices.split(u"\\") |
| 1450 # If there are no sufficent subfields, the subfields are added | 1485 # If there are no sufficent subfields, the subfields are added |
| 1451 # whith empty value | 1486 # whith empty value |
| 1452 _nsub = len(_local_offices_list) % 10 | 1487 _nsub = len(_local_offices_list) % 10 |
| 1453 if _nsub != 0: | 1488 if _nsub != 0: |
| 1454 _local_offices_list = _local_offices_list + \ | 1489 _local_offices_list = _local_offices_list + \ |
| 1455 [""]*(10-len(field_list)) | 1490 [u""]*(10-len(field_list)) |
| 1456 _local_offices = [] | 1491 _local_offices = [] |
| 1457 _local_offices_index = 0 | 1492 _local_offices_index = 0 |
| 1458 while _local_offices_index < len(_local_offices_list)-9: | 1493 while _local_offices_index < len(_local_offices_list)-9: |
| 1459 # _____subfields_____ | 1494 # _____subfields_____ |
| 1460 _type = _local_offices_list[_local_offices_index] | 1495 _type = _local_offices_list[_local_offices_index] |
| 1464 _town = _local_offices_list[_local_offices_index+4] | 1499 _town = _local_offices_list[_local_offices_index+4] |
| 1465 _province = _local_offices_list[_local_offices_index+5] | 1500 _province = _local_offices_list[_local_offices_index+5] |
| 1466 _country = _local_offices_list[_local_offices_index+6] | 1501 _country = _local_offices_list[_local_offices_index+6] |
| 1467 _phone = _local_offices_list[_local_offices_index+7] | 1502 _phone = _local_offices_list[_local_offices_index+7] |
| 1468 # last ; is erased | 1503 # last ; is erased |
| 1469 if len(_phone) and _phone[-1] == ";": | 1504 if len(_phone) and _phone[-1] == u";": |
| 1470 _phone = _phone[:-1] | 1505 _phone = _phone[:-1] |
| 1471 _phone_list = _phone.split(";") | 1506 _phone_list = _phone.split(u";") |
| 1507 _phone_list = [_phone.encode("utf8") for _phone in _phone_list] | |
| 1472 _fax = _local_offices_list[_local_offices_index+8] | 1508 _fax = _local_offices_list[_local_offices_index+8] |
| 1473 # last ; is erased | 1509 # last ; is erased |
| 1474 if len(_fax) and _fax[-1] == ";": | 1510 if len(_fax) and _fax[-1] == u";": |
| 1475 _fax = _fax[:-1] | 1511 _fax = _fax[:-1] |
| 1476 _fax_list = _fax.split(";") | 1512 _fax_list = _fax.split(u";") |
| 1513 _fax_list = [_fax.encode("utf8") for _fax in _fax_list] | |
| 1477 _contact_person = _local_offices_list[_local_offices_index+9] | 1514 _contact_person = _local_offices_list[_local_offices_index+9] |
| 1478 if _type != "" or _subname != "" or _address != "" or \ | 1515 if _type != u"" or _subname != u"" or _address != u"" or \ |
| 1479 _postal_code != "" or _town != "" or _province != "" or \ | 1516 _postal_code != u"" or _town != u"" or _province != u"" or \ |
| 1480 _country != "" or _phone != "" or _fax != "" or \ | 1517 _country != u"" or _phone != u"" or _fax != u"" or \ |
| 1481 _contact_person != "": | 1518 _contact_person != u"": |
| 1482 _local_offices.append([_type, _subname, _address, | 1519 _local_offices.append([_type.encode("utf8"), _subname.encode("utf8"), |
| 1483 _postal_code, _town, _province, | 1520 _address.encode("utf8"), _postal_code.encode("utf8"), |
| 1484 _country, _phone_list, _fax_list, | 1521 _town.encode("utf8"), _province.encode("utf8"), |
| 1485 _contact_person]) | 1522 _country.encode("utf8"), _phone_list, |
| 1523 _fax_list, _contact_person.encode("utf8")]) | |
| 1486 _local_offices_index = _local_offices_index + 10 | 1524 _local_offices_index = _local_offices_index + 10 |
| 1487 # _____cif web email_____ | 1525 # _____cif web email_____ |
| 1488 _c_w_e = self.delete_control_space(field_list[4]) | 1526 _c_w_e = self.delete_control_space(field_list[4]) |
| 1489 # last \ is erased | 1527 # last \ is erased |
| 1490 if len(_c_w_e) and _c_w_e[-1] == "\\": | 1528 if len(_c_w_e) and _c_w_e[-1] == u"\\": |
| 1491 _c_w_e = _c_w_e[:-1] | 1529 _c_w_e = _c_w_e[:-1] |
| 1492 _c_w_e_list = _c_w_e.split("\\") | 1530 _c_w_e_list = _c_w_e.split(u"\\") |
| 1493 # _____subfields_____ | 1531 # _____subfields_____ |
| 1494 # If there are no sufficient fields, the fields are added | 1532 # If there are no sufficient fields, the fields are added |
| 1495 # with empty value:"" | 1533 # with empty value:"" |
| 1496 _c_w_e_list = _c_w_e_list + [""]*(3-len(_c_w_e_list)) | 1534 _c_w_e_list = _c_w_e_list + [u""]*(3-len(_c_w_e_list)) |
| 1497 _cif = _c_w_e_list[0] | 1535 _cif = _c_w_e_list[0] |
| 1498 _web = _c_w_e_list[1] | 1536 _web = _c_w_e_list[1] |
| 1499 _email = _c_w_e_list[2] | 1537 _email = _c_w_e_list[2] |
| 1500 self.__budget.setCompany(_company_code, _sumamary, _name, | 1538 self.__budget.setCompany(_company_code.encode("utf8"), |
| 1501 _local_offices, _cif, _web, _email) | 1539 _sumamary.encode("utf8"), _name.encode("utf8"), |
| 1540 _local_offices, _cif.encode("utf8"), | |
| 1541 _web.encode("utf8"), _email.encode("utf8")) | |
| 1502 self.num_valid_record = self.num_valid_record +1 | 1542 self.num_valid_record = self.num_valid_record +1 |
| 1503 | 1543 |
| 1504 def _parseX(self, field_list): | 1544 def _parseX(self, field_list): |
| 1505 """_parseX(self, field_list) | 1545 """_parseX(self, field_list) |
| 1506 | 1546 |
| 1525 field_list = field_list[1:] | 1565 field_list = field_list[1:] |
| 1526 # _____Fields_____ | 1566 # _____Fields_____ |
| 1527 # "control": "[\t \n\r]" | 1567 # "control": "[\t \n\r]" |
| 1528 _field_1 = self.delete_control_space(field_list[0]) | 1568 _field_1 = self.delete_control_space(field_list[0]) |
| 1529 _field_2 = self.delete_control_space(field_list[1]) | 1569 _field_2 = self.delete_control_space(field_list[1]) |
| 1530 if _field_1 == "": | 1570 if _field_1 == u"": |
| 1531 # A) | 1571 # A) |
| 1532 _field_2_list = _field_2.split("\\") | 1572 _field_2_list = _field_2.split(u"\\") |
| 1533 _ti_index = 0 | 1573 _ti_index = 0 |
| 1534 while _ti_index < len(_field_2_list)-3: | 1574 while _ti_index < len(_field_2_list)-3: |
| 1535 _ti_code = _field_2_list[_ti_index] | 1575 _ti_code = _field_2_list[_ti_index] |
| 1536 _ti_description = _field_2_list[_ti_index+1] | 1576 _ti_description = _field_2_list[_ti_index+1] |
| 1537 _ti_unit = _field_2_list[_ti_index+2] | 1577 _ti_unit = _field_2_list[_ti_index+2] |
| 1538 if _ti_code != "": | 1578 if _ti_code != "": |
| 1539 self.__budget.addTecInfo(_ti_code, _ti_description, | 1579 self.__budget.addTecInfo(_ti_code.encode("utf8"), _ti_description.encode("utf8"), |
| 1540 _ti_unit) | 1580 _ti_unit.encode("utf8")) |
| 1541 _ti_index = _ti_index + 3 | 1581 _ti_index = _ti_index + 3 |
| 1542 else: | 1582 else: |
| 1543 # B) | 1583 # B) |
| 1544 # "#" and "##" characters at the end of the code are erased | 1584 # "#" and "##" characters at the end of the code are erased |
| 1545 # invalid characters are also erased | 1585 # invalid characters are also erased |
| 1546 _record_code = self.validateCode(_field_1) | 1586 _record_code = self.validateCode(_field_1) |
| 1547 _field_2_list = _field_2.split("\\") | 1587 _field_2_list = _field_2.split(u"\\") |
| 1548 _ti_index = 0 | 1588 _ti_index = 0 |
| 1549 _ti_dict = {} | 1589 _ti_dict = {} |
| 1550 while _ti_index < len(_field_2_list)-2: | 1590 while _ti_index < len(_field_2_list)-2: |
| 1551 _ti_code = _field_2_list[_ti_index] | 1591 _ti_code = _field_2_list[_ti_index] |
| 1552 _ti_value = _field_2_list[_ti_index+1] | 1592 _ti_value = _field_2_list[_ti_index+1] |
| 1553 if _ti_code != "" and _ty_value != "": | 1593 if _ti_code != u"" and _ty_value != u"": |
| 1554 _ti_dict[_ti_code] = _ty_value | 1594 _ti_dict[_ti_code.encode("utf8")] = _ty_value.encode("utf8") |
| 1555 _ti_index = _ti_index + 2 | 1595 _ti_index = _ti_index + 2 |
| 1556 self.__budget.setTecnicalInformation(_record_code, _ti_dict) | 1596 self.__budget.setTecnicalInformation(_record_code.encode("utf8"), _ti_dict) |
| 1557 self.num_valid_record = self.num_valid_record +1 | 1597 self.num_valid_record = self.num_valid_record +1 |
| 1558 | 1598 |
| 1559 def _parseF(self, field_list): | 1599 def _parseF(self, field_list): |
| 1560 """_parseF(self, field_list) | 1600 """_parseF(self, field_list) |
| 1561 | 1601 |
| 1582 _record_code = self.validateCode(_record_code) | 1622 _record_code = self.validateCode(_record_code) |
| 1583 # _____Grafic files_____ | 1623 # _____Grafic files_____ |
| 1584 _files = self.delete_control(field_list[1]) | 1624 _files = self.delete_control(field_list[1]) |
| 1585 # _____subfields_____ | 1625 # _____subfields_____ |
| 1586 # last \ is erased | 1626 # last \ is erased |
| 1587 if len(_files) and _files[-1] == "\\": | 1627 if len(_files) and _files[-1] == u"\\": |
| 1588 _files = _files[:-1] | 1628 _files = _files[:-1] |
| 1589 _files_list = _files.split("\\") | 1629 _files_list = _files.split(u"\\") |
| 1590 # adding empty subfiels if necesary | 1630 # adding empty subfiels if necesary |
| 1591 if len(_files_list)%3 > 0: | 1631 if len(_files_list)%3 > 0: |
| 1592 _files_list.extend[""]*(3 - len(_files_list)%3) | 1632 _files_list.extend[u""]*(3 - len(_files_list)%3) |
| 1593 _file_index = 0 | 1633 _file_index = 0 |
| 1594 _tested_files_list = [] | 1634 _tested_files_list = [] |
| 1595 while _file_index < len(_files_list)-3: | 1635 while _file_index < len(_files_list)-3: |
| 1596 _type = _files_list[_file_index].replace(" ","") | 1636 _type = _files_list[_file_index].replace(u" ",u"") |
| 1597 ## _types = { | 1637 ## _types = { |
| 1598 ## "0": _("others"), | 1638 ## "0": _("others"), |
| 1599 ## "1": _("características técnicas y de fabricación"), | 1639 ## "1": _("características técnicas y de fabricación"), |
| 1600 ## "2": _("manual de colocación, uso y mantenimiento"), | 1640 ## "2": _("manual de colocación, uso y mantenimiento"), |
| 1601 ## "3": _("certificado/s de elementos y sistemas"), | 1641 ## "3": _("certificado/s de elementos y sistemas"), |
| 1607 ## "9": _("cálculo de elementos y sistemas"), | 1647 ## "9": _("cálculo de elementos y sistemas"), |
| 1608 ## "10": _("presentación, datos generales, objetivos, etc. de "\ | 1648 ## "10": _("presentación, datos generales, objetivos, etc. de "\ |
| 1609 ## "empresa"), | 1649 ## "empresa"), |
| 1610 ## "11": _("certificado/s de empresa"), | 1650 ## "11": _("certificado/s de empresa"), |
| 1611 ## "12": _("obras realizadas")} | 1651 ## "12": _("obras realizadas")} |
| 1612 _types = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", | 1652 _types = [u"0", u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10", |
| 1613 "11", "12"] | 1653 u"11", u"12"] |
| 1614 if not _type in _types: | 1654 if not _type in _types: |
| 1615 _type = "0" | 1655 _type = u"0" |
| 1616 _filenames = _files_list[_file_index + 1] | 1656 _filenames = _files_list[_file_index + 1] |
| 1617 _description = _files_list[_file_index + 2] | 1657 _description = _files_list[_file_index + 2] |
| 1618 _file_index += 3 | 1658 _file_index += 3 |
| 1619 if len(_filenames) and _filenames[-1] == ";": | 1659 if len(_filenames) and _filenames[-1] == u";": |
| 1620 _files = _files[:-1] | 1660 _files = _files[:-1] |
| 1621 _filenames_list = _files.split(";") | 1661 _filenames_list = _files.split(u";") |
| 1622 _path = os.path.dirname(self.__filename) | 1662 _path = os.path.dirname(self.__filename) |
| 1623 for _filename in filenames_list: | 1663 for _filename in filenames_list: |
| 1624 _file_path = os.path.join(_path, _filename) | 1664 _file_path = os.path.join(_path, _filename.encode("utf8")) |
| 1625 if os.path.exists(_file_path): | 1665 if os.path.exists(_file_path): |
| 1626 _tested_files_list.append([_file_path, _type, | 1666 _tested_files_list.append([_file_path, _type.encode("utf8"), |
| 1627 _description]) | 1667 _description.encode("utf8")]) |
| 1628 else: | 1668 else: |
| 1629 _name_ext = os.path.splitext(_filename) | 1669 _name_ext = os.path.splitext(_filename) |
| 1630 _file_name = _name_ext[0] | 1670 _file_name = _name_ext[0] |
| 1631 _file_ext = _name_ext[1] | 1671 _file_ext = _name_ext[1] |
| 1632 _file_name_u = _file_name.upper() | 1672 _file_name_u = _file_name.upper() |
| 1640 _file_path_uu = os.path.join(_path, _uu) | 1680 _file_path_uu = os.path.join(_path, _uu) |
| 1641 _file_path_ul = os.path.join(_path, _ul) | 1681 _file_path_ul = os.path.join(_path, _ul) |
| 1642 _file_path_lu = os.path.join(_path, _lu) | 1682 _file_path_lu = os.path.join(_path, _lu) |
| 1643 _file_path_ll = os.path.join(_path, _ll) | 1683 _file_path_ll = os.path.join(_path, _ll) |
| 1644 if os.path.exists(_file_path_uu): | 1684 if os.path.exists(_file_path_uu): |
| 1645 _tested_files_list.append([_file_path_uu, _type, | 1685 _tested_files_list.append([_file_path_uu, _type.encode("utf8"), |
| 1646 _description]) | 1686 _description.encode("utf8")]) |
| 1647 elif os.path.exists(_grafic_file_path_ul): | 1687 elif os.path.exists(_grafic_file_path_ul): |
| 1648 _tested_files_list.append([_file_path_ul, _type, | 1688 _tested_files_list.append([_file_path_ul, _type.encode("utf8"), |
| 1649 _description]) | 1689 _description.encode("utf8")]) |
| 1650 elif os.path.exists(_grafic_file_path_lu): | 1690 elif os.path.exists(_grafic_file_path_lu): |
| 1651 _tested_files_list.append([_file_path_lu, _type, | 1691 _tested_files_list.append([_file_path_lu, _type.encode("utf8"), |
| 1652 _description]) | 1692 _description.encode("utf8")]) |
| 1653 elif os.path.exists(_grafic_file_path_ll): | 1693 elif os.path.exists(_grafic_file_path_ll): |
| 1654 _tested_files_list.append([_file_path_ll, _type, | 1694 _tested_files_list.append([_file_path_ll, _type.encode("utf8"), |
| 1655 _description]) | 1695 _description.encode("utf8")]) |
| 1656 else: | 1696 else: |
| 1657 print utils.mapping(_("The file $1 do not exist"), | 1697 print utils.mapping(_("The file $1 do not exist"), |
| 1658 (_file_path,)) | 1698 (_file_path,)) |
| 1659 if len(_tested_files_list) > 0: | 1699 if len(_tested_files_list) > 0: |
| 1660 for _file in _tested_file_list: | 1700 for _file in _tested_file_list: |
| 1661 self.__budget.addFile(_record_code, _file[0], file[1], file[2]) | 1701 self.__budget.addFile(_record_code.encode("utf8"), _file[0], file[1], file[2]) |
| 1662 self.num_valid_record = self.num_valid_record +1 | 1702 self.num_valid_record = self.num_valid_record +1 |
| 1663 | 1703 |
| 1664 def _parseB(self, field_list): | 1704 def _parseB(self, field_list): |
| 1665 """_parseB(self, field_list) | 1705 """_parseB(self, field_list) |
| 1666 | 1706 |
| 1716 # invalid characters are also erased | 1756 # invalid characters are also erased |
| 1717 _code = self.validateCode(_code) | 1757 _code = self.validateCode(_code) |
| 1718 # _____Labels_____ | 1758 # _____Labels_____ |
| 1719 # last \ is erased | 1759 # last \ is erased |
| 1720 # TODO: change the others parsers to this: | 1760 # TODO: change the others parsers to this: |
| 1721 while len(_labels) > 0 and _labels[-1] == "\\": | 1761 while len(_labels) > 0 and _labels[-1] == u"\\": |
| 1722 _labels = _labels[:-1] | 1762 _labels = _labels[:-1] |
| 1723 # replace "_" to " " | 1763 # replace "_" to " " |
| 1724 _labels = _labels.replace("_"," ") | 1764 _labels = _labels.replace(u"_",u" ") |
| 1725 _label_list = _labels.split("\\") | 1765 _label_list = _labels.split(u"\\") |
| 1726 for _label in _label_list: | 1766 for _label in _label_list: |
| 1727 self.__budget.addLabel(_code, _label) | 1767 self.__budget.addLabel(_code.encode("utf8"), _label.encode("utf8")) |
| 1728 self.num_valid_record = self.num_valid_record + 1 | 1768 self.num_valid_record = self.num_valid_record + 1 |
| 1729 | 1769 |
| 1730 def _parseP(self, field_list): | 1770 def _parseP(self, field_list): |
| 1731 """_parseP(self, field_list) | 1771 """_parseP(self, field_list) |
| 1732 | 1772 |
| 1743 """ | 1783 """ |
| 1744 # TODO: Use global parametric record | 1784 # TODO: Use global parametric record |
| 1745 if len(field_list) > 2: | 1785 if len(field_list) > 2: |
| 1746 # delete control caracters and spaces | 1786 # delete control caracters and spaces |
| 1747 _family_code = self.delete_control_space(field_list[1]) | 1787 _family_code = self.delete_control_space(field_list[1]) |
| 1748 if _family_code == "": # A)Global paremetric record | 1788 if _family_code == u"": # A)Global paremetric record |
| 1749 # The record must have 3 or 4 fields | 1789 # The record must have 3 or 4 fields |
| 1750 if len(field_list) > 4: | 1790 if len(field_list) > 4: |
| 1751 field_list = field_list[0:4] | 1791 field_list = field_list[0:4] |
| 1752 field_list = field_list[1:] | 1792 field_list = field_list[1:] |
| 1753 if len(field_list) == 2: | 1793 if len(field_list) == 2: |
| 1754 field_list.append("") | 1794 field_list.append(u"") |
| 1755 if len(field_list) != 3: | 1795 if len(field_list) != 3: |
| 1756 return | 1796 return |
| 1757 else: # B)Family Parametric record | 1797 else: # B)Family Parametric record |
| 1758 # The record must have 3 fields | 1798 # The record must have 3 fields |
| 1759 if len(field_list) > 3: | 1799 if len(field_list) > 3: |
| 1764 return | 1804 return |
| 1765 else: | 1805 else: |
| 1766 return | 1806 return |
| 1767 # _____Description_____ | 1807 # _____Description_____ |
| 1768 _description = field_list[1] | 1808 _description = field_list[1] |
| 1769 if _description == "": | 1809 if _description == u"": |
| 1770 print _("PyArq hates parametric DLLs") | 1810 print _("PyArq hates parametric DLLs") |
| 1771 return | 1811 return |
| 1772 # Adding last end of line | 1812 # Adding last end of line |
| 1773 _description = _description + "\r\n" | 1813 _description = _description + u"\r\n" |
| 1774 # Delete comments | 1814 # Delete comments |
| 1775 # "comment" : "#.*\r\n" | 1815 # "comment" : "#.*\r\n" |
| 1776 _description = self.__pattern["comment"].sub("\r\n",_description) | 1816 _description = self.__pattern["comment"].sub(u"\r\n",_description) |
| 1777 # Tabs to spaces | 1817 # Tabs to spaces |
| 1778 _description = _description.replace("\t"," ") | 1818 _description = _description.replace(u"\t",u" ") |
| 1779 # Delete empty lines | 1819 # Delete empty lines |
| 1780 # "empty_line": r"(\r\n) *\r\n" | 1820 # "empty_line": r"(\r\n) *\r\n" |
| 1781 while self.__pattern["empty_line"].search(_description): | 1821 while self.__pattern["empty_line"].search(_description): |
| 1782 _description = self.__pattern["empty_line"].sub( | 1822 _description = self.__pattern["empty_line"].sub( |
| 1783 lambda x: x.groups()[0], _description) | 1823 lambda x: x.groups()[0], _description) |
| 1784 # Delete spaces before and after / | 1824 # Delete spaces before and after / |
| 1785 # "space_before_backslash" : r"( )+\\" | 1825 # "space_before_backslash" : r"( )+\\" |
| 1786 _description = self.__pattern["space_before_backslash"].sub( | 1826 _description = self.__pattern["space_before_backslash"].sub( |
| 1787 r"\\",_description) | 1827 ur"\\",_description) |
| 1788 # "space_after_backslash" : r"\\( )+" | 1828 # "space_after_backslash" : r"\\( )+" |
| 1789 _description = self.__pattern["space_after_backslash"].sub( | 1829 _description = self.__pattern["space_after_backslash"].sub( |
| 1790 r"\\",_description) | 1830 ur"\\",_description) |
| 1791 # Join lines that start but not end with / | 1831 # Join lines that start but not end with / |
| 1792 _description = "\r\n" + _description # add leading end of line | 1832 _description = u"\r\n" + _description # add leading end of line |
| 1793 # "start_noend_backslash": "(\r\n\\\.*[^\\\])\r\n" | 1833 # "start_noend_backslash": "(\r\n\\\.*[^\\\])\r\n" |
| 1794 while self.__pattern["start_noend_backslash"].search(_description): | 1834 while self.__pattern["start_noend_backslash"].search(_description): |
| 1795 _description = self.__pattern["start_noend_backslash"].sub( | 1835 _description = self.__pattern["start_noend_backslash"].sub( |
| 1796 lambda x: x.groups()[0], _description) | 1836 lambda x: x.groups()[0], _description) |
| 1797 # Join lines that end with a + - * / ^ and @ & < > <= >= = <> ! | 1837 # Join lines that end with a + - * / ^ and @ & < > <= >= = <> ! |
| 1803 while self.__pattern["matricial_var"].search(_description): | 1843 while self.__pattern["matricial_var"].search(_description): |
| 1804 _description = self.__pattern["matricial_var"].sub( | 1844 _description = self.__pattern["matricial_var"].sub( |
| 1805 lambda x: x.groups()[0], _description) | 1845 lambda x: x.groups()[0], _description) |
| 1806 _description = _description[2:] # remove leading end of line | 1846 _description = _description[2:] # remove leading end of line |
| 1807 #_description = re.sub(r"\\( )+",r"\\",_description) | 1847 #_description = re.sub(r"\\( )+",r"\\",_description) |
| 1808 _lines = _description.split("\r\n") | 1848 _lines = _description.split(u"\r\n") |
| 1809 _final_description = "" | 1849 _final_description = u"" |
| 1810 _pass_line = 0 | 1850 _pass_line = 0 |
| 1811 for index in range(len(_lines)): | 1851 for index in range(len(_lines)): |
| 1812 _line = _lines[index] | 1852 _line = _lines[index] |
| 1813 # Parse lines | 1853 # Parse lines |
| 1814 if len(_line) != 0: # Delete empty lines | 1854 if len(_line) != 0: # Delete empty lines |
| 1815 if _pass_line > 0: | 1855 if _pass_line > 0: |
| 1816 _pass_line = _pass_line -1 | 1856 _pass_line = _pass_line -1 |
| 1817 _line = "" | 1857 _line = u"" |
| 1818 elif _line.isspace(): | 1858 elif _line.isspace(): |
| 1819 _line = "" | 1859 _line = u"" |
| 1820 elif _line[0] != "\\": | 1860 elif _line[0] != u"\\": |
| 1821 # Delete spaces out "" delimiter | 1861 # Delete spaces out "" delimiter |
| 1822 _list = _line.split('"') | 1862 _list = _line.split(u'"') |
| 1823 _final_line = "" | 1863 _final_line = u"" |
| 1824 for index1 in range(len(_list)): | 1864 for index1 in range(len(_list)): |
| 1825 if index1 % 2 != 0: | 1865 if index1 % 2 != 0: |
| 1826 _parcial_line = '"' + _list[index1] | 1866 _parcial_line = u'"' + _list[index1] |
| 1827 else: | 1867 else: |
| 1828 _parcial_line = '"' + _list[index1].replace(" ","") | 1868 _parcial_line = u'"' + _list[index1].replace(u" ",u"") |
| 1829 _final_line = _final_line + _parcial_line | 1869 _final_line = _final_line + _parcial_line |
| 1830 _line = _final_line[1:] | 1870 _line = _final_line[1:] |
| 1831 _lines[index] = _line | 1871 _lines[index] = _line |
| 1832 # parse data | 1872 # parse data |
| 1833 if len(_line) > 2 and _line[:2] == "::": | 1873 if len(_line) > 2 and _line[:2] == u"::": |
| 1834 # Delete spaces out " delimiter | 1874 # Delete spaces out " delimiter |
| 1835 #print "__PRECIO__" + _line[2:] | 1875 #print "__PRECIO__" + _line[2:] |
| 1836 pass | 1876 pass |
| 1837 elif len(_line) > 2 and _line[:2] == "%:": | 1877 elif len(_line) > 2 and _line[:2] == u"%:": |
| 1838 # Delete spaces out " delimiter | 1878 # Delete spaces out " delimiter |
| 1839 #print "__%AUX__" + _line[2:] | 1879 #print "__%AUX__" + _line[2:] |
| 1840 pass | 1880 pass |
| 1841 elif len(_line) > 3 and _line[:2] == "%%:": | 1881 elif len(_line) > 3 and _line[:2] == u"%%:": |
| 1842 # Delete spaces out " delimiter | 1882 # Delete spaces out " delimiter |
| 1843 #print "__%%AUX__" + _line[2:] | 1883 #print "__%%AUX__" + _line[2:] |
| 1844 pass | 1884 pass |
| 1845 elif self.__pattern["var"].search(_line): | 1885 elif self.__pattern["var"].search(_line): |
| 1846 # Delete spaces out " delimiter | 1886 # Delete spaces out " delimiter |
| 1847 #print "line =", _line | 1887 #print "line =", _line |
| 1848 while _line.count('"') % 2 == 1 and \ | 1888 while _line.count(u'"') % 2 == 1 and \ |
| 1849 index + _pass_line + 1 < len(_lines) -1: | 1889 index + _pass_line + 1 < len(_lines) -1: |
| 1850 _line = _line + _lines[index + _pass_line + 1] | 1890 _line = _line + _lines[index + _pass_line + 1] |
| 1851 _pass_line = _pass_line + 1 | 1891 _pass_line = _pass_line + 1 |
| 1852 _search = self.__pattern["var"].search(_line) | 1892 _search = self.__pattern["var"].search(_line) |
| 1853 if _search is not None: | 1893 if _search is not None: |
| 1854 _var = _search.groups()[0] + " = " + _search.groups()[1] | 1894 _var = _search.groups()[0] + u" = " + _search.groups()[1] |
| 1855 #print "__VAR__" + str(_var) | 1895 #print "__VAR__" + str(_var) |
| 1856 pass | 1896 pass |
| 1857 else: | 1897 else: |
| 1858 #print "no __VAR__", _line | 1898 #print "no __VAR__", _line |
| 1859 pass | 1899 pass |
| 1860 elif self.__pattern["descomposition"].search(_line): | 1900 elif self.__pattern["descomposition"].search(_line): |
| 1861 # Delete spaces out " delimiter | 1901 # Delete spaces out " delimiter |
| 1862 #_patern = "(^[^:]*):(.*)$" | 1902 #_patern = "(^[^:]*):(.*)$" |
| 1863 _search = self.__pattern["descomposition"].search(_line) | 1903 _search = self.__pattern["descomposition"].search(_line) |
| 1864 if _search is not None: | 1904 if _search is not None: |
| 1865 _var = _search.groups()[0] + ":" + _search.groups()[1] | 1905 _var = _search.groups()[0] + u":" + _search.groups()[1] |
| 1866 #print "__Descomposición__" + str(_var) | 1906 #print "__Descomposición__" + str(_var) |
| 1867 pass | 1907 pass |
| 1868 else: | 1908 else: |
| 1869 #print "no __Descomposición__", _line | 1909 #print "no __Descomposición__", _line |
| 1870 pass | 1910 pass |
| 1871 else: | 1911 else: |
| 1872 print "Parametric: code: " + _family_code | 1912 print "Parametric: code: " + _family_code.encode("utf8") |
| 1873 print "******* Desconocido *** : " + _line | 1913 print "******* Desconocido *** : " + _line |
| 1874 if index-10 > 0: print "-11 :", _lines[index-11] | 1914 if index-10 > 0: print "-11 :", _lines[index-11].encode("utf8") |
| 1875 if index-10 > 0: print "-10 :", _lines[index-10] | 1915 if index-10 > 0: print "-10 :", _lines[index-10].encode("utf8") |
| 1876 if index-9 > 0: print "-9 :", _lines[index-9] | 1916 if index-9 > 0: print "-9 :", _lines[index-9].encode("utf8") |
| 1877 if index-8 > 0: print "-8 :", _lines[index-8] | 1917 if index-8 > 0: print "-8 :", _lines[index-8].encode("utf8") |
| 1878 if index-7 > 0: print "-7 :", _lines[index-7] | 1918 if index-7 > 0: print "-7 :", _lines[index-7].encode("utf8") |
| 1879 if index-6 > 0: print "-6 :", _lines[index-6] | 1919 if index-6 > 0: print "-6 :", _lines[index-6].encode("utf8") |
| 1880 if index-5 > 0: print "-5 :", _lines[index-5] | 1920 if index-5 > 0: print "-5 :", _lines[index-5].encode("utf8") |
| 1881 if index-4 > 0: print "-4 :", _lines[index-4] | 1921 if index-4 > 0: print "-4 :", _lines[index-4].encode("utf8") |
| 1882 if index-3 > 0: print "-3 :", _lines[index-3] | 1922 if index-3 > 0: print "-3 :", _lines[index-3].encode("utf8") |
| 1883 if index-2 > 0: print "-2 :", _lines[index-2] | 1923 if index-2 > 0: print "-2 :", _lines[index-2].encode("utf8") |
| 1884 if index-1 > 0: print "-1 :", _lines[index-1] | 1924 if index-1 > 0: print "-1 :", _lines[index-1].encode("utf8") |
| 1885 print "-0 :", _lines[index-0] | 1925 print "-0 :", _lines[index-0] |
| 1886 pass | 1926 pass |
| 1887 else: | 1927 else: |
| 1888 _parameter_list = _line.split("\\")[1:-1] | 1928 _parameter_list = _line.split(u"\\")[1:-1] |
| 1889 if len(_parameter_list) >= 2: | 1929 if len(_parameter_list) >= 2: |
| 1890 if _parameter_list[0] == "C" or \ | 1930 if _parameter_list[0] == u"C" or \ |
| 1891 _parameter_list[0] == "COMENTARIO": | 1931 _parameter_list[0] == u"COMENTARIO": |
| 1892 #print "__COMENTARIO__" + _parameter_list[1] | 1932 #print "__COMENTARIO__" + _parameter_list[1] |
| 1893 self.__budget.setParametricSelectComment( | 1933 self.__budget.setParametricSelectComment( |
| 1894 _family_code, _parameter_list[1]) | 1934 _family_code.encode("utf8"), _parameter_list[1].encode("utf8")) |
| 1895 elif _parameter_list[0] == "R" or \ | 1935 elif _parameter_list[0] == u"R" or \ |
| 1896 _parameter_list[0] == "RESUMEN": | 1936 _parameter_list[0] == u"RESUMEN": |
| 1897 #print "__RESUMEN__" + _parameter_list[1] | 1937 #print "__RESUMEN__" + _parameter_list[1] |
| 1898 self.__budget.setParametricSummary(_family_code, | 1938 self.__budget.setParametricSummary(_family_code.encode("utf8"), |
| 1899 _parameter_list[1]) | 1939 _parameter_list[1].encode("utf8")) |
| 1900 elif _parameter_list[0] == "T" or \ | 1940 elif _parameter_list[0] == u"T" or \ |
| 1901 _parameter_list[0] == "TEXTO": | 1941 _parameter_list[0] == u"TEXTO": |
| 1902 #print "__TEXTO__" + _parameter_list[1] | 1942 #print "__TEXTO__" + _parameter_list[1] |
| 1903 self.__budget.setParametricText(_family_code, | 1943 self.__budget.setParametricText(_family_code.encode("utf8"), |
| 1904 _parameter_list[1]) | 1944 _parameter_list[1].encode("utf8")) |
| 1905 elif _parameter_list[0] == "P" or \ | 1945 elif _parameter_list[0] == u"P" or \ |
| 1906 _parameter_list[0] == "PLIEGO": | 1946 _parameter_list[0] == u"PLIEGO": |
| 1907 #print "__PLIEGO__" + str(_parameter_list[1:]) | 1947 #print "__PLIEGO__" + str(_parameter_list[1:]) |
| 1908 pass | 1948 pass |
| 1909 elif _parameter_list[0] == "K" or \ | 1949 elif _parameter_list[0] == u"K" or \ |
| 1910 _parameter_list[0] == "CLAVES": | 1950 _parameter_list[0] == u"CLAVES": |
| 1911 #print "__CLAVES__" + str(_parameter_list[1:]) | 1951 #print "__CLAVES__" + str(_parameter_list[1:]) |
| 1912 pass | 1952 pass |
| 1913 elif _parameter_list[0] == "F" or \ | 1953 elif _parameter_list[0] == u"F" or \ |
| 1914 _parameter_list[0] == "COMERCIAL": | 1954 _parameter_list[0] == u"COMERCIAL": |
| 1915 #print "__COMERCIAL__" + str(_parameter_list[1:]) | 1955 #print "__COMERCIAL__" + str(_parameter_list[1:]) |
| 1916 pass | 1956 pass |
| 1917 else: | 1957 else: |
| 1918 #print "==PARAMETRO==" + str(_parameter_list[:]) | 1958 #print "==PARAMETRO==" + str(_parameter_list[:]) |
| 1919 pass | 1959 pass |
| 1920 _final_description = _final_description + _line + "\r\n" | 1960 _final_description = _final_description + _line + u"\r\n" |
| 1921 | 1961 |
| 1922 #print _line | 1962 #print _line |
| 1923 # Delete last empty line | 1963 # Delete last empty line |
| 1924 _description = _final_description[:-2] | 1964 _description = _final_description[:-2] |
| 1925 _lines = _description.split("\r\n") | 1965 _lines = _description.split(u"\r\n") |
| 1926 for _line in _lines: | 1966 for _line in _lines: |
| 1927 pass | 1967 pass |
| 1928 #print _line | 1968 #print _line |
| 1929 self.num_valid_record = self.num_valid_record + 1 | 1969 self.num_valid_record = self.num_valid_record + 1 |
| 1930 | 1970 |
| 1993 if len(registro_V) > 5: | 2033 if len(registro_V) > 5: |
| 1994 _version = registro_V[5].strip() | 2034 _version = registro_V[5].strip() |
| 1995 # remove leading spaces | 2035 # remove leading spaces |
| 1996 if _version in self.__character_sets_dict: | 2036 if _version in self.__character_sets_dict: |
| 1997 self.__character_set = self.__character_sets_dict[_version] | 2037 self.__character_set = self.__character_sets_dict[_version] |
| 2038 print utils.mapping(_("FIEBDC character encoding: $1"),(self.__character_set,)) | |
| 1998 else: | 2039 else: |
| 1999 print utils.mapping(_("This codepage do not exist in "\ | 2040 print utils.mapping(_("This Character encoding do not exist in "\ |
| 2000 "FIEBDC3! Default codepage: $1"), | 2041 "FIEBDC3! Default Character encoding: $1"), |
| 2001 (self.__character_set,)) | 2042 (self.__character_set,)) |
| 2002 else: | 2043 else: |
| 2003 print utils.mapping(_("This V record dot have a codepage! "\ | 2044 print utils.mapping(_("This V record dot have a character encoding! "\ |
| 2004 "Default codepage: $1"), | 2045 "Default character encoding: $1"), |
| 2005 (self.__character_set,)) | 2046 (self.__character_set,)) |
| 2006 else: | 2047 else: |
| 2007 print utils.mapping(_("Not 'V' record in File! Default codepage: "\ | 2048 print utils.mapping(_("Not 'V' record in File! Default character encoding: "\ |
| 2008 "$1"), (self.__character_set,)) | 2049 "$1"), (self.__character_set,)) |
| 2009 if self.__character_set != "utf8": | 2050 _buffer = unicode(_buffer, self.__character_set) |
| 2010 _buffer = unicode(_buffer, self.__character_set) | |
| 2011 _buffer = _buffer.encode("utf8") | |
| 2012 # Any INFORMATION between the beginning of the file and the | 2051 # Any INFORMATION between the beginning of the file and the |
| 2013 # beginning of the first registry “~” is ignored | 2052 # beginning of the first registry “~” is ignored |
| 2014 #"after_first_tilde" : "^[^~]*~" | 2053 #"after_first_tilde" : "^[^~]*~" |
| 2015 _buffer = self.__pattern["after_first_tilde"].sub("",_buffer) | 2054 _buffer = self.__pattern["after_first_tilde"].sub("",_buffer) |
| 2016 while _buffer != "" and not self.__cancel: | 2055 while _buffer != u"" and not self.__cancel: |
| 2017 #-# the blank characters (32), tabs (9) and end of line (13 and 10) | 2056 #-# the blank characters (32), tabs (9) and end of line (13 and 10) |
| 2018 # before the separators '~', '|' are erased. | 2057 # before the separators '~', '|' are erased. |
| 2019 # Before separator \ not deleted because it affects the reading of | 2058 # Before separator \ not deleted because it affects the reading of |
| 2020 # the record ~P | 2059 # the record ~P |
| 2021 _buffer = self.eraseControlCharacters(_buffer) | 2060 _buffer = self.eraseControlCharacters(_buffer) |
| 2022 _record_list = _buffer.split("~") | 2061 _record_list = _buffer.split(u"~") |
| 2023 # The last record can be incomplete unless it is the last one of | 2062 # The last record can be incomplete unless it is the last one of |
| 2024 # the file | 2063 # the file |
| 2025 if len(_record_list) > 1: | 2064 if len(_record_list) > 1: |
| 2026 # not the end | 2065 # not the end |
| 2027 _last_record = _record_list.pop() | 2066 _last_record = _record_list.pop() |
| 2028 else: | 2067 else: |
| 2029 # the end record | 2068 # the end record |
| 2030 # The blank characters (32), tabs (9) and end of line | 2069 # The blank characters (32), tabs (9) and end of line |
| 2031 # (13 and 10) at the end of the file are ignored. | 2070 # (13 and 10) at the end of the file are ignored. |
| 2032 #"end_control" : "((\r\n)| |\t)+$" | 2071 #"end_control" : "((\r\n)| |\t)+$" |
| 2033 _record_list[-1] = self.__pattern["end_control"].sub("", | 2072 _record_list[-1] = self.__pattern["end_control"].sub(u"", |
| 2034 _record_list[-1]) | 2073 _record_list[-1]) |
| 2035 _last_record = "" | 2074 _last_record = u"" |
| 2036 for record in _record_list: | 2075 for record in _record_list: |
| 2037 if self.__cancel: | 2076 if self.__cancel: |
| 2038 break | 2077 break |
| 2039 self.parseRecord(record) | 2078 self.parseRecord(record) |
| 2040 interface.progress(_file.tell() / _filesize) | 2079 interface.progress(_file.tell() / _filesize) |
| 2041 _buffer2 = _file.read(100000) | 2080 _buffer2 = _file.read(100000) |
| 2042 if self.__character_set != "utf8": | 2081 _buffer2 = unicode(_buffer2, self.__character_set) |
| 2043 _buffer2 = unicode(_buffer2, self.__character_set) | |
| 2044 _buffer2 = _buffer2.encode("utf8") | |
| 2045 _buffer = _last_record + _buffer2 | 2082 _buffer = _last_record + _buffer2 |
| 2046 _file.close() | 2083 _file.close() |
| 2047 if self.__cancel: | 2084 if self.__cancel: |
| 2048 print _("Process terminated") | 2085 print _("Process terminated") |
| 2049 return None | 2086 return None |
| 2113 budget.addPriceToRecord(_price,_record) | 2150 budget.addPriceToRecord(_price,_record) |
| 2114 print _("End Test") | 2151 print _("End Test") |
| 2115 | 2152 |
| 2116 def delete_control_space(self, text): | 2153 def delete_control_space(self, text): |
| 2117 text = self.delete_control(text) | 2154 text = self.delete_control(text) |
| 2118 text = text.replace(" ", "") | 2155 text = text.replace(u" ", u"") |
| 2119 return text | 2156 return text |
| 2120 | 2157 |
| 2121 def delete_control(self, text): | 2158 def delete_control(self, text): |
| 2122 text = text.replace("\t", "") | 2159 text = text.replace(u"\t", u"") |
| 2123 text = text.replace("\r", "") | 2160 text = text.replace(u"\r", u"") |
| 2124 text = text.replace("\n", "") | 2161 text = text.replace(u"\n", u"") |
| 2125 return text | 2162 return text |
