comparison Generic/fiebdc.py @ 23:65e7ae0d0e63

GTK2 to GTK3
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Thu, 02 May 2019 16:31:17 +0200
parents f7e0cc58737f
children 189f8274aecd
comparison
equal deleted inserted replaced
22:7bd4ca56607d 23:65e7ae0d0e63
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-2014 Miguel Ángel Bárcena Rodríguez 6 ## Copyright (C) 2010-2019 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
36 class Read(object): 36 class Read(object):
37 """fiebdc.Read: 37 """fiebdc.Read:
38 38
39 Description: 39 Description:
40 Reads and parses a fiebdc file 40 Reads and parses a fiebdc file
41 +-- __budget: budget ("base.Budget" object)
42 +-- __file_format: File format of the fiebdc file
43 +-- __format_list: List of file format that can be readed
44 +-- __character_sets_dict: Dictionary with the character sets supported
45 +-- __character_set: character_set of the file
46 +- __generator: program which the file is created
47 +-- __cancel: Boolean value, True mean that the read process must stop
48 +-- __filename: The filename of the fiebdc file that is readed
49 +-- __pattern: re compiled pattern dict
50 +-- __statistics: Statistics object, records number
41 Constructor: 51 Constructor:
42 fiebdc.Read(filename=None, budget=None) 52 fiebdc.Read(filename=None, budget=None)
43 Ancestry: 53 Ancestry:
44 +-- object 54 +-- object
45 +-- Read 55 +-- Read
46 Atributes: 56 Atributes:
47 "__budget": budget ("base.Budget" object) 57 No public Atributes
48 "__file_format": File format of the fiebdc file
49 "__format_list": List of file format that can be readed
50 "__character_sets_dict": Dictionary with the character sets supported
51 "__character_set": character_set of the file
52 "__generator": program which the file is created
53 "__cancel": Boolean value, True mean that the read process must stop
54 "__filename": The filename of the fiebdc file that is readed
55 "__pattern": re compiled pattern dict
56 "__statistics": Statistics object, records number
57 Methods: 58 Methods:
58 __init__(self, filename=None, budget=None) 59 cancel()
59 cancel(self) 60 eraseControlCharacters(string)
60 eraseControlCharacters(self, string) 61 validateCode(code)
61 validateCode(self, code) 62 parseDate(date)
62 parseDate(self, date) 63 parseRecord(record)
63 parseRecord(self,record) 64 readFile(budget=None, filename=None)
64 _parseV(self, field_list)
65 _parseC(self, field_list)
66 _parseDY(self, field_list)
67 _parseMN(self, field_list)
68 _parseT(self, field_list)
69 _parseK(self, field_list)
70 _parseW(self, field_list)
71 _parseL(self, field_list)
72 _parseQ(self, field_list)
73 _parseJ(self, field_list)
74 _parseG(self, field_list)
75 _parseE(self, field_list)
76 _parseX(self, field_list)
77 _parseF(self, field_list)
78 readFile(self, budget=None, filename=None)
79 """ 65 """
80 def __init__(self, filename=None, budget=None): 66 def __init__(self, filename=None, budget=None):
81 """def __init__(self, filename=None, budget=None) 67 """def __init__(filename=None, budget=None)
82 68
83 Sets the instance attributes 69 Sets the instance attributes
70 __budget: budget ("base.Budget" object)
71 __file_format: File format of the fiebdc file
72 __format_list: List of file format that can be readed
73 __character_sets_dict: Dictionary with the character sets supported
74 __character_set: character_set of the file
75 __generator: program which the file is created
76 __cancel: Boolean value, True mean that the read process must stop
77 __filename: The filename of the fiebdc file that is readed
78 __pattern: re compiled pattern dict
79 __statistics: Statistics object, records number
84 """ 80 """
85 self.__budget = budget 81 self.__budget = budget
86 self.__filename = filename 82 self.__filename = filename
87 if not self.__budget is None: 83 if not self.__budget is None:
88 self.__budget.filename = self.__filename 84 self.__budget.filename = self.__filename
94 # 437 -> IBM437 -> cp437 90 # 437 -> IBM437 -> cp437
95 self.__character_sets_dict = {"ANSI" : "cp1252", 91 self.__character_sets_dict = {"ANSI" : "cp1252",
96 "850" : "850", 92 "850" : "850",
97 "437" : "cp437"} 93 "437" : "cp437"}
98 self.__file_format = "FIEBDC-3/2007" 94 self.__file_format = "FIEBDC-3/2007"
99 self.__generator = globalVars.version 95 self.__generator = globalVars.name + " " + globalVars.version
100 self.__character_set = "850" 96 self.__character_set = "850"
101 self.__pattern = { 97 self.__pattern = {
102 "control_tilde" : re.compile(u"((\r\n)| |\t)+~"), 98 "control_tilde" : re.compile(u"((\r\n)| |\t)+~"),
103 "control_vbar" : re.compile(u"((\r\n)| |\t)+\|"), 99 "control_vbar" : re.compile(u"((\r\n)| |\t)+\|"),
104 "control_backslash" : re.compile(ur"((\r\n)| |\t)+\\"), 100 "control_backslash" : re.compile(ur"((\r\n)| |\t)+\\"),
119 "end_control" : re.compile(u"((\r\n)| |\t)+$"), 115 "end_control" : re.compile(u"((\r\n)| |\t)+$"),
120 } 116 }
121 self.__statistics = Statistics() 117 self.__statistics = Statistics()
122 118
123 def cancel(self): 119 def cancel(self):
124 """def cancel(self) 120 """def cancel()
125 121
126 Sets the "__cancel" attribute to True, It stops the read process. 122 Sets the "__cancel" attribute to True, It stops the read process.
127 """ 123 """
128 self.__cancel = True 124 self.__cancel = True
129 125
130 def eraseControlCharacters(self, string): 126 def eraseControlCharacters(self, string):
131 """eraseControlCharacters(self,string) 127 """eraseControlCharacters(string)
132 128
133 Return a copy of the string with the blank characters (32), 129 Return a copy of the string with the blank characters (32),
134 tabs (9) and end of line (13 and 10) before of the separators 130 tabs (9) and end of line (13 and 10) before of the separators
135 '~', '|' erased. 131 '~', '|' erased.
136 Before separator \ not deleted because it affects the reading of the 132 Before separator \ not deleted because it affects the reading of the
143 # "control_backslash" : r"((\r\n)| |\t)+\\" 139 # "control_backslash" : r"((\r\n)| |\t)+\\"
144 #string = self.__pattern["control_backslash"].sub(r"\\",string) 140 #string = self.__pattern["control_backslash"].sub(r"\\",string)
145 return string 141 return string
146 142
147 def validateCode(self, code): 143 def validateCode(self, code):
148 """validateCode(self, code) 144 """validateCode(code)
149 145
150 Test if the code have invalid characters and try to erase it, 146 Test if the code have invalid characters and try to erase it,
151 if it is posible return a valid code else return a empty string. 147 if it is posible return a valid code else return a empty string.
152 """ 148 """
153 if not isinstance(code, unicode): 149 if not isinstance(code, unicode):
154 print _("Invalid code, it must be a unicode string") 150 print(_("Invalid code, it must be a unicode string") )
155 return u"" 151 return u""
156 # Valid chararcter: A-Z a-z 0-9 ñ Ñ . $ # % & _ 152 # Valid chararcter: A-Z a-z 0-9 ñ Ñ . $ # % & _
157 # "valid_code" : "[^A-Za-z0-9ñÑ.$#%&_]" 153 # "valid_code" : "[^A-Za-z0-9ñÑ.$#%&_]"
158 _ucode = self.__pattern["valid_code"].sub(u"", code) 154 _ucode = self.__pattern["valid_code"].sub(u"_", code)
159 if _ucode != code: 155 if _ucode != code:
160 try: 156 try:
161 print utils.mapping(_("The code '$1' have invalid characters."), 157 print(utils.mapping(_("The code '$1' have invalid characters, replaced by '$2'."),
162 (code.encode("utf8"),)) 158 (code.encode("utf8"),_ucode.encode("utf8"))) )
163 except: 159 except:
164 print utils.mapping(_("The code '$1' have invalid characters and can not be encoded in utf8."), (code,)) 160 print(utils.mapping(_("The code '$1' have invalid characters and can not be encoded in utf8."), (code,)) )
165 161
166 if len(_ucode) == 0: 162 if len(_ucode) == 0:
167 _normalize_code = ''.join((c for c in unicodedata.normalize('NFD', _ucode) if unicodedata.category(c) != 'Mn')) 163 _normalize_code = ''.join((c for c in unicodedata.normalize('NFD', _ucode) if unicodedata.category(c) != 'Mn'))
168 # from http://www.leccionespracticas.com/uncategorized/eliminar-tildes-con-python-solucionado/ 164 # from http://www.leccionespracticas.com/uncategorized/eliminar-tildes-con-python-solucionado/
169 _ucode = self.__pattern["valid_code"].sub(u"", _normalize_code) 165 _ucode = self.__pattern["valid_code"].sub(u"", _normalize_code)
171 _hash_code = hashlib.sha256() 167 _hash_code = hashlib.sha256()
172 _hash_code.update(code.encode('utf-8')) 168 _hash_code.update(code.encode('utf-8'))
173 _hexdigest_code = _hash_code.hexdigest() 169 _hexdigest_code = _hash_code.hexdigest()
174 _ucode = self.__pattern["valid_code"].sub(u"", _hexdigest_code) 170 _ucode = self.__pattern["valid_code"].sub(u"", _hexdigest_code)
175 code = _ucode 171 code = _ucode
172 if code == u"##":
173 # root code is an empty code : set to ROOT
174 return u"ROOT"
176 # the lasts characters can not be <#> or <##> 175 # the lasts characters can not be <#> or <##>
177 # <##> -> root record in FIEFDC-3 176 # <##> -> root record in FIEFDC-3
178 # <#> -> chapter record in FIEFDC-3 177 # <#> -> chapter record in FIEFDC-3
179 if len(code) > 0: 178 if len(code) > 0:
180 while code[-1] == u"#": 179 while code[-1] == u"#":
181 code = code[:-1] 180 code = code[:-1]
181 if len(code) == 0:
182 return code
182 if len(code) > 20: 183 if len(code) > 20:
183 code = code[:20] 184 code = code[:20]
184 # only one charecter # % or & 185 # only one charecter # % or &
185 if sum([code.count(c) for c in u'#%&']) > 1: 186 if sum([code.count(c) for c in u'#%&']) > 1:
186 print utils.mapping(_("The code '$1' contains special "\ 187 print(utils.mapping(_("The code '$1' contains special "\
187 "characters repeated."),(code.encode("utf8"),)) 188 "characters repeated."),(code.encode("utf8"),)) )
188 _i = min([code.find(c) for c in u'#%&']) 189 _i = min([code.find(c) for c in u'#%&'])
189 code = code[:_i+1] + \ 190 code = code[:_i+1] + \
190 self.__pattern["special_char"].sub(u"", code[_i+1:]) 191 self.__pattern["special_char"].sub(u"", code[_i+1:])
191 return code 192 return code
192 193
193 def parseDate(self, date): 194 def parseDate(self, date):
194 """parseDate(self, date) 195 """parseDate(date)
195 196
196 date: in the format: 197 date: in the format:
197 uneven len: add a Leading 0 198 uneven len: add a Leading 0
198 len = 8 DDMMYYYY 199 len = 8 DDMMYYYY
199 len <= 6 DDMMYY “80/20”. >80 -> >1980 <80 -> <2080 200 len <= 6 DDMMYY “80/20”. >80 -> >1980 <80 -> <2080
231 if _m != 0 and _d != 0: 232 if _m != 0 and _d != 0:
232 if calendar.monthrange(_y, _m)[1] < _d: 233 if calendar.monthrange(_y, _m)[1] < _d:
233 _d = 0 234 _d = 0
234 return (_y, _m, _d) 235 return (_y, _m, _d)
235 236
236 def parseRecord(self,record): 237 def parseRecord(self, record, interface):
237 """parseRecord(self,record) 238 """parseRecord(record, interface)
238 239
239 record: the record line readed from the file whith the format: 240 record: the record line readed from the file whith the format:
240 type|field|field|subfield\subfield|... 241 type|field|field|subfield\subfield|...
241 [a] nothing or "a" 242 [a] nothing or "a"
242 {a} zero or more #-#twice#-# "a" 243 {a} zero or more #-#twice#-# "a"
315 1- Record Code 316 1- Record Code
316 2- New code 317 2- New code
317 A: Labels 318 A: Labels
318 1- Record Code 319 1- Record Code
319 2- <Label\> 320 2- <Label\>
321 interface:
320 """ 322 """
321 # TODO: ~L ~J RTF and HTML files 323 # TODO: ~L ~J RTF and HTML files
322 # TODO: test ~Q ~J ~G 324 # TODO: test ~Q ~J ~G
323 # TODO: ~P. Registro tipo Descripción Paramétrica. 325 # TODO: ~P. Registro tipo Descripción Paramétrica.
324 # TODO: ~O. Registro tipo Relación Comercial. 326 # TODO: ~O. Registro tipo Relación Comercial.
329 if _field_list[0] == u"V": 331 if _field_list[0] == u"V":
330 self.__statistics.V += 1 332 self.__statistics.V += 1
331 self._parseV(_field_list) 333 self._parseV(_field_list)
332 elif _field_list[0] == u"C": 334 elif _field_list[0] == u"C":
333 self.__statistics.C += 1 335 self.__statistics.C += 1
334 self._parseC(_field_list) 336 self._parseC(_field_list, interface)
335 elif _field_list[0] == u"D": 337 elif _field_list[0] == u"D":
336 self.__statistics.D += 1 338 self.__statistics.D += 1
337 self._parseDY(_field_list) 339 self._parseDY(_field_list, interface)
338 elif _field_list[0] == u"Y": 340 elif _field_list[0] == u"Y":
339 self.__statistics.Y += 1 341 self.__statistics.Y += 1
340 self._parseDY(_field_list) 342 self._parseDY(_field_list, interface)
341 elif _field_list[0] == u"M": 343 elif _field_list[0] == u"M":
342 self.__statistics.M += 1 344 self.__statistics.M += 1
343 self._parseMN(_field_list) 345 self._parseMN(_field_list)
344 elif _field_list[0] == u"N": 346 elif _field_list[0] == u"N":
345 self.__statistics.N += 1 347 self.__statistics.N += 1
384 self._parseF(_field_list) 386 self._parseF(_field_list)
385 elif _field_list[0] == u"A": 387 elif _field_list[0] == u"A":
386 self.__statistics.A += 1 388 self.__statistics.A += 1
387 self._parseA(_field_list) 389 self._parseA(_field_list)
388 else: 390 else:
391 print(utils.mapping(_("FIEBDC. Unknow record: $1"),(record[:100],)))
389 self.__statistics.unknow += 1 392 self.__statistics.unknow += 1
390 393
391 def _parseV(self, field_list): 394 def _parseV(self, field_list):
392 """_parseV(self, field_list) 395 """_parseV(field_list)
393 396
394 field_list: field list of the record 397 field_list: field list of the record
395 0- V :Property and Version 398 0- V :Property and Version
396 1- [File_Owner] 399 1- [File_Owner]
397 2- Format_Version[\DDMMYYYY] 400 2- Format_Version[\DDMMYYYY]
402 7- [Data type] 405 7- [Data type]
403 8- [Number budget certificate] 406 8- [Number budget certificate]
404 9- [Date budget certificate] 407 9- [Date budget certificate]
405 """ 408 """
406 if self.__statistics.records != 1: 409 if self.__statistics.records != 1:
407 print utils.mapping(_("The 'V' record (Property and Version) "\ 410 print(utils.mapping(_("The 'V' record (Property and Version) "\
408 "must be the first record in the file but it is the "\ 411 "must be the first record in the file but it is the "\
409 "number: $1"), (self.__statistics.records,)) 412 "number: $1"), (str(self.__statistics.records),)) )
410 print _("The default values were taken and this V record is "\ 413 print(_("The default values were taken and this V record is "\
411 "ignored") 414 "ignored") )
412 return 415 return
413 # _____number of fields_____ 416 # _____number of fields_____
414 # Any INFORMATION after last field separator is ignored 417 # Any INFORMATION after last field separator is ignored
415 if len(field_list) > 10: 418 if len(field_list) > 10:
416 field_list = field_list[:10] 419 field_list = field_list[:10]
439 # _____Version-Date_____ 442 # _____Version-Date_____
440 _version_date = _version_date.split(u"\\") 443 _version_date = _version_date.split(u"\\")
441 _file_format = _version_date[0] 444 _file_format = _version_date[0]
442 if _file_format in self.__format_list: 445 if _file_format in self.__format_list:
443 self.__file_format = _file_format 446 self.__file_format = _file_format
444 print utils.mapping(_("FIEBDC format: $1"),(_file_format,)) 447 print(utils.mapping(_("FIEBDC format: $1"),(_file_format,)) )
445 448
446 if len(_version_date) > 1: 449 if len(_version_date) > 1:
447 _date = _version_date[1] 450 _date = _version_date[1]
448 if _date != u"": 451 if _date != u"":
449 _parsed_date = self.parseDate(_date) 452 _parsed_date = self.parseDate(_date)
450 if _parsed_date is not None: 453 if _parsed_date is not None:
451 self.__budget.setDate(_parsed_date) 454 self.__budget.setDate(_parsed_date)
452 # _____Generator_____ 455 # _____Generator_____
453 # ignored field 456 # ignored field
454 print utils.mapping(_("FIEBDC file generated by $1"),(_generator,)) 457 print(utils.mapping(_("FIEBDC file generated by $1"),(_generator,)) )
455 # _____Header_Title_____ 458 # _____Header_Title_____
456 _header_title = _header_title.split(u"\\") 459 _header_title = _header_title.split(u"\\")
457 _header_title = [_title.strip() for _title in _header_title] 460 _header_title = [_title.strip() for _title in _header_title]
458 _header = _header_title.pop(0) 461 _header = _header_title.pop(0)
459 _header = [_item.encode("utf8") for _item in _header] 462 _header = [_item.encode("utf8") for _item in _header]
497 elif _data_type != "": 500 elif _data_type != "":
498 self.__budget.setBudgeType(_data_type) 501 self.__budget.setBudgeType(_data_type)
499 self.__statistics.valid = self.__statistics.valid + 1 502 self.__statistics.valid = self.__statistics.valid + 1
500 503
501 def _parseK(self, field_list): 504 def _parseK(self, field_list):
502 """_parseK(self, field_list) 505 """_parseK(field_list)
503 506
504 field_list: field list of the record 507 field_list: field list of the record
505 0- K: Coefficients 508 0- K: Coefficients
506 1- { DN \ DD \ DS \ DR \ DI \ DP \ DC \ DM \ DIVISA \ } 509 1- { DN \ DD \ DS \ DR \ DI \ DP \ DC \ DM \ DIVISA \ }
507 2- CI \ GG \ BI \ BAJA \ IVA 510 2- CI \ GG \ BI \ BAJA \ IVA
738 _decimal_index = _decimal_index + 13 741 _decimal_index = _decimal_index + 13
739 self.__budget.setDecimals(_percentage_dict, 742 self.__budget.setDecimals(_percentage_dict,
740 (_decimal_index//13)) 743 (_decimal_index//13))
741 self.__statistics.valid = self.__statistics.valid +1 744 self.__statistics.valid = self.__statistics.valid +1
742 745
743 def _parseC(self, field_list): 746 def _parseC(self, field_list, interface):
744 """_parseC(self, field_list) 747 """_parseC(field_list)
745 748
746 field_list: field list of the record 749 field_list: field list of the record
747 0- C: Record 750 0- C: Record
748 1- Code{\Code} 751 1- Code{\Code}
749 2- [Unit] 752 2- [Unit]
772 # _____Code_____ 775 # _____Code_____
773 _codes = _codes.split(u"\\") 776 _codes = _codes.split(u"\\")
774 if len(_codes) > 0: 777 if len(_codes) > 0:
775 # parse the hierarchy of the first code 778 # parse the hierarchy of the first code
776 # hierarchy: 0->root, 1->Chapter/subchapter, 2->other 779 # hierarchy: 0->root, 1->Chapter/subchapter, 2->other
777 if len(_codes[0]) > 2 and _codes[0][-2:] == u"##": 780 if len(_codes[0]) > 1 and _codes[0][-2:] == u"##":
778 _hierarchy = 0 781 _hierarchy = 0
779 elif len(_codes[0]) > 1 and _codes[0][-1:] == u"#": 782 elif len(_codes[0]) > 0 and _codes[0][-1:] == u"#":
780 _hierarchy = 1 783 _hierarchy = 1
781 else: 784 else:
782 _hierarchy = 2 785 _hierarchy = 2
783 # "#" and "##" characters at the end of the code are erased 786 # "#" and "##" characters at the end of the code are erased
784 # invalid characters are also erased 787 # invalid characters are also erased
790 if len(_codes) > 0: 793 if len(_codes) > 0:
791 #TODO: test this 794 #TODO: test this
792 _code = _codes[0] 795 _code = _codes[0]
793 _synonyms = [synonym.encode("utf8") for synonym in _codes] 796 _synonyms = [synonym.encode("utf8") for synonym in _codes]
794 else: 797 else:
795 print _("Record C without a valid code") 798 print(_("Record C without a valid code") )
796 return 799 return
797 # _____Unit_____ 800 # _____Unit_____
798 # nothing to do 801 # nothing to do
799 # _____Summary_____ 802 # _____Summary_____
800 # nothing to do 803 # nothing to do
802 # last \ is erased 805 # last \ is erased
803 if len(_dates) > 0 and _dates[-1] == u"\\": 806 if len(_dates) > 0 and _dates[-1] == u"\\":
804 _dates = _dates[:-1] 807 _dates = _dates[:-1]
805 if len(_prices) > 0 and _prices[-1] == u"\\": 808 if len(_prices) > 0 and _prices[-1] == u"\\":
806 _prices = _prices[:-1] 809 _prices = _prices[:-1]
810 interface.updateGui()
807 _dates = _dates.split(u"\\") 811 _dates = _dates.split(u"\\")
808 _prices = _prices.split(u"\\") 812 _prices = _prices.split(u"\\")
809 # number of prices = number of titles in "V" line 813 # number of prices = number of titles in "V" line
810 # if there are no sufficient prices it takes the last price defined 814 # if there are no sufficient prices it takes the last price defined
811 _title_num = len(self.__budget.getTitleList()[1]) 815 _title_num = len(self.__budget.getTitleList()[1])
858 # 1->[sub]chapter -> 0 -> None,PU 862 # 1->[sub]chapter -> 0 -> None,PU
859 # 2->Other -> 0 -> None,EA,EU,EC,EF,PA 863 # 2->Other -> 0 -> None,EA,EU,EC,EF,PA
860 # 1 -> None,H 864 # 1 -> None,H
861 # 2 -> None,Q,% 865 # 2 -> None,Q,%
862 # 3 -> None,MC,MCr,MM,MS,ME,MCu,Mal,ML,M 866 # 3 -> None,MC,MCr,MM,MS,ME,MCu,Mal,ML,M
867 interface.updateGui()
863 if _hierarchy == 0: 868 if _hierarchy == 0:
864 if _type == u"OB": 869 if _type == u"OB":
865 _subtype = _type 870 _subtype = _type
866 _type = 0 871 _type = 0
867 elif _type == u"0" or _type == u"": 872 elif _type == u"0" or _type == u"":
868 _subtype = u"" 873 _subtype = u""
869 _type = 0 874 _type = 0
870 else: 875 else:
871 print utils.mapping(_("Incorrect type ($1) in the code $2"), 876 print(utils.mapping(_("Incorrect type ($1) in the code $2"),
872 (_type.encode("utf8"), _code.encode("utf8"))) 877 (_type.encode("utf8"), _code.encode("utf8"))) )
873 _type = 0 878 _type = 0
874 _subtype = u"" 879 _subtype = u""
875 elif _hierarchy == 1: 880 elif _hierarchy == 1:
876 if _type == u"PU": 881 if _type == u"PU":
877 _subtype = _type 882 _subtype = _type
878 _type = 0 883 _type = 0
879 elif _type == u"0" or _type == u"": 884 elif _type == u"0" or _type == u"":
880 _subtype = u"" 885 _subtype = u""
881 _type = 0 886 _type = 0
882 else: 887 else:
883 print utils.mapping(_("Incorrect type ($1) in the code $2"), 888 print(utils.mapping(_("Incorrect type ($1) in the code $2"),
884 (_type.encode("utf8"), _code.encode("utf8"))) 889 (_type.encode("utf8"), _code.encode("utf8"))) )
885 _type = 0 890 _type = 0
886 _subtype = u"" 891 _subtype = u""
887 else: 892 else:
888 if _type == u"EA" or _type == u"EU" or _type == u"EC" or \ 893 if _type == u"EA" or _type == u"EU" or _type == u"EC" or \
889 _type == u"EF" or _type == u"PA": 894 _type == u"EF" or _type == u"PA":
906 _type = int(_type) 911 _type = int(_type)
907 elif _type == u"": 912 elif _type == u"":
908 _subtype = u"" 913 _subtype = u""
909 _type = 0 914 _type = 0
910 else: 915 else:
911 print utils.mapping(_("Incorrect type ($1) in the code $2"), 916 print(utils.mapping(_("Incorrect type ($1) in the code $2"),
912 (_type.encode("utf8"), _code.encode("utf8"))) 917 (_type.encode("utf8"), _code.encode("utf8"))) )
913 _type = 0 918 _type = 0
914 _subtype = u"" 919 _subtype = u""
915 self.__budget.setRecord(_code.encode("utf8"), _synonyms, _hierarchy, 920 self.__budget.setRecord(_code.encode("utf8"), _synonyms, _hierarchy,
916 _unit.encode("utf8"), _summary.encode("utf8"), 921 _unit.encode("utf8"), _summary.encode("utf8"),
917 _prices, _dates, _type, _subtype.encode("utf8")) 922 _prices, _dates, _type, _subtype.encode("utf8"))
918 self.__statistics.valid = self.__statistics.valid + 1 923 self.__statistics.valid = self.__statistics.valid + 1
919 924
920 def _parseDY(self, field_list): 925 def _parseDY(self, field_list, interface):
921 """_parseDY(self, field_list) 926 """_parseDY(field_list)
922 927
923 field_list: field list of the record 928 field_list: field list of the record
924 0- D or Y: DECOMPOSITION or ADD DECOMPOSITION 929 0- D or Y: DECOMPOSITION or ADD DECOMPOSITION
925 1- Parent Code 930 1- Parent Code
926 2- <Child Code\ [Factor]\ [Yield]> 931 2- <Child Code\ [Factor]\ [Yield]>
937 # control character are erased: end of line, tab, space 942 # control character are erased: end of line, tab, space
938 # _____Fields_____ 943 # _____Fields_____
939 _record_type = field_list[0] 944 _record_type = field_list[0]
940 _code = self.delete_control_space(field_list[1]) 945 _code = self.delete_control_space(field_list[1])
941 _children = self.delete_control_space(field_list[2]) 946 _children = self.delete_control_space(field_list[2])
947 interface.updateGui()
942 # _____Code_____ 948 # _____Code_____
943 # "#" and "##" characters at the end of the code are erased 949 # "#" and "##" characters at the end of the code are erased
944 # invalid characters are also erased 950 # invalid characters are also erased
945 _code = self.validateCode(_code) 951 _code = self.validateCode(_code)
946 # _____children_____ 952 # _____children_____
947 # TODO: test the number of decimals in factor an yield values 953 # TODO: test the number of decimals in factor an yield values
948 _children = _children.split(u"\\") 954 _children = _children.split(u"\\")
949 _children_list = [ ] 955 _children_list = [ ]
950 _child_index = 0 956 _child_index = 0
957 interface.updateGui()
951 while _child_index < len(_children)-3: 958 while _child_index < len(_children)-3:
952 # _____subfields_____ 959 # _____subfields_____
953 _child_code = _children[_child_index] 960 _child_code = _children[_child_index]
954 _factor = _children[_child_index+1] 961 _factor = _children[_child_index+1]
955 _yield = _children[_child_index+2] 962 _yield = _children[_child_index+2]
958 # _____factor_____ 965 # _____factor_____
959 if _factor != u"": 966 if _factor != u"":
960 try: 967 try:
961 _factor = float(_factor) 968 _factor = float(_factor)
962 except ValueError: 969 except ValueError:
963 print utils.mapping(_("ValueError loadig the "\ 970 print(utils.mapping(_("ValueError loadig the "\
964 "descomposition of the record $1, the factor "\ 971 "descomposition of the record $1, the factor "\
965 "of the child $2 must be a float number and "\ 972 "of the child $2 must be a float number and "\
966 "can not be $3, seted default value 1.0"), 973 "can not be $3, seted default value 1.0"),
967 (_code.encode("utf8"), _child_code.encode("utf8"), _factor.encode("utf8"))) 974 (_code.encode("utf8"), _child_code.encode("utf8"), _factor.encode("utf8"))) )
968 _factor = 1.0 975 _factor = 1.0
969 #____yield___ 976 #____yield___
970 if _yield != u"": 977 if _yield != u"":
971 try: 978 try:
972 _yield = float(_yield) 979 _yield = float(_yield)
973 except ValueError: 980 except ValueError:
974 print utils.mapping(_("ValueError loading the "\ 981 print(utils.mapping(_("ValueError loading the "\
975 "descomposition of the record $1, the yield of "\ 982 "descomposition of the record $1, the yield of "\
976 "the child $2, must be a float number and can"\ 983 "the child $2, must be a float number and can"\
977 "not be $3, seted default value 1.0"), 984 "not be $3, seted default value 1.0"),
978 (_code.encode("utf8"), _child_code.encode("utf8"), _factor.encode("utf8"))) 985 (_code.encode("utf8"), _child_code.encode("utf8"), _factor.encode("utf8"))) )
979 _yield = 1.0 986 _yield = 1.0
980 if _child_code != u"" and _code != u"": 987 if _child_code != u"" and _code != u"":
981 _children_list.append([_child_code, _factor, _yield ]) 988 _children_list.append([_child_code, _factor, _yield ])
982 if _record_type == u"D": 989 if _record_type == u"D":
983 _position = _child_index / 3 990 _position = _child_index / 3
984 else: #_record_type == "Y" 991 else: #_record_type == "Y"
985 _position = -1 992 _position = -1
986 self.__budget.setTree(_code.encode("utf8"), _child_code.encode("utf8"), _position, _factor, 993 self.__budget.setTree(_code.encode("utf8"), _child_code.encode("utf8"), _position, _factor,
987 _yield, "", "", "", "") 994 _yield, "", "", "", "")
988 _child_index = _child_index + 3 995 _child_index = _child_index + 3
996 interface.updateGui()
989 self.__statistics.valid = self.__statistics.valid +1 997 self.__statistics.valid = self.__statistics.valid +1
990 998
991 def _parseT(self, field_list): 999 def _parseT(self, field_list):
992 """_parseT(self, field_list) 1000 """_parseT(field_list)
993 1001
994 field_list: field list of the record 1002 field_list: field list of the record
995 0- T: Text 1003 0- T: Text
996 1- Record code 1004 1- Record code
997 2- Description text 1005 2- Description text
1015 # _____Text_____ 1023 # _____Text_____
1016 self.__budget.setText(_code.encode("utf8"), _text.encode("utf8")) 1024 self.__budget.setText(_code.encode("utf8"), _text.encode("utf8"))
1017 self.__statistics.valid = self.__statistics.valid + 1 1025 self.__statistics.valid = self.__statistics.valid + 1
1018 1026
1019 def _parseMN(self, field_list): 1027 def _parseMN(self, field_list):
1020 """_parseMN(self, field_list) 1028 """_parseMN(field_list)
1021 1029
1022 field_list: field list of the record 1030 field_list: field list of the record
1023 0- M or N: MEASURE or ADD MEASURE 1031 0- M or N: MEASURE or ADD MEASURE
1024 1- [Parent Code\]Child Code 1032 1- [Parent Code\]Child Code
1025 2- {Path\} 1033 2- {Path\}
1057 _child_code = self.validateCode(_code_list[1]) 1065 _child_code = self.validateCode(_code_list[1])
1058 elif len(_code_list) == 1: 1066 elif len(_code_list) == 1:
1059 _child_code = self.validateCode(_code_list[0]) 1067 _child_code = self.validateCode(_code_list[0])
1060 _parent_code = None 1068 _parent_code = None
1061 else: 1069 else:
1062 print utils.mapping(_("Invalid codes in $1 record, codes $2"), 1070 print(utils.mapping(_("Invalid codes in $1 record, codes $2"),
1063 (_record_type.encode("utf8"), _codes.encode("utf8"))) 1071 (_record_type.encode("utf8"), _codes.encode("utf8"))) )
1064 return 1072 return
1065 if _child_code == u"": 1073 if _child_code == u"":
1066 print utils.mapping(_("Empty child code in $1 record, codes: "\ 1074 print(utils.mapping(_("Empty child code in $1 record, codes: "\
1067 "$2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) 1075 "$2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) )
1068 return 1076 return
1069 if _parent_code == None: 1077 if _parent_code == None:
1070 # Empty parent code. No-estructured measures. 1078 # Empty parent code. No-estructured measures.
1071 pass 1079 pass
1072 1080
1081 else: 1089 else:
1082 _path = _path_list[-1] 1090 _path = _path_list[-1]
1083 try: 1091 try:
1084 _path = int(_path) 1092 _path = int(_path)
1085 except ValueError: 1093 except ValueError:
1086 print utils.mapping(_("Invalid path in $1 record, "\ 1094 print(utils.mapping(_("Invalid path in $1 record, "\
1087 "codes $2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) 1095 "codes $2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) )
1088 return 1096 return
1089 if _path > 0: 1097 if _path > 0:
1090 _path -= 1 1098 _path -= 1
1091 else: 1099 else:
1092 _path = -2 1100 _path = -2
1093 # _____Total_____ 1101 # _____Total_____
1094 try: 1102 try:
1095 _total = float(_total) 1103 _total = float(_total)
1096 except ValueError: 1104 except ValueError:
1097 print utils.mapping(_("Invalid Total Measure value in $1 "\ 1105 print(utils.mapping(_("Invalid Total Measure value in $1 "\
1098 "record, codes $2. Total fixed to 0."), 1106 "record, codes $2. Total fixed to 0."),
1099 (_record_type.encode("utf8"), _codes.encode("utf8"))) 1107 (_record_type.encode("utf8"), _codes.encode("utf8"))) )
1100 _total = 0 1108 _total = 0
1101 # _____Measure lines_____ 1109 # _____Measure lines_____
1102 _lines = _lines.split(u"\\") 1110 _lines = _lines.split(u"\\")
1103 _line_index = 0 1111 _line_index = 0
1104 _line_list = [ ] 1112 _line_list = [ ]
1113 _linetype = 0 1121 _linetype = 0
1114 _comment= _lines[_line_index + 1] 1122 _comment= _lines[_line_index + 1]
1115 if _linetype == 3: 1123 if _linetype == 3:
1116 # "formula": ".*[^0123456789\.()\+\-\*/\^abcdp ].*" 1124 # "formula": ".*[^0123456789\.()\+\-\*/\^abcdp ].*"
1117 if self.__pattern["formula"].match(_comment): 1125 if self.__pattern["formula"].match(_comment):
1118 print utils.mapping(_("The comment is not a formula or "\ 1126 print(utils.mapping(_("The comment is not a formula or "\
1119 "its have invalid characters, in the $1 record, "\ 1127 "its have invalid characters, in the $1 record, "\
1120 "codes $2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) 1128 "codes $2"), (_record_type.encode("utf8"), _codes.encode("utf8"))) )
1121 return 1129 return
1122 else: 1130 else:
1123 _formula = _comment.encode("utf8") 1131 _formula = _comment.encode("utf8")
1124 _comment = "" 1132 _comment = ""
1125 else: 1133 else:
1139 _units = float(_units) 1147 _units = float(_units)
1140 if _length != u"": _length = float(_length) 1148 if _length != u"": _length = float(_length)
1141 if _width != u"": _width = float(_width) 1149 if _width != u"": _width = float(_width)
1142 if _height != u"": _height = float(_height) 1150 if _height != u"": _height = float(_height)
1143 except ValueError: 1151 except ValueError:
1144 print utils.mapping(_("The measure values are not float "\ 1152 print(utils.mapping(_("The measure values are not float "\
1145 "numbers, code $1"), (_codes.encode("utf8"),)) 1153 "numbers, code $1"), (_codes.encode("utf8"),)) )
1146 return 1154 return
1147 # Prevent subfield units remains empty. 1155 # Prevent subfield units remains empty.
1148 if (_units == u"" and (_length != u"" or _width != u"" 1156 if (_units == u"" and (_length != u"" or _width != u""
1149 or _height != u"")): 1157 or _height != u"")):
1150 _units = 1.0 1158 _units = 1.0
1154 self.__budget.setTree(_parent_code, _child_code.encode("utf8"), _path, "", "", 1162 self.__budget.setTree(_parent_code, _child_code.encode("utf8"), _path, "", "",
1155 _total, _line_list, _label.encode("utf8"), _record_type.encode("utf8")) 1163 _total, _line_list, _label.encode("utf8"), _record_type.encode("utf8"))
1156 self.__statistics.valid = self.__statistics.valid + 1 1164 self.__statistics.valid = self.__statistics.valid + 1
1157 1165
1158 def _parseW(self, field_list): 1166 def _parseW(self, field_list):
1159 """_parseW(self, field_list) 1167 """_parseW(field_list)
1160 1168
1161 field_list: field list of the record 1169 field_list: field list of the record
1162 0- W: Geografical field 1170 0- W: Geografical field
1163 1- Field Code 1171 1- Field Code
1164 2- Field 1172 2- Field
1193 _field_index = _field_index + 2 1201 _field_index = _field_index + 2
1194 self.__budget.setSheetFields(_field_dict) 1202 self.__budget.setSheetFields(_field_dict)
1195 self.__statistics.valid = self.__statistics.valid +1 1203 self.__statistics.valid = self.__statistics.valid +1
1196 1204
1197 def _parseL(self, field_list): 1205 def _parseL(self, field_list):
1198 """_parseL(self, field_list) 1206 """_parseL(field_list)
1199 1207
1200 field_list: field list of the record 1208 field_list: field list of the record
1201 0- L: Sheet of Conditions 1 1209 0- L: Sheet of Conditions 1
1202 A: 1210 A:
1203 1- Empty 1211 1- Empty
1257 # invalid characters are also erased 1265 # invalid characters are also erased
1258 _record_code = self.validateCode(_record_code) 1266 _record_code = self.validateCode(_record_code)
1259 _scodes_text = field_list[1] 1267 _scodes_text = field_list[1]
1260 if _scodes_text == u"": 1268 if _scodes_text == u"":
1261 # TODO: rtf and html files 1269 # TODO: rtf and html files
1262 print "Html and rtf files not yet implemented in ~L record" 1270 print("Html and rtf files not yet implemented in ~L record" )
1263 else: 1271 else:
1264 # _____Section-code_Section-text_____ 1272 # _____Section-code_Section-text_____
1265 # last \ is erased 1273 # last \ is erased
1266 if len(_scodes_text) and _scodes_text[-1] == u"\\": 1274 if len(_scodes_text) and _scodes_text[-1] == u"\\":
1267 _scodes_text = _scodes_text[:-1] 1275 _scodes_text = _scodes_text[:-1]
1286 self.__budget.setSheetParagraphs(_paragraph_dict) 1294 self.__budget.setSheetParagraphs(_paragraph_dict)
1287 self.__budget.setSheetRecord(_record_code.encode("utf8"), "*", _section_dict) 1295 self.__budget.setSheetRecord(_record_code.encode("utf8"), "*", _section_dict)
1288 self.__statistics.valid = self.__statistics.valid +1 1296 self.__statistics.valid = self.__statistics.valid +1
1289 1297
1290 def _parseQ(self, field_list): 1298 def _parseQ(self, field_list):
1291 """_parseQ(self, field_list) 1299 """_parseQ(field_list)
1292 1300
1293 field_list: field list of the record 1301 field_list: field list of the record
1294 0- Q: Sheet of Conditions 2 1302 0- Q: Sheet of Conditions 2
1295 1- Record Code 1303 1- Record Code
1296 2- {Section Code\Paragraph key\{Field key;}\}| 1304 2- {Section Code\Paragraph key\{Field key;}\}|
1347 for _field, _section_dict in _field_dict.iteritems(): 1355 for _field, _section_dict in _field_dict.iteritems():
1348 self.__budget.setSheetRecord(_record_code.encode("utf8"), _field.encode("utf8"), _section_dict) 1356 self.__budget.setSheetRecord(_record_code.encode("utf8"), _field.encode("utf8"), _section_dict)
1349 self.__statistics.valid = self.__statistics.valid +1 1357 self.__statistics.valid = self.__statistics.valid +1
1350 1358
1351 def _parseJ(self, field_list): 1359 def _parseJ(self, field_list):
1352 """_parseJ(self, field_list) 1360 """_parseJ(field_list)
1353 1361
1354 field_list: field list of the record 1362 field_list: field list of the record
1355 0- J: Sheet of Conditions 3 1363 0- J: Sheet of Conditions 3
1356 1- Paragraph code 1364 1- Paragraph code
1357 2- [Paragraph text] 1365 2- [Paragraph text]
1372 _paragraph_code = self.delete_control_space(field_list[0]) 1380 _paragraph_code = self.delete_control_space(field_list[0])
1373 # _____Paragraph text_____ 1381 # _____Paragraph text_____
1374 _paragraph_text = field_list[1] 1382 _paragraph_text = field_list[1]
1375 if _paragraph_text == u"": 1383 if _paragraph_text == u"":
1376 # TODO: rtf and html files 1384 # TODO: rtf and html files
1377 print "Html and rtf files not yet implemented in ~J record" 1385 print("Html and rtf files not yet implemented in ~J record" )
1378 else: 1386 else:
1379 self.__budget.setSheetParagraph(paragraph_code.encode("utf8"), paragraph_text.encode("utf8")) 1387 self.__budget.setSheetParagraph(paragraph_code.encode("utf8"), paragraph_text.encode("utf8"))
1380 self.__statistics.valid = self.__statistics.valid +1 1388 self.__statistics.valid = self.__statistics.valid +1
1381 1389
1382 def _parseG(self, field_list): 1390 def _parseG(self, field_list):
1383 """_parseG(self, field_list) 1391 """_parseG(field_list)
1384 1392
1385 field_list: field list of the record 1393 field_list: field list of the record
1386 0- G: Grafic info 1394 0- G: Grafic info
1387 1- record code 1395 1- record code
1388 2- <grafic_file.ext\> 1396 2- <grafic_file.ext\>
1410 _grafic_files = _grafic_files[:-1] 1418 _grafic_files = _grafic_files[:-1]
1411 _grafic_file_list = _grafic_files.split(u"\\") 1419 _grafic_file_list = _grafic_files.split(u"\\")
1412 _tested_grafic_file_list = [] 1420 _tested_grafic_file_list = []
1413 for _grafic_file in _grafic_file_list: 1421 for _grafic_file in _grafic_file_list:
1414 _str_grafic_file = _grafic_file.encode("utf8") 1422 _str_grafic_file = _grafic_file.encode("utf8")
1415 _path = os.path.dirname(self.__filename) 1423 _path = os.path.dirname(self.__filename).encode("utf8")
1416 _grafic_file_path = os.path.join(_path, _str_grafic_file) 1424 _grafic_file_path = os.path.join(_path, _str_grafic_file)
1417 if os.path.exists(_grafic_file_path): 1425 if os.path.exists(_grafic_file_path):
1418 _tested_grafic_file_list.append(_grafic_file_path) 1426 _tested_grafic_file_list.append(_grafic_file_path)
1419 else: 1427 else:
1420 _name_ext = os.path.splitext(_str_grafic_file) 1428 _name_ext = os.path.splitext(_str_grafic_file)
1439 elif os.path.exists(_grafic_file_path_lu): 1447 elif os.path.exists(_grafic_file_path_lu):
1440 _tested_grafic_file_list.append(_grafic_file_path_lu) 1448 _tested_grafic_file_list.append(_grafic_file_path_lu)
1441 elif os.path.exists(_grafic_file_path_ll): 1449 elif os.path.exists(_grafic_file_path_ll):
1442 _tested_grafic_file_list.append(_grafic_file_path_ll) 1450 _tested_grafic_file_list.append(_grafic_file_path_ll)
1443 else: 1451 else:
1444 print utils.mapping(_("The file $1 do not exist"), 1452 print(utils.mapping(_("The file $1 do not exist"),
1445 (_grafic_file_path,)) 1453 (_grafic_file_path.decode("utf8"),)) )
1446 if len(_grafic_file_list) > 0: 1454 if len(_grafic_file_list) > 0:
1447 for _grafic_file in _tested_grafic_file_list: 1455 for _grafic_file in _tested_grafic_file_list:
1448 self.__budget.addFile(_record_code.encode("utf8"), _grafic_file, "img", "") 1456 self.__budget.addFile(_record_code.encode("utf8"), _grafic_file, "img", "")
1449 self.__statistics.valid = self.__statistics.valid +1 1457 self.__statistics.valid = self.__statistics.valid +1
1450 1458
1451 def _parseE(self, field_list): 1459 def _parseE(self, field_list):
1452 """_parseE(self, field_list) 1460 """_parseE(field_list)
1453 1461
1454 field_list: field list of the record 1462 field_list: field list of the record
1455 0- E: Company 1463 0- E: Company
1456 1- company Code 1464 1- company Code
1457 2 [ summary ] 1465 2 [ summary ]
1546 _local_offices, _cif.encode("utf8"), 1554 _local_offices, _cif.encode("utf8"),
1547 _web.encode("utf8"), _email.encode("utf8")) 1555 _web.encode("utf8"), _email.encode("utf8"))
1548 self.__statistics.valid = self.__statistics.valid +1 1556 self.__statistics.valid = self.__statistics.valid +1
1549 1557
1550 def _parseX(self, field_list): 1558 def _parseX(self, field_list):
1551 """_parseX(self, field_list) 1559 """_parseX(field_list)
1552 1560
1553 field_list: field list of the record 1561 field_list: field list of the record
1554 A) 1562 A)
1555 0- X: Tecnical information 1563 0- X: Tecnical information
1556 1- Empty 1564 1- Empty
1601 _ti_index = _ti_index + 2 1609 _ti_index = _ti_index + 2
1602 self.__budget.setTecnicalInformation(_record_code.encode("utf8"), _ti_dict) 1610 self.__budget.setTecnicalInformation(_record_code.encode("utf8"), _ti_dict)
1603 self.__statistics.valid = self.__statistics.valid +1 1611 self.__statistics.valid = self.__statistics.valid +1
1604 1612
1605 def _parseF(self, field_list): 1613 def _parseF(self, field_list):
1606 """_parseF(self, field_list) 1614 """_parseF(field_list)
1607 1615
1608 field_list: field list of the record 1616 field_list: field list of the record
1609 0- F: Files 1617 0- F: Files
1610 1- Record code 1618 1- Record code
1611 2- { Type \ { Filenames; } \ [Description] } 1619 2- { Type \ { Filenames; } \ [Description] }
1612 """ 1620 """
1613 1621 print("parseF")
1622 print(field_list)
1614 # _____Number of fields_____ 1623 # _____Number of fields_____
1615 # The record must have at least 3 fields 1624 # The record must have at least 3 fields
1616 if len(field_list) < 3: 1625 if len(field_list) < 3:
1617 return 1626 return
1618 # Any INFORMATION after last field separator is ignored 1627 # Any INFORMATION after last field separator is ignored
1636 # adding empty subfiels if necesary 1645 # adding empty subfiels if necesary
1637 if len(_files_list)%3 > 0: 1646 if len(_files_list)%3 > 0:
1638 _files_list.extend[u""]*(3 - len(_files_list)%3) 1647 _files_list.extend[u""]*(3 - len(_files_list)%3)
1639 _file_index = 0 1648 _file_index = 0
1640 _tested_files_list = [] 1649 _tested_files_list = []
1650 print(_files_list)
1641 while _file_index < len(_files_list)-3: 1651 while _file_index < len(_files_list)-3:
1642 _type = _files_list[_file_index].replace(u" ",u"") 1652 _type = _files_list[_file_index].replace(u" ",u"")
1643 ## _types = { 1653 ## _types = {
1644 ## "0": _("others"), 1654 ## "0": _("others"),
1645 ## "1": _("características técnicas y de fabricación"), 1655 ## "1": _("características técnicas y de fabricación"),
1646 ## "2": _("manual de colocación, uso y mantenimiento"), 1656 ## "2": _("manual de colocación, uso y mantenimiento"),
1647 ## "3": _("certificado/s de elementos y sistemas"), 1657 ## "3": _("certificado/s de elementos y sistemas"),
1648 ## "4": _("normativa y bibliografía"), 1658 ## "4": _("normativa y bibliografía"),
1649 ## "5": _("tarifa de precios"), 1659 ## "5": _("tarifa de precios"),
1650 ## "6": _("condiciones de venta"), 1660 ## "6": _("condiciones de venta"),
1651 ## "7": _("carta de colores"), 1661 ## "7": _("carta de colores"),
1652 ## "8": _("ámbito de aplicación y criterios selección"), 1662 ## "8": _("ámbito de aplicación y criterios selección"),
1653 ## "9": _("cálculo de elementos y sistemas"), 1663 ## "9": _("cálculo de elementos y sistemas"),
1654 ## "10": _("presentación, datos generales, objetivos, etc. de "\ 1664 ## "10": _("presentación, datos generales, objetivos, " \
1655 ## "empresa"), 1665 ## "etc. de empresa"),
1656 ## "11": _("certificado/s de empresa"), 1666 ## "11": _("certificado/s de empresa"),
1657 ## "12": _("obras realizadas")} 1667 ## "12": _("obras realizadas")}
1658 _types = [u"0", u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10", 1668 _types = [u"0", u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10",
1659 u"11", u"12"] 1669 u"11", u"12"]
1660 if not _type in _types: 1670 if not _type in _types:
1661 _type = u"0" 1671 _type = u"0"
1662 _filenames = _files_list[_file_index + 1] 1672 _filenames = _files_list[_file_index + 1]
1663 _description = _files_list[_file_index + 2] 1673 _description = _files_list[_file_index + 2]
1664 _file_index += 3 1674 _file_index += 3
1675 print(u"type: " + _type)
1676 print(u"filenames: " + _filenames)
1677 print(u"_description: " + _description)
1665 if len(_filenames) and _filenames[-1] == u";": 1678 if len(_filenames) and _filenames[-1] == u";":
1666 _files = _files[:-1] 1679 _files = _files[:-1]
1667 _filenames_list = _files.split(u";") 1680 _filenames_list = _filenames.split(u";")
1681
1668 _path = os.path.dirname(self.__filename) 1682 _path = os.path.dirname(self.__filename)
1669 for _filename in filenames_list: 1683 for _filename in _filenames_list:
1670 _file_path = os.path.join(_path, _filename.encode("utf8")) 1684 _file_path = os.path.join(_path, _filename.encode("utf8"))
1671 if os.path.exists(_file_path): 1685 if os.path.exists(_file_path):
1672 _tested_files_list.append([_file_path, _type.encode("utf8"), 1686 _tested_files_list.append([_file_path, _type.encode("utf8"),
1673 _description.encode("utf8")]) 1687 _description.encode("utf8")])
1674 else: 1688 else:
1698 _description.encode("utf8")]) 1712 _description.encode("utf8")])
1699 elif os.path.exists(_grafic_file_path_ll): 1713 elif os.path.exists(_grafic_file_path_ll):
1700 _tested_files_list.append([_file_path_ll, _type.encode("utf8"), 1714 _tested_files_list.append([_file_path_ll, _type.encode("utf8"),
1701 _description.encode("utf8")]) 1715 _description.encode("utf8")])
1702 else: 1716 else:
1703 print utils.mapping(_("The file $1 do not exist"), 1717 print(utils.mapping(_("The file $1 do not exist"),
1704 (_file_path,)) 1718 (_file_path,)) )
1705 if len(_tested_files_list) > 0: 1719 if len(_tested_files_list) > 0:
1706 for _file in _tested_file_list: 1720 for _file in _tested_files_list:
1707 self.__budget.addFile(_record_code.encode("utf8"), _file[0], file[1], file[2]) 1721 self.__budget.addFile(_record_code.encode("utf8"), _file[0], _file[1], _file[2])
1708 self.__statistics.valid = self.__statistics.valid +1 1722 self.__statistics.valid = self.__statistics.valid +1
1709 1723
1710 def _parseB(self, field_list): 1724 def _parseB(self, field_list):
1711 """_parseB(self, field_list) 1725 """_parseB(field_list)
1712 1726
1713 field_list: field list of the record 1727 field_list: field list of the record
1714 0- B: Change code 1728 0- B: Change code
1715 1- Record Code 1729 1- Record Code
1716 2- New code 1730 2- New code
1735 # change code 1749 # change code
1736 self.__budget.changeCode(_code, _new_code) 1750 self.__budget.changeCode(_code, _new_code)
1737 self.__statistics.valid = self.__statistics.valid + 1 1751 self.__statistics.valid = self.__statistics.valid + 1
1738 1752
1739 def _parseA(self, field_list): 1753 def _parseA(self, field_list):
1740 """_parseA(self, field_list) 1754 """_parseA(field_list)
1741 1755
1742 field_list: field list of the record 1756 field_list: field list of the record
1743 0- A: Labels 1757 0- A: Labels
1744 1- Record Code 1758 1- Record Code
1745 2- <Label\> 1759 2- <Label\>
1772 for _label in _label_list: 1786 for _label in _label_list:
1773 self.__budget.addLabel(_code.encode("utf8"), _label.encode("utf8")) 1787 self.__budget.addLabel(_code.encode("utf8"), _label.encode("utf8"))
1774 self.__statistics.valid = self.__statistics.valid + 1 1788 self.__statistics.valid = self.__statistics.valid + 1
1775 1789
1776 def _parseP(self, field_list): 1790 def _parseP(self, field_list):
1777 """_parseP(self, field_list) 1791 """_parseP(field_list)
1778 1792
1779 field_list: Parametric record 1793 field_list: Parametric record
1780 A) Global paremetric record 1794 A) Global paremetric record
1781 0- P: Parametric 1795 0- P: Parametric
1782 1- Empty 1796 1- Empty
1804 # The record must have 3 fields 1818 # The record must have 3 fields
1805 if len(field_list) > 3: 1819 if len(field_list) > 3:
1806 field_list = field_list[0:3] 1820 field_list = field_list[0:3]
1807 field_list = field_list[1:] 1821 field_list = field_list[1:]
1808 if len(field_list) != 2: 1822 if len(field_list) != 2:
1809 print _("PyArq hates parametric DLLs") 1823 print(_("PyArq hates parametric DLLs") )
1810 return 1824 return
1811 else: 1825 else:
1812 return 1826 return
1813 # _____Description_____ 1827 # _____Description_____
1814 _description = field_list[1] 1828 _description = field_list[1]
1815 if _description == u"": 1829 if _description == u"":
1816 print _("PyArq hates parametric DLLs") 1830 print(_("PyArq hates parametric DLLs") )
1817 return 1831 return
1818 # Adding last end of line 1832 # Adding last end of line
1819 _description = _description + u"\r\n" 1833 _description = _description + u"\r\n"
1820 # Delete comments 1834 # Delete comments
1821 # "comment" : "#.*\r\n" 1835 # "comment" : "#.*\r\n"
1876 _line = _final_line[1:] 1890 _line = _final_line[1:]
1877 _lines[index] = _line 1891 _lines[index] = _line
1878 # parse data 1892 # parse data
1879 if len(_line) > 2 and _line[:2] == u"::": 1893 if len(_line) > 2 and _line[:2] == u"::":
1880 # Delete spaces out " delimiter 1894 # Delete spaces out " delimiter
1881 #print "__PRECIO__" + _line[2:] 1895 #print("__PRECIO__" + _line[2:])
1882 pass 1896 pass
1883 elif len(_line) > 2 and _line[:2] == u"%:": 1897 elif len(_line) > 2 and _line[:2] == u"%:":
1884 # Delete spaces out " delimiter 1898 # Delete spaces out " delimiter
1885 #print "__%AUX__" + _line[2:] 1899 #print("__%AUX__" + _line[2:])
1886 pass 1900 pass
1887 elif len(_line) > 3 and _line[:2] == u"%%:": 1901 elif len(_line) > 3 and _line[:2] == u"%%:":
1888 # Delete spaces out " delimiter 1902 # Delete spaces out " delimiter
1889 #print "__%%AUX__" + _line[2:] 1903 #print("__%%AUX__" + _line[2:] )
1890 pass 1904 pass
1891 elif self.__pattern["var"].search(_line): 1905 elif self.__pattern["var"].search(_line):
1892 # Delete spaces out " delimiter 1906 # Delete spaces out " delimiter
1893 #print "line =", _line 1907 #print( "line =", _line )
1894 while _line.count(u'"') % 2 == 1 and \ 1908 while _line.count(u'"') % 2 == 1 and \
1895 index + _pass_line + 1 < len(_lines) -1: 1909 index + _pass_line + 1 < len(_lines) -1:
1896 _line = _line + _lines[index + _pass_line + 1] 1910 _line = _line + _lines[index + _pass_line + 1]
1897 _pass_line = _pass_line + 1 1911 _pass_line = _pass_line + 1
1898 _search = self.__pattern["var"].search(_line) 1912 _search = self.__pattern["var"].search(_line)
1899 if _search is not None: 1913 if _search is not None:
1900 _var = _search.groups()[0] + u" = " + _search.groups()[1] 1914 _var = _search.groups()[0] + u" = " + _search.groups()[1]
1901 #print "__VAR__" + str(_var) 1915 #print("__VAR__" + str(_var) )
1902 pass 1916 pass
1903 else: 1917 else:
1904 #print "no __VAR__", _line 1918 #print( "no __VAR__", _line )
1905 pass 1919 pass
1906 elif self.__pattern["descomposition"].search(_line): 1920 elif self.__pattern["descomposition"].search(_line):
1907 # Delete spaces out " delimiter 1921 # Delete spaces out " delimiter
1908 #_patern = "(^[^:]*):(.*)$" 1922 #_patern = "(^[^:]*):(.*)$"
1909 _search = self.__pattern["descomposition"].search(_line) 1923 _search = self.__pattern["descomposition"].search(_line)
1910 if _search is not None: 1924 if _search is not None:
1911 _var = _search.groups()[0] + u":" + _search.groups()[1] 1925 _var = _search.groups()[0] + u":" + _search.groups()[1]
1912 #print "__Descomposición__" + str(_var) 1926 #print( "__Descomposición__" + str(_var) )
1913 pass 1927 pass
1914 else: 1928 else:
1915 #print "no __Descomposición__", _line 1929 #print("no __Descomposición__", _line )
1916 pass 1930 pass
1917 else: 1931 else:
1918 print "Parametric: code: " + _family_code.encode("utf8") 1932 print("Parametric: code: " + _family_code.encode("utf8") )
1919 print "******* Desconocido *** : " + _line 1933 print("******* Desconocido *** : " + _line )
1920 if index-10 > 0: print "-11 :", _lines[index-11].encode("utf8") 1934 if index-10 > 0: print("-11 : " + _lines[index-11].encode("utf8") )
1921 if index-10 > 0: print "-10 :", _lines[index-10].encode("utf8") 1935 if index-10 > 0: print("-10 : " + _lines[index-10].encode("utf8") )
1922 if index-9 > 0: print "-9 :", _lines[index-9].encode("utf8") 1936 if index-9 > 0: print("-9 : " + _lines[index-9].encode("utf8") )
1923 if index-8 > 0: print "-8 :", _lines[index-8].encode("utf8") 1937 if index-8 > 0: print("-8 : " + _lines[index-8].encode("utf8") )
1924 if index-7 > 0: print "-7 :", _lines[index-7].encode("utf8") 1938 if index-7 > 0: print("-7 : " + _lines[index-7].encode("utf8") )
1925 if index-6 > 0: print "-6 :", _lines[index-6].encode("utf8") 1939 if index-6 > 0: print("-6 : " + _lines[index-6].encode("utf8") )
1926 if index-5 > 0: print "-5 :", _lines[index-5].encode("utf8") 1940 if index-5 > 0: print("-5 : " + _lines[index-5].encode("utf8") )
1927 if index-4 > 0: print "-4 :", _lines[index-4].encode("utf8") 1941 if index-4 > 0: print("-4 : " + _lines[index-4].encode("utf8") )
1928 if index-3 > 0: print "-3 :", _lines[index-3].encode("utf8") 1942 if index-3 > 0: print("-3 : " + _lines[index-3].encode("utf8") )
1929 if index-2 > 0: print "-2 :", _lines[index-2].encode("utf8") 1943 if index-2 > 0: print("-2 : " + _lines[index-2].encode("utf8") )
1930 if index-1 > 0: print "-1 :", _lines[index-1].encode("utf8") 1944 if index-1 > 0: print("-1 : " + _lines[index-1].encode("utf8") )
1931 print "-0 :", _lines[index-0] 1945 print("-0 :" + _lines[index-0] )
1932 pass 1946 pass
1933 else: 1947 else:
1934 _parameter_list = _line.split(u"\\")[1:-1] 1948 _parameter_list = _line.split(u"\\")[1:-1]
1935 if len(_parameter_list) >= 2: 1949 if len(_parameter_list) >= 2:
1936 if _parameter_list[0] == u"C" or \ 1950 if _parameter_list[0] == u"C" or \
1937 _parameter_list[0] == u"COMENTARIO": 1951 _parameter_list[0] == u"COMENTARIO":
1938 #print "__COMENTARIO__" + _parameter_list[1] 1952 #print( "__COMENTARIO__" + _parameter_list[1])
1939 self.__budget.setParametricSelectComment( 1953 self.__budget.setParametricSelectComment(
1940 _family_code.encode("utf8"), _parameter_list[1].encode("utf8")) 1954 _family_code.encode("utf8"), _parameter_list[1].encode("utf8"))
1941 elif _parameter_list[0] == u"R" or \ 1955 elif _parameter_list[0] == u"R" or \
1942 _parameter_list[0] == u"RESUMEN": 1956 _parameter_list[0] == u"RESUMEN":
1943 #print "__RESUMEN__" + _parameter_list[1] 1957 #print( "__RESUMEN__" + _parameter_list[1])
1944 self.__budget.setParametricSummary(_family_code.encode("utf8"), 1958 self.__budget.setParametricSummary(_family_code.encode("utf8"),
1945 _parameter_list[1].encode("utf8")) 1959 _parameter_list[1].encode("utf8"))
1946 elif _parameter_list[0] == u"T" or \ 1960 elif _parameter_list[0] == u"T" or \
1947 _parameter_list[0] == u"TEXTO": 1961 _parameter_list[0] == u"TEXTO":
1948 #print "__TEXTO__" + _parameter_list[1] 1962 #print( "__TEXTO__" + _parameter_list[1])
1949 self.__budget.setParametricText(_family_code.encode("utf8"), 1963 self.__budget.setParametricText(_family_code.encode("utf8"),
1950 _parameter_list[1].encode("utf8")) 1964 _parameter_list[1].encode("utf8"))
1951 elif _parameter_list[0] == u"P" or \ 1965 elif _parameter_list[0] == u"P" or \
1952 _parameter_list[0] == u"PLIEGO": 1966 _parameter_list[0] == u"PLIEGO":
1953 #print "__PLIEGO__" + str(_parameter_list[1:]) 1967 #print( "__PLIEGO__" + str(_parameter_list[1:]) )
1954 pass 1968 pass
1955 elif _parameter_list[0] == u"K" or \ 1969 elif _parameter_list[0] == u"K" or \
1956 _parameter_list[0] == u"CLAVES": 1970 _parameter_list[0] == u"CLAVES":
1957 #print "__CLAVES__" + str(_parameter_list[1:]) 1971 #print( "__CLAVES__" + str(_parameter_list[1:]) )
1958 pass 1972 pass
1959 elif _parameter_list[0] == u"F" or \ 1973 elif _parameter_list[0] == u"F" or \
1960 _parameter_list[0] == u"COMERCIAL": 1974 _parameter_list[0] == u"COMERCIAL":
1961 #print "__COMERCIAL__" + str(_parameter_list[1:]) 1975 #print( "__COMERCIAL__" + str(_parameter_list[1:]) )
1962 pass 1976 pass
1963 else: 1977 else:
1964 #print "==PARAMETRO==" + str(_parameter_list[:]) 1978 #print( "==PARAMETRO==" + str(_parameter_list[:]) )
1965 pass 1979 pass
1966 _final_description = _final_description + _line + u"\r\n" 1980 _final_description = _final_description + _line + u"\r\n"
1967 1981
1968 #print _line 1982 #print( _line )
1969 # Delete last empty line 1983 # Delete last empty line
1970 _description = _final_description[:-2] 1984 _description = _final_description[:-2]
1971 _lines = _description.split(u"\r\n") 1985 _lines = _description.split(u"\r\n")
1972 for _line in _lines: 1986 for _line in _lines:
1973 pass 1987 pass
1974 #print _line 1988 #print( _line )
1975 self.__statistics.valid = self.__statistics.valid + 1 1989 self.__statistics.valid = self.__statistics.valid + 1
1976 1990
1977 def readFile(self, budget=None, filename=None, interface=None): 1991 def readFile(self, budget=None, filename=None, interface=None):
1978 """readFile(self, budget=None, filename=None) 1992 """readFile(budget=None, filename=None)
1979 1993
1980 filename: the filename of the fiebdc file 1994 filename: the filename of the fiebdc file
1981 budget: base.obra object 1995 budget: base.obra object
1982 interface: a object to send messages 1996 interface: a object to send messages
1983 must have readFile_send_message(message) 1997 must have readFile_send_message(message)
1984 readFile_set_statistics(statistics) 1998 readFile_set_statistics(statistics)
1985 readFile_progress(percent) 1999 readFile_progress(percent)
1986 readFile_end() 2000 readFile_end()
1987 readFile_cancel() 2001 readFile_cancel()
1988 Return the budget objetc or None if the file can be readed 2002 updateGui()
2003 Return None
1989 """ 2004 """
1990 if not filename is None and not budget is None: 2005 if not filename is None and not budget is None:
1991 self.__filename = filename 2006 self.__filename = filename
1992 self.__budget = budget 2007 self.__budget = budget
1993 self.__budget.filename = self.__filename 2008 self.__budget.filename = self.__filename
2000 interface.readFile_set_statistics(self.__statistics) 2015 interface.readFile_set_statistics(self.__statistics)
2001 _time = time.time() 2016 _time = time.time()
2002 try: 2017 try:
2003 _file = open(self.__filename, 'r') 2018 _file = open(self.__filename, 'r')
2004 except IOError: 2019 except IOError:
2005 print utils.mapping("IOError: $1", (self.__filename,)) 2020 print( utils.mapping("IOError: $1", (self.__filename,)) )
2021 return None
2022 _filesize = float(os.path.getsize(self.__filename))
2023 if _filesize == 0.0:
2024 print( utils.mapping("Empty File: $1", (self.__filename,)) )
2025 # Todo: Create empty budget
2006 return None 2026 return None
2007 self.__budget.filename = self.__filename 2027 self.__budget.filename = self.__filename
2008 interface.readFile_send_message(utils.mapping(_("Loading file $1"), 2028 interface.readFile_send_message(utils.mapping(_("Loading file $1"),
2009 (self.__filename,))) 2029 (self.__filename,)))
2010 _filesize = float(os.path.getsize(self.__filename))
2011 interface.readFile_progress(_file.tell() / _filesize) 2030 interface.readFile_progress(_file.tell() / _filesize)
2012 _buffer = _file.read(1000) 2031 _buffer = _file.read(1000)
2032 interface.updateGui()
2013 # set codepage from V record 2033 # set codepage from V record
2014 _record_list = _buffer.split("~") 2034 _record_list = _buffer.split("~")
2015 registro_V = _record_list[1] 2035 registro_V = _record_list[1]
2016 # ~V|[PROPIEDAD_ARCHIVO]|VERSION_FORMATO[\DDMMAAAA]|[PROGRAMA_EMISION]| 2036 # ~V|[PROPIEDAD_ARCHIVO]|VERSION_FORMATO[\DDMMAAAA]|[PROGRAMA_EMISION]|
2017 # [CABECERA]\{ ROTULO_IDENTIFICACION \}|[JUEGO_CARACTERES]| 2037 # [CABECERA]\{ ROTULO_IDENTIFICACION \}|[JUEGO_CARACTERES]|
2041 else: 2061 else:
2042 interface.readFile_send_message(utils.mapping(_( 2062 interface.readFile_send_message(utils.mapping(_(
2043 "Not 'V' record in File! Default character encoding: "\ 2063 "Not 'V' record in File! Default character encoding: "\
2044 "$1"), (self.__character_set,))) 2064 "$1"), (self.__character_set,)))
2045 _buffer = unicode(_buffer, self.__character_set) 2065 _buffer = unicode(_buffer, self.__character_set)
2066 interface.updateGui()
2046 # Any INFORMATION between the beginning of the file and the 2067 # Any INFORMATION between the beginning of the file and the
2047 # beginning of the first registry “~” is ignored 2068 # beginning of the first registry “~” is ignored
2048 #"after_first_tilde" : "^[^~]*~" 2069 #"after_first_tilde" : "^[^~]*~"
2049 _buffer = self.__pattern["after_first_tilde"].sub("",_buffer) 2070 _buffer = self.__pattern["after_first_tilde"].sub("",_buffer)
2050 while _buffer != u"" and not self.__cancel: 2071 while _buffer != u"" and not self.__cancel:
2054 # the record ~P 2075 # the record ~P
2055 _buffer = self.eraseControlCharacters(_buffer) 2076 _buffer = self.eraseControlCharacters(_buffer)
2056 _record_list = _buffer.split(u"~") 2077 _record_list = _buffer.split(u"~")
2057 # The last record can be incomplete unless it is the last one of 2078 # The last record can be incomplete unless it is the last one of
2058 # the file 2079 # the file
2059 if len(_record_list) > 1: 2080 #if len(_record_list) > 1:
2081 if (_file.tell() / _filesize) != 1.0:
2060 # not the end 2082 # not the end
2061 _last_record = _record_list.pop() 2083 _last_record = _record_list.pop()
2062 else: 2084 else:
2063 # the end record 2085 # The last record
2064 # The blank characters (32), tabs (9) and end of line 2086 # The blank characters (32), tabs (9) and end of line
2065 # (13 and 10) at the end of the file are ignored. 2087 # (13 and 10) at the end of the file are ignored.
2066 #"end_control" : "((\r\n)| |\t)+$" 2088 #"end_control" : "((\r\n)| |\t)+$"
2067 _record_list[-1] = self.__pattern["end_control"].sub(u"", 2089 _record_list[-1] = self.__pattern["end_control"].sub(u"",
2068 _record_list[-1]) 2090 _record_list[-1])
2069 _last_record = u"" 2091 _last_record = u""
2070 for record in _record_list: 2092 for record in _record_list:
2071 if self.__cancel: 2093 if self.__cancel:
2072 break 2094 break
2073 self.parseRecord(record) 2095 self.parseRecord(record, interface)
2096 interface.updateGui()
2074 interface.readFile_progress(_file.tell() / _filesize) 2097 interface.readFile_progress(_file.tell() / _filesize)
2075 _buffer2 = _file.read(100000) 2098 _buffer2 = _file.read(100000)
2099 interface.updateGui()
2076 _buffer2 = unicode(_buffer2, self.__character_set) 2100 _buffer2 = unicode(_buffer2, self.__character_set)
2077 _buffer = _last_record + _buffer2 2101 _buffer = _last_record + _buffer2
2102 interface.updateGui()
2078 _file.close() 2103 _file.close()
2079 if self.__cancel: 2104 if self.__cancel:
2080 interface.readFile_cancel() 2105 interface.readFile_cancel()
2081 return None 2106 return None
2082 else: 2107 else:
2083 self.__statistics.time = time.time()-_time 2108 self.__statistics.time = time.time()-_time
2084 if self.__statistics.O > 0: 2109 if self.__statistics.O > 0:
2085 interface.readFile_send_message( 2110 interface.readFile_send_message(
2086 utils.mapping(_("$1 unsuported record type O: "\ 2111 utils.mapping(_("$1 unsuported record type O: "\
2087 "Comercial Relationship"), (self.__statistics.O,))) 2112 "Comercial Relationship"), (str(self.__statistics.O,))))
2088 if self.__statistics.valid == 0: 2113 if self.__statistics.valid == 0:
2089 interface.readFile_send_message(_("This file is not a valid FIBDC3 file")) 2114 interface.readFile_send_message(_("This file is not a valid FIBDC3 file"))
2090 return None 2115 return None
2091 interface.readFile_end() 2116 interface.readFile_end()
2092 self._testBudget(self.__budget) 2117 self._testBudget(self.__budget, interface)
2093 return self.__budget 2118 return None
2094 2119
2095 def _testBudget(self, budget): 2120 def _testBudget(self, budget, interface):
2096 """testBudget(self,budget) 2121 """testBudget(budget)
2097 2122
2098 budget: base.obra object 2123 budget: base.obra object
2099 Test and repair budget object after read it from bc3 file 2124 Test and repair budget object after read it from bc3 file
2100 """ 2125 """
2101 # TODO: more to do here 2126 # TODO: more to do here
2102 print _("Testing budget ...") 2127 print( _("Testing budget ...") )
2103 # Add price to records without price 2128 # Add price to records without price
2104 _iter = budget.iter() 2129 _iter = budget.iter()
2105 _titlelist = budget.getTitleList()[1] 2130 _titlelist = budget.getTitleList()[1]
2106 if len(_titlelist) == 0: 2131 if len(_titlelist) == 0:
2107 _titlenum = 1 2132 _titlenum = 1
2115 _leftprices = _titlenum - _len_prices 2140 _leftprices = _titlenum - _len_prices
2116 for _index in range(0,_leftprices): 2141 for _index in range(0,_leftprices):
2117 _root = budget.getRecord(budget.getRoot()) 2142 _root = budget.getRecord(budget.getRoot())
2118 _price = [0.0, _root.getDate(_len_prices + _index)] 2143 _price = [0.0, _root.getDate(_len_prices + _index)]
2119 budget.addPriceToRecord(_price,_record) 2144 budget.addPriceToRecord(_price,_record)
2120 print _("End Test") 2145 interface.updateGui()
2146 print( _("End Test") )
2121 2147
2122 def delete_control_space(self, text): 2148 def delete_control_space(self, text):
2123 text = self.delete_control(text) 2149 text = self.delete_control(text)
2124 text = text.replace(u" ", u"") 2150 text = text.replace(u" ", u"")
2125 return text 2151 return text
2139 fiebdc.Interface() 2165 fiebdc.Interface()
2140 Ancestry: 2166 Ancestry:
2141 +-- object 2167 +-- object
2142 +-- Interface 2168 +-- Interface
2143 Atributes: 2169 Atributes:
2170 "endSuccessfully": True/False
2144 "__progress": The progress percentage 2171 "__progress": The progress percentage
2145 "__statistics": The record statistics 2172 "__statistics": The record statistics
2146 Methods: 2173 Methods:
2147 __init__(self) 2174 __init__(self)
2148 readFile_send_message(message) 2175 readFile_send_message(message)
2149 readFile_progress(percent) 2176 readFile_progress(percent)
2150 readFile_set_statistics(statistics) 2177 readFile_set_statistics(statistics)
2151 readFile_end() 2178 readFile_end()
2152 readFile_cancel() 2179 readFile_cancel()
2180 updateGui()
2153 2181
2154 """ 2182 """
2155 def __init__(self): 2183 def __init__(self):
2156 self.__progress = 0.0 2184 self.__progress = 0.0
2157 self.__statistics = Statistics() 2185 self.__statistics = Statistics()
2186 self.endSuccessfully = False
2158 2187
2159 def readFile_set_statistics(self, statistics): 2188 def readFile_set_statistics(self, statistics):
2160 """readFile_set_statistics(statistics) 2189 """readFile_set_statistics(statistics)
2161 2190
2162 statistics: record statistics from readFile method 2191 statistics: record statistics from readFile method
2168 def readFile_send_message(self, message): 2197 def readFile_send_message(self, message):
2169 """readFile_send_message(message) 2198 """readFile_send_message(message)
2170 2199
2171 message: mesage from readFile method 2200 message: mesage from readFile method
2172 2201
2173 print message 2202 print( message )
2174 """ 2203 """
2175 print message 2204 print( message )
2176 2205
2177 def readFile_progress(self, percent): 2206 def readFile_progress(self, percent):
2178 """progress(percent) 2207 """progress(percent)
2179 2208
2180 percent: Percentage executed. 2209 percent: Percentage executed.
2186 def readFile_end(self): 2215 def readFile_end(self):
2187 """readFile_end() 2216 """readFile_end()
2188 2217
2189 The readFile method end successfully 2218 The readFile method end successfully
2190 """ 2219 """
2191 print self.__statistics 2220 self.endSuccessfully == True
2221 print(self.__statistics)
2222 print("progreso = " + str(self.__progress))
2192 2223
2193 def readFile_cancel(self): 2224 def readFile_cancel(self):
2194 """readFile_cancel() 2225 """readFile_cancel()
2195 2226
2196 The readFile method is canceled 2227 The readFile method is canceled
2197 """ 2228 """
2198 print _("Process terminated") 2229 self.endSuccessfully == False
2230 print( _("Process terminated") )
2231 print("progreso = " + str(self.__progress))
2232
2233 def updateGui(self):
2234 """updateGui(self)
2235
2236 Some interfaces need update gui while doing some time intensive
2237 computation. Do it here.
2238 """
2239 pass
2199 2240
2200 class Statistics(object): 2241 class Statistics(object):
2201 """fiebdc.Statistics 2242 """fiebdc.Statistics
2202 2243
2203 Description: 2244 Description:
2262 self.A = 0 2303 self.A = 0
2263 self.unknow = 0 2304 self.unknow = 0
2264 self.time = 0.0 2305 self.time = 0.0
2265 2306
2266 def __str__(self): 2307 def __str__(self):
2308 return self.str().encode("utf8")
2309
2310 def str(self):
2311
2267 return utils.mapping(_("Time to load: $1 seconds"), 2312 return utils.mapping(_("Time to load: $1 seconds"),
2268 (("%.2f" %(self.time)),)) + "\n" + \ 2313 (("%.2f" %(self.time)),)) + "\n" + \
2269 utils.mapping(_("Records/Valid Records: $1/$2"), 2314 utils.mapping(_("Records/Valid Records: $1/$2"),
2270 (self.records, self.valid)) + "\n" +\ 2315 (str(self.records), str(self.valid))) + "\n" +\
2271 "V: %s\n" %(self.V,) + \ 2316 "V: %s\n" %(self.V,) + \
2272 "C: %s\n" %(self.C,) + \ 2317 "C: %s\n" %(self.C,) + \
2273 "D: %s\n" %(self.D,) + \ 2318 "D: %s\n" %(self.D,) + \
2274 "Y: %s\n" %(self.Y,) + \ 2319 "Y: %s\n" %(self.Y,) + \
2275 "M: %s\n" %(self.M,) + \ 2320 "M: %s\n" %(self.M,) + \