comparison Generic/fiebdc.py @ 5:6502bfdaa84d

update import durus database
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Sat, 06 Nov 2010 21:30:33 +0100
parents 2ac1551ad2ab
children 2fc6b47dbe70
comparison
equal deleted inserted replaced
4:4e976a99efb9 5:6502bfdaa84d
1936 interface: a object to send messages 1936 interface: a object to send messages
1937 must have printf(message) progress(percent) 1937 must have printf(message) progress(percent)
1938 recordStatistics(...) 1938 recordStatistics(...)
1939 Return the budget objetc or None if the file can be readed 1939 Return the budget objetc or None if the file can be readed
1940 """ 1940 """
1941 if filename != None and budget != None: 1941 if not filename is None and not budget is None:
1942 self.__filename = filename 1942 self.__filename = filename
1943 self.__budget = budget 1943 self.__budget = budget
1944 self.__budget.filename = self.__filename 1944 self.__budget.filename = self.__filename
1945 if self.__filename is None or self.__budget is None or \ 1945 if self.__filename is None or self.__budget is None or self.__cancel:
1946 self.__cancel == True:
1947 return None 1946 return None
1948 if not os.path.exists(self.__filename): 1947 if not os.path.exists(self.__filename):
1949 return None 1948 return None
1950 _time = time.time() 1949 _time = time.time()
1951 try: 1950 try:
2012 _buffer = _buffer.encode("utf8") 2011 _buffer = _buffer.encode("utf8")
2013 # Any INFORMATION between the beginning of the file and the 2012 # Any INFORMATION between the beginning of the file and the
2014 # beginning of the first registry “~” is ignored 2013 # beginning of the first registry “~” is ignored
2015 #"after_first_tilde" : "^[^~]*~" 2014 #"after_first_tilde" : "^[^~]*~"
2016 _buffer = self.__pattern["after_first_tilde"].sub("",_buffer) 2015 _buffer = self.__pattern["after_first_tilde"].sub("",_buffer)
2017 while _buffer != "" and self.__cancel != True: 2016 while _buffer != "" and not self.__cancel:
2018 #-# the blank characters (32), tabs (9) and end of line (13 and 10) 2017 #-# the blank characters (32), tabs (9) and end of line (13 and 10)
2019 # before the separators '~', '|' are erased. 2018 # before the separators '~', '|' are erased.
2020 # Before separator \ not deleted because it affects the reading of 2019 # Before separator \ not deleted because it affects the reading of
2021 # the record ~P 2020 # the record ~P
2022 _buffer = self.eraseControlCharacters(_buffer) 2021 _buffer = self.eraseControlCharacters(_buffer)
2033 #"end_control" : "((\r\n)| |\t)+$" 2032 #"end_control" : "((\r\n)| |\t)+$"
2034 _record_list[-1] = self.__pattern["end_control"].sub("", 2033 _record_list[-1] = self.__pattern["end_control"].sub("",
2035 _record_list[-1]) 2034 _record_list[-1])
2036 _last_record = "" 2035 _last_record = ""
2037 for record in _record_list: 2036 for record in _record_list:
2038 if self.__cancel == True: 2037 if self.__cancel:
2039 break 2038 break
2040 self.parseRecord(record) 2039 self.parseRecord(record)
2041 interface.progress(_file.tell() / _filesize) 2040 interface.progress(_file.tell() / _filesize)
2042 _buffer2 = _file.read(100000) 2041 _buffer2 = _file.read(100000)
2043 if self.__character_set != "utf8": 2042 if self.__character_set != "utf8":
2044 _buffer2 = unicode(_buffer2, self.__character_set) 2043 _buffer2 = unicode(_buffer2, self.__character_set)
2045 _buffer2 = _buffer2.encode("utf8") 2044 _buffer2 = _buffer2.encode("utf8")
2046 _buffer = _last_record + _buffer2 2045 _buffer = _last_record + _buffer2
2047 _file.close() 2046 _file.close()
2048 if self.__cancel == True: 2047 if self.__cancel:
2049 print _("Cancelled process") 2048 print _("Cancelled process")
2050 return None 2049 return None
2051 else: 2050 else:
2052 print utils.mapping(_("Time to load: $1 seconds"), 2051 print utils.mapping(_("Time to load: $1 seconds"),
2053 (("%.2f" %(time.time()-_time)),)) 2052 (("%.2f" %(time.time()-_time)),))