def ReadCurr(self, key): tempstruct = [] for root, dirs, files in os.walk(self.dm.Currdir): for name in files: # print ('Read Current File: ' + name) fullname, ext = os.path.splitext(name.strip()) # print str("fullname is " + fullname) # print ("fullpath is " + os.path.normpath(os.path.join(self.dm.getdirectorystring(fullname),self.dm.getfilename(fullname)))) if ext == ".txt": filename = self.dm.getfilename(fullname) # print str("filename is " + filename) dirname = self.dm.getdirectorystring(fullname) # print dirname corename = self.dm.getcorename(fullname) # print corename key = self.dm.getkey(fullname) # print key if not fullname is "": os.chdir(root) cpfile = open(name, "r") temp = singlefilestructure(self.tm, name, dirname, filename, corename, key, cpfile.readlines()) tempstruct.append(temp) # tempstruct.add(name, dirname, corename, cpfile.readlines()) cpfile.close() # print "End of loop..." for actfile in tempstruct: if actfile.iskey(""): temp = translatefilestructure(self.tm, actfile.corename, actfile) self.currdata.append(temp) for group in self.currdata: for actfile in tempstruct: if not actfile.iskey("") and actfile.isname(group.corename): group.add(actfile)
def ReadRef(self, key): tempstruct = [] for root, dirs, files in os.walk(self.dm.Refdir): for name in files: # print (' Read Reference File: ' + name) fullname, ext = os.path.splitext(name.strip()) # print str("fullname is " + fullname) if ext == ".txt": filename = self.dm.getfilename(fullname) # print str("filename is " + filename) dirname = self.dm.getdirectorystring(fullname) # print dirname corename = self.dm.getcorename(fullname) # print corename key = self.dm.getkey(fullname) # print key if not fullname is "": os.chdir(root) cpfile = open(name, "r") temp = singlefilestructure(self.tm, name, dirname, filename, corename, key, cpfile.readlines()) tempstruct.append(temp) # tempstruct.add(name, dirname, corename, cpfile.readlines()) cpfile.close() # print "End of loop..." # print str("Length of structure: " + str(len(tempstruct))) for actfile in tempstruct: if actfile.iskey(""): temp = translatefilestructure(self.tm, actfile.corename, actfile) self.refdata.append(temp) # print str("Creating Group " + actfile.corename + "...") for group in self.refdata: for actfile in tempstruct: # print str("Comparing " + group.corename + " with " + actfile.corename + " ...") if not actfile.iskey("") and actfile.isname(group.corename): group.add(actfile)
def ReadRef(self, key): tempstruct = [] for root, dirs, files in os.walk(self.dm.Refdir): for name in files: #print (' Read Reference File: ' + name) fullname, ext = os.path.splitext(name.strip()) #print str("fullname is " + fullname) if ext == ".txt": filename = self.dm.getfilename(fullname) #print str("filename is " + filename) dirname = self.dm.getdirectorystring(fullname) #print dirname corename = self.dm.getcorename(fullname) #print corename key = self.dm.getkey(fullname) #print key if not fullname is "": os.chdir(root) cpfile = open(name,"r") temp = singlefilestructure(self.tm, name, dirname, filename, corename, key, cpfile.readlines()) tempstruct.append(temp) #tempstruct.add(name, dirname, corename, cpfile.readlines()) cpfile.close() #print "End of loop..." #print str("Length of structure: " + str(len(tempstruct))) for actfile in tempstruct: if actfile.iskey(""): temp = translatefilestructure(self.tm, actfile.corename, actfile) self.refdata.append(temp) #print str("Creating Group " + actfile.corename + "...") for group in self.refdata: for actfile in tempstruct: #print str("Comparing " + group.corename + " with " + actfile.corename + " ...") if not actfile.iskey("") and actfile.isname(group.corename): group.add(actfile)
def ReadCurr(self, key): tempstruct = [] for root, dirs, files in os.walk(self.dm.Currdir): for name in files: #print ('Read Current File: ' + name) fullname, ext = os.path.splitext(name.strip()) #print str("fullname is " + fullname) #print ("fullpath is " + os.path.normpath(os.path.join(self.dm.getdirectorystring(fullname),self.dm.getfilename(fullname)))) if ext == ".txt": filename = self.dm.getfilename(fullname) #print str("filename is " + filename) dirname = self.dm.getdirectorystring(fullname) #print dirname corename = self.dm.getcorename(fullname) #print corename key = self.dm.getkey(fullname) #print key if not fullname is "": os.chdir(root) cpfile = open(name,"r") temp = singlefilestructure(self.tm, name, dirname, filename, corename, key, cpfile.readlines()) tempstruct.append(temp) #tempstruct.add(name, dirname, corename, cpfile.readlines()) cpfile.close() #print "End of loop..." for actfile in tempstruct: if actfile.iskey(""): temp = translatefilestructure(self.tm, actfile.corename, actfile) self.currdata.append(temp) for group in self.currdata: for actfile in tempstruct: if not actfile.iskey("") and actfile.isname(group.corename): group.add(actfile)
def add(self, fullfilename, filepath, filename, filecontent): corename = self.dm.getcorename(fullfilename) key = self.dm.getkey(fullfilename) temp = singlefilestructure(self.tm, fullfilename, filepath, filename, corename, key, filecontent) self.files.append(temp) if not key in self.kinds: self.kinds.append(key) self.count = self.count + 1
def Importfunction(self): """ This function imports new or improved translation documents """ if not os.path.exists(self.filestruct.dm.Currdir): self.statustext.set("Failed! Create Data First!") self.update() else: if os.path.exists(self.filestruct.dm.Importdir): os.chdir(self.filestruct.dm.Importdir) self.statustext.set("Starting...") self.update() tempstruct = [] for root, dirs, files in os.walk(self.filestruct.dm.Importdir): for name in files: fullname, ext = os.path.splitext(name.strip()) if ext == ".txt": #print ('Fullname: ' + fullname) filename, dirname, corename, trunkname, key = self.filestruct.dm.getinfo( fullname) #print ('Filename: ' + filename) #print ('Dirname: ' + dirname) #print ('Corename: ' + corename) #print ('Trunkname: ' + trunkname) #print ('Key: ' + key) if not fullname is "": os.chdir(root) cpfile = open(name, "r") temp = singlefilestructure( self.filestruct.tm, name, dirname, filename, corename, key, cpfile.readlines()) tempstruct.append(temp) cpfile.close() for file in tempstruct: transstruct = self.filestruct.findcurrgroup(file.corename) transstruct.exchange(file) self.statustext.set("Done!") self.update() else: self.statustext.set("No Import found...") self.update()
def Importfunction(self): """ This function imports new or improved translation documents """ if not os.path.exists(self.filestruct.dm.Currdir): self.statustext.set("Failed! Create Data First!") self.update() else: if os.path.exists(self.filestruct.dm.Importdir): os.chdir(self.filestruct.dm.Importdir) self.statustext.set("Starting...") self.update() tempstruct = [] for root, dirs, files in os.walk(self.filestruct.dm.Importdir): for name in files: fullname, ext = os.path.splitext(name.strip()) if ext == ".txt": #print ('Fullname: ' + fullname) filename, dirname, corename, trunkname, key = self.filestruct.dm.getinfo(fullname) #print ('Filename: ' + filename) #print ('Dirname: ' + dirname) #print ('Corename: ' + corename) #print ('Trunkname: ' + trunkname) #print ('Key: ' + key) if not fullname is "": os.chdir(root) cpfile = open(name,"r") temp = singlefilestructure(self.filestruct.tm, name, dirname, filename, corename, key, cpfile.readlines()) tempstruct.append(temp) cpfile.close() for file in tempstruct: transstruct = self.filestruct.findcurrgroup(file.corename) transstruct.exchange(file) self.statustext.set("Done!") self.update() else: self.statustext.set("No Import found...") self.update()
def export(self, languagestring): self.dm.gotodaydir() # print ("Entering function filestruct.export...") logfile = open("Logfile_" + languagestring + ".txt", "a") cvsfile = open("CVSfile_" + languagestring + ".txt", "a") logfile.write(str("Logging Output generated " + self.dm.getnow() + "\n\n")) cvsfile.write("export CVS_RSH=ssh\n") cvsfile.write("[email protected]:/cvsroot/jmri\n") for currgroup in self.currdata: # print ("Testing " + currgroup.corename.strip() + " ...") refgroup = [] for tempgroup in self.refdata: # print ('Checking '+ tempgroup.corename.strip()) if tempgroup.corename.strip() == currgroup.corename.strip(): refgroup = tempgroup # print ('Refgroup fond!') break reforigfile = [] reftransfile = [] if not refgroup == []: reforigfile = refgroup.original reftransfile = refgroup.get(languagestring) currorigfile = currgroup.original currtransfile = currgroup.get(languagestring) # print(currtransfile) if not currtransfile == []: if os.path.exists(os.path.normpath(os.path.join(currtransfile.path, currtransfile.filename))): numMissing, numNontrans, numObsolete = currtransfile.compare(self.tm, currorigfile) if (numMissing == 0) and (numNontrans == 0) and (numObsolete == 0): os.chdir(currtransfile.path) cpfile = open(currtransfile.filename, "r") reffile = singlefilestructure( self.tm, currtransfile.fullfilename, currtransfile.path, currtransfile.filename, currtransfile.corename, currtransfile.key, cpfile.readlines(), ) # print(currtransfile.filename) # print(currtransfile.fullfilename) cpfile.close() if currtransfile.isdifferent(self.tm, reffile): # print(currtransfile.path) # print(currtransfile.filename) # print(currtransfile.fullfilename) # print(reffile.filename) # print(reffile.fullfilename) cpfile = open(currtransfile.filename, "w") currtransfile.write(cpfile) cpfile.close() os.chdir(self.dm.Refdir) cpfile = open(currorigfile.fullfilename, "w") currorigfile.write(cpfile) cpfile.close() cpfile = open(currtransfile.fullfilename, "w") currtransfile.write(cpfile) cpfile.close() logfile.write(str("Updating file: " + currorigfile.filename + "\n")) cvsfile.write("\n" + "cd " + str(currorigfile.path).strip() + "\n") redname = currorigfile.filename.split(".", 1) cvsfile.write( "cvs -z3 -d:ext:[email protected]:/cvsroot/jmri update " + currorigfile.filename + "\n" ) else: numMissing, numNontrans, numObsolete = currtransfile.compare(self.tm, currorigfile) # print(currtransfile.path) # print(currtransfile.filename) if (numMissing == 0) and (numNontrans == 0) and (numObsolete == 0): os.chdir(currtransfile.path) # print(currtransfile.path) # print(currtransfile.filename) # print(currtransfile.fullfilename) cpfile = open(currtransfile.filename, "w") currtransfile.write(cpfile) cpfile.close() os.chdir(self.dm.Refdir) cpfile = open(currorigfile.fullfilename, "w") currorigfile.write(cpfile) cpfile.close() cpfile = open(currtransfile.fullfilename, "w") currtransfile.write(cpfile) cpfile.close() logfile.write(str("Adding file: " + currorigfile.filename + "\n")) cvsfile.write("\n" + "cd " + str(currorigfile.path).strip() + "\n") redname = currorigfile.filename.split(".", 1) cvsfile.write( "cvs -z3 -d:ext:[email protected]:/cvsroot/jmri add " + currorigfile.filename + "\n" ) logfile.write(str("\n")) cvsfile.write("\n" + "cd " + str(self.dm.Startpath).strip() + "\n") cvsfile.write( 'cvs -d:ext:[email protected]:/cvsroot/jmri commit -m "Translation Update ' + self.dm.gettoday() + '"\n' ) cvsfile.close() logfile.close()
def export(self, languagestring): self.dm.gotodaydir() #print ("Entering function filestruct.export...") logfile = open("Logfile_" + languagestring +".txt",'a') cvsfile = open("CVSfile_" + languagestring +".txt",'a') logfile.write(str("Logging Output generated " + self.dm.getnow() + "\n\n")) cvsfile.write("export CVS_RSH=ssh\n") cvsfile.write("[email protected]:/cvsroot/jmri\n") for currgroup in self.currdata: #print ("Testing " + currgroup.corename.strip() + " ...") refgroup = [] for tempgroup in self.refdata: #print ('Checking '+ tempgroup.corename.strip()) if tempgroup.corename.strip() == currgroup.corename.strip(): refgroup = tempgroup #print ('Refgroup fond!') break reforigfile = [] reftransfile = [] if not refgroup == []: reforigfile = refgroup.original reftransfile = refgroup.get(languagestring) currorigfile = currgroup.original currtransfile = currgroup.get(languagestring) #print(currtransfile) if not currtransfile == []: if os.path.exists(os.path.normpath(os.path.join(currtransfile.path,currtransfile.filename))): numMissing, numNontrans, numObsolete = currtransfile.compare(self.tm, currorigfile) if (numMissing == 0) and (numNontrans == 0) and (numObsolete == 0): os.chdir(currtransfile.path) cpfile = open(currtransfile.filename,"r") reffile = singlefilestructure(self.tm, currtransfile.fullfilename, currtransfile.path, currtransfile.filename, currtransfile.corename, currtransfile.key, cpfile.readlines()) #print(currtransfile.filename) #print(currtransfile.fullfilename) cpfile.close() if currtransfile.isdifferent(self.tm, reffile): #print(currtransfile.path) #print(currtransfile.filename) #print(currtransfile.fullfilename) #print(reffile.filename) #print(reffile.fullfilename) cpfile = open(currtransfile.filename,"w") currtransfile.write(cpfile) cpfile.close() os.chdir(self.dm.Refdir) cpfile = open(currorigfile.fullfilename,"w") currorigfile.write(cpfile) cpfile.close() cpfile = open(currtransfile.fullfilename,"w") currtransfile.write(cpfile) cpfile.close() logfile.write(str("Updating file: " + currorigfile.filename + "\n")) cvsfile.write("\n" + "cd " + str(currorigfile.path).strip() + "\n") redname = currorigfile.filename.split(".", 1) cvsfile.write("cvs -z3 -d:ext:[email protected]:/cvsroot/jmri update " + currorigfile.filename + "\n") else: numMissing, numNontrans, numObsolete = currtransfile.compare(self.tm, currorigfile) #print(currtransfile.path) #print(currtransfile.filename) if (numMissing == 0) and (numNontrans == 0) and (numObsolete == 0): os.chdir(currtransfile.path) #print(currtransfile.path) #print(currtransfile.filename) #print(currtransfile.fullfilename) cpfile = open(currtransfile.filename,"w") currtransfile.write(cpfile) cpfile.close() os.chdir(self.dm.Refdir) cpfile = open(currorigfile.fullfilename,"w") currorigfile.write(cpfile) cpfile.close() cpfile = open(currtransfile.fullfilename,"w") currtransfile.write(cpfile) cpfile.close() logfile.write(str("Adding file: " + currorigfile.filename + "\n")) cvsfile.write("\n" + "cd " + str(currorigfile.path).strip() + "\n") redname = currorigfile.filename.split(".", 1) cvsfile.write("cvs -z3 -d:ext:[email protected]:/cvsroot/jmri add " + currorigfile.filename + "\n") logfile.write(str("\n")) cvsfile.write("\n" + "cd " + str(self.dm.Startpath).strip() + "\n") cvsfile.write("cvs -d:ext:[email protected]:/cvsroot/jmri commit -m \"Translation Update " + self.dm.gettoday() + "\"\n") cvsfile.close() logfile.close()