def CMD_FileOpen(self,filepath): if filepath==None: if self.filepath==None: raise self.Error('Please specify the filepath') filepath = self.filepath else: self.filepath=filepath # Get the text: local_dir,tmp = os.path.split(self.filepath) text = FMFileManagement.open(filepath) meta_filepath,tmp = os.path.splitext(self.filepath) meta_filepath += '.athw_meta' if os.path.exists(meta_filepath): self.metadata=DPMetaData.init_from_xml_string( FMFileManagement.open(meta_filepath)) else: self.metadata=DPMetaData() language = self.metadata['language'] lastpos = self.metadata['lastpos'] self.textEdit.setText(text,type='xml',new_language=language) if lastpos != None: cur = self.textEdit.textCursor() cur.setPosition(lastpos) self.textEdit.setTextCursor(cur) return True
def open(filepath): file=FMFileManagement.open(filepath,output='readlines') res=[] # We read the config file file=FMFileManagement.open(filepath,output='readlines') # We fill the res with the values contained into the file for ligne in file: ligne=ligne.strip() ligne = ligne.split(' ') res.append(ligne) return res
def SLOT_actionSendToExternalSoftware (self): # Send the scene to another software (mine is called Antidote and # accept only a certain type of encoding). path=AWPreferences['EXTERNAL_SOFT_PATH'] if path=="": QtGui.QMessageBox.information(self, "External Software Sender", "Sorry, there is no path to the external software in the "+\ "configuration file.") return False text=self.textEdit.toXml() i=0 while AWPreferences['TMP_FILE_MARK']+"tmp"+str(i).zfill(3)+'.txt' in \ os.listdir('.'): i+=1 name=AWPreferences['TMP_FILE_MARK']+"tmp"+str(i).zfill(3)+'.txt' FMFileManagement.save(text,name, encoding='utf-8-sig', mode='w') s=subprocess.Popen(path+' '+os.path.abspath(name)) res = QtGui.QMessageBox.question(self, "External Software Sender", "Have you finished to correct the file?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel) if (res == QtGui.QMessageBox.Yes) : text = FMFileManagement.open(name, encoding='utf-8-sig', mode='rb') self.textEdit.setText(text,type='xml')
def open(pathway=None,errors='raise'): """ - pathway : the path to the "config.txt" file - errors: in ['raise','print','skip'] In the case of line line of the file not well written, it either: - it raises the error if it is 'raise' - it prints the error if it is 'print' - it skips the error if it is 'skip' """ assert errors in ['raise','print','skip'] pathway=pathway result_dictionary={} # We read the config.txt file file=FMFileManagement.open(pathway,output='readlines') # We get rid of the comments and empty lines file,equivalent_line = CLPreferencesFiles.clean_file(file) # We fill the result_dictionary with the values contained into the file for i,ligne in enumerate(file): try : # We call the method interpret_ligne to seperate the key from the values e,v=CLPreferencesFiles.interpret_ligne(ligne) result_dictionary[str(e)]=v except CLPreferencesFiles.Error , e: e_other = CLPreferencesFiles.Error(e.raison, line=equivalent_line[i], file=pathway) if errors=='raise': raise e_other elif errors=='print': print e_other elif errors=='skip': pass
def open(filepath): file=FMFileManagement.open(filepath,output='readlines') res={} # We read the config file file=FMFileManagement.open(filepath,output='readlines') # We fill the res with the values contained into the file for ligne in file: ligne=ligne.strip() i=ligne.find(' ') if i!= -1: k=ligne[:i] v=ligne[i:].strip() res[k]=v return res
def __init__(self,file=None,fromtext=None): """ A general class for importation (usually used with re-implementations) - file : the file to open with the text - fromtext: if file==None, we will take the string of these argument """ assert file!=None or fromtext!=None, 'either file or fromtext argument should not be None' if file!=None: self.file = file self.raw_text = FMFileManagement.open(self.file,with_codecs=False) else: self.file=None self.raw_text = fromtext self.text =False
def odt2html(self,skip=False): args = '-headless -convert-to html -outdir' dir_file,tmp = os.path.split(self.file) path,ext = os.path.splitext(self.file) newfile = path+'.html' if not skip or not os.path.exists(newfile): to_call = DIPreferences['LIBREOFFICE_COMMAND'] + ' ' + \ args + ' ' +\ os.path.abspath(dir_file)+ ' '+ \ os.path.abspath(self.file) print 'to_call : ',to_call res = os.system(to_call) if res!=0: raise IOError('Problem during convertion of the file, is the LIBREOFFICE_COMMAND correct ?') else: print "Skip the creation of the file" self.raw_text = FMFileManagement.open(newfile,with_codecs=False)