def set_source(self, name): IP.set_source(self, name) self.filename = name self.fileversion = self.read_fileversion() if self.fileversion == None: gutils.error(_('The format of the file is not supported.')) return False return True
def set_source(self, name): IP.set_source(self, name) self.filename = name self.fileversion = self.read_fileversion() if self.fileversion == None: gutils.error(_('The format of the file is not supported.')) return False if self.filename: self.imdbfilename = os.path.join(os.path.dirname(self.filename), 'IMDb.dat') else: self.imdbfilename = None return True
def set_source(self, name): # source _dependent_ initialization goes here if name is None or not os.path.isfile(name): return False IP.set_source(self, name) self.__source_name = name # auto-detect file-encoding (optional) try: from chardet.universaldetector import UniversalDetector detector = UniversalDetector() detector.reset() lines = 0 for line in file(self.__source_name, "rb"): detector.feed(line) lines += 1 if detector.done or lines == 50: break detector.close() encoding = string.lower(detector.result["encoding"]) except: log.exception("") encoding = "utf_8" encoding = self._encoding_cleanup.sub("", encoding) model = self.gtk.get_widget("e_encoding").get_model() itempos = 0 for item in model: pos1 = string.find(self._encoding_cleanup.sub("", string.lower(str(item[0]))), encoding) if pos1 == 0: break itempos += 1 self.gtk.get_widget("e_encoding").set_active(itempos) # auto-detect CSV import settings (optional) try: import csv sniffer = csv.Sniffer() csvfilesize = os.path.getsize(self.__source_name) if csvfilesize > 65535: csvfilesize = 65535 csvfile = file(self.__source_name, "rb") try: # quote char, line terminator and field delimiter proposed_dialect = sniffer.sniff(csvfile.read(csvfilesize)) self.gtk.get_widget("e_delimiter").set_text(proposed_dialect.delimiter) self.gtk.get_widget("e_quotechar").set_text(proposed_dialect.quotechar) if proposed_dialect.lineterminator == "\r\n": self.gtk.get_widget("e_lineterminator").set_active(1) # first row with column headers csvfile.seek(0) if sniffer.has_header(csvfile.read(csvfilesize)): self.gtk.get_widget("e_startrow").set_text("1") else: self.gtk.get_widget("e_startrow").set_text("0") finally: csvfile.close() except: log.exception("") # run dialog response = self.gtk.get_widget("d_import").run() if response == gtk.RESPONSE_OK: return True else: return False
def set_source(self, name): # source _dependent_ initialization goes here if name is None or not os.path.isfile(name): return False IP.set_source(self, name) self.__source_name = name # auto-detect file-encoding (optional) try: from chardet.universaldetector import UniversalDetector detector = UniversalDetector() detector.reset() lines = 0 for line in file(self.__source_name, 'rb'): detector.feed(line) lines += 1 if detector.done or lines == 50: break detector.close() encoding = string.lower(detector.result['encoding']) except: log.exception('') encoding = 'utf_8' encoding = self._encoding_cleanup.sub('', encoding) model = self.gtk.get_widget('e_encoding').get_model() itempos = 0 for item in model: pos1 = string.find( self._encoding_cleanup.sub('', string.lower(str(item[0]))), encoding) if pos1 == 0: break itempos += 1 self.gtk.get_widget('e_encoding').set_active(itempos) # auto-detect CSV import settings (optional) try: import csv sniffer = csv.Sniffer() csvfilesize = os.path.getsize(self.__source_name) if csvfilesize > 65535: csvfilesize = 65535 csvfile = file(self.__source_name, 'rb') try: # quote char, line terminator and field delimiter proposed_dialect = sniffer.sniff(csvfile.read(csvfilesize)) self.gtk.get_widget('e_delimiter').set_text( proposed_dialect.delimiter) self.gtk.get_widget('e_quotechar').set_text( proposed_dialect.quotechar) if proposed_dialect.lineterminator == '\r\n': self.gtk.get_widget('e_lineterminator').set_active(1) # first row with column headers csvfile.seek(0) if sniffer.has_header(csvfile.read(csvfilesize)): self.gtk.get_widget('e_startrow').set_text('1') else: self.gtk.get_widget('e_startrow').set_text('0') finally: csvfile.close() except: log.exception('') # run dialog response = self.gtk.get_widget('d_import').run() if response == gtk.RESPONSE_OK: return True else: return False