diff --git a/.gitignore b/.gitignore index efba46a..2af4e65 100644 --- a/.gitignore +++ b/.gitignore @@ -220,3 +220,4 @@ cache* Log.txt scenerypacks_info.txt warnings.htm +data.dat \ No newline at end of file diff --git a/xpstart/scenery.py b/xpstart/scenery.py index 9f1871d..0ec257a 100644 --- a/xpstart/scenery.py +++ b/xpstart/scenery.py @@ -9,45 +9,43 @@ class Scenery(xpstart.Base): just the path to the scenery goes to the constructor. """ - def __init__(self,path,gui=None): + def __init__(self, path, gui=None): """ @type path: string @param path: the path to the scenery without ending "/" """ - - xpstart.Base.__init__(self,gui) - + + xpstart.Base.__init__(self, gui) self.__pathAptDat = "/Earth nav data/apt.dat" """Path to the apt.dat File begining at scenery folder""" - - + self.dataFile = "xpstart/cache_sceneries.txt" """The file were the data of the scenerie is cached That parameter is overwritten In one file there can be stored more data. The logic for storing is classname:title:dataname:data""" - - #======================================================================= + + self.userFile = "xpstart/data.dat" + + # ======================================================================= # The path to the scenery # If there is a / at the end it will be removed. - #======================================================================= + # ======================================================================= if path.endswith("/") or path.endswith("\\"): path = path[:-1] self.path = path - self.title = os.path.basename(self.path) """The title of a scenery is defined by the folder name""" - self.aptDatPath = "%s/%s" % (self.path,self.__pathAptDat) + self.aptDatPath = "%s/%s" % (self.path, self.__pathAptDat) """The path to the apt.dat file Were the apt.dat file is, when a scenery has one""" - + self.aptDat = os.path.exists(self.aptDatPath) """Is true, when there is a apt.dat file If apt.dat data is requested that parameter is asked""" - self.libraryTxt = os.path.exists("%s/library.txt" % (self.path)) """ If there is a library.txt file""" @@ -57,48 +55,47 @@ def __init__(self,path,gui=None): be defined. This gives the developer the possibility to define when his scenery should be loaded by the system. """ - self.pathSceneryTxt = "%s/%s" % (self.path,self.sceneryTxtFile) + self.pathSceneryTxt = "%s/%s" % (self.path, self.sceneryTxtFile) self.sceneryTxt = os.path.exists(self.pathSceneryTxt) if self.sceneryTxt: self.authLayergroup = self.getTxtProperty("LAYERGROUP", self.pathSceneryTxt) else: self.authLayergroup = "" - + self.counterObjects = self.getObjectCount() """Counts the objects and stores them into that parameter The parameter is a dictionary like the __objTypes""" - self.icaoCodes = self.searchIcaoCodes() """Icao codes of the scenery if there is an apt.dat One scenery can have many icao codes. The parameter is type list """ - + self.userLayer = self.getUserLayer() """Initialize the userLayer """ - - + + def countObjects(self): """ Counts all objects of the scenery and returns a dictionary with all the defined object types an the number how often they occur. """ - + counter = {} exceptionDirs = ["opensceneryx"] exceptionFiles = ["placeholder"] - + for objType in self.objTypes: counter[objType] = 0 # sum is for the sum() of all objects counter['sum'] = 0 self.echo("Analysing objects from %s" % (self.title)) - for path,dirs,files in os.walk(self.path): + for path, dirs, files in os.walk(self.path): if os.path.basename(path) in exceptionDirs: continue - if len(files)== 0: + if len(files) == 0: continue for objFile in files: fileElements = objFile.split(".") @@ -106,20 +103,20 @@ def countObjects(self): counter[fileElements[1]] = counter[fileElements[1]] + 1 counter['sum'] = counter['sum'] + 1 return counter - + def echoIcaoCodes(self): if len(self.icaoCodes) > 0: self.echo("ICAO Definitions in %s:" % (self.title)) self.echo(", ".join(self.icaoCodes)) - + def getSceneyPackIniStatus(self): """ Reads the status of the scenery out of the scenery_packs.ini Returns true for enabled and false for disabled """ iniFilePath = "%s/../scenery_packs.ini" % (self.path) - iniFile = open(iniFilePath,"r") + iniFile = open(iniFilePath, "r") for l in iniFile: l = l.strip() c = l.split(" ") @@ -134,7 +131,7 @@ def getSceneyPackIniStatus(self): return False else: return True - + def getObjectCount(self): """ Method to get the object count. For performance the cache is been used. @@ -150,24 +147,33 @@ def getObjectCount(self): counter = self.countObjects() self.writeData("counter", self.makeString(counter)) return counter - + def getUserLayer(self): """ Reads the user layer out of the cache. If no layer is availiable the value is "" """ - return self.readData("userLayer") - - + userLayer = self.readData("userLayer", self.userFile) + # Because the file changed from dataFile to userFile + # If there is an entry in the old file the value is copied + if userLayer == "": + userLayer = self.readData("userLayer", self.dataFile) + if userLayer is not "": + self.writeUserLayer(userLayer) + return userLayer + + + + def loadSceneryTxt(self): """Loads the scenery.txt file and sets the intern variables""" if self.sceneryTxt: - f = open(self.pathSceneryTxt,"r") + f = open(self.pathSceneryTxt, "r") for l in f: if l.startswith("LAYERGROUP"): print "H" - #TODO + # TODO f.close() - + def searchIcaoCodes(self): """ Returns a list with all the ICAO codes find in the apt.dat file of the @@ -194,13 +200,12 @@ def searchIcaoCodes(self): aptDatFile.close() self.writeData("icao", self.makeString(icaoCodes)) return icaoCodes - - def writeUserLayer(self,userLayer): + + def writeUserLayer(self, userLayer): """ The user can choose a layer for each scenery that value ist stored in the cache. """ - self.writeData("userLayer",userLayer) - + self.writeData("userLayer", userLayer, self.userFile) \ No newline at end of file diff --git a/xpstart/xpstart.py b/xpstart/xpstart.py index 468d8c1..f48b862 100644 --- a/xpstart/xpstart.py +++ b/xpstart/xpstart.py @@ -1,45 +1,44 @@ - class Base(): """ The base class contains parameters and function which has to be used by all other classes. These are some global definitions """ - - - def __init__(self,gui=None): - #======================================================================= + + + def __init__(self, gui=None): + # ======================================================================= # Object Types # Used for counting the objects #======================================================================= self.objTypes = [ - "ags", - "dsf", - "fac", - "for", - "lin", - "obj", - "pol", - "str", - "ter"] - + "ags", + "dsf", + "fac", + "for", + "lin", + "obj", + "pol", + "str", + "ter"] + #======================================================================= # A title will be filled in when there is an instance # That the cache functions work an empty title is created #======================================================================= self.title = "" - + #======================================================================= # Possibility to store a object for the gui to send messages #======================================================================= self.gui = gui - + #======================================================================= # The file were the data of the class is cached # In one file there can be stored more data. The logic for storing is # classname:title:dataname:data #======================================================================= self.dataFile = "xpstart/cache.ini" - + #======================================================================= # The delimiters are stored as parameter # dataDelimiterKey is to separate key and value from dictionaries @@ -47,11 +46,11 @@ def __init__(self,gui=None): #======================================================================= self.dataDelimiterKey = "," self.dataDelimiterEntry = ";" - + self.logFile = "xpstart/Log.txt" - - - def echo(self,txt): + + + def echo(self, txt): """ Method for sending text message to the user """ @@ -59,14 +58,13 @@ def echo(self,txt): print txt else: self.gui.echo(txt) - - - - def getTxtProperty(self,property,path): + + + def getTxtProperty(self, property, path): """ Method to get the value of a property which is defined in a txt file """ - f = open(path,"r") + f = open(path, "r") for l in f: c = l.split() if c[0].strip() == property: @@ -74,15 +72,16 @@ def getTxtProperty(self,property,path): return " ".join(c[1:]) f.close() return "" - - def log(self,txt): + + def log(self, txt): import datetime + timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - lf = open(self.logFile,"a") - lf.write("%s: %s\n" % (timestamp,txt)) + lf = open(self.logFile, "a") + lf.write("%s: %s\n" % (timestamp, txt)) lf.close() - - def makeDict(self,s): + + def makeDict(self, s): """ Makes a dictionary out of a string. The string should be made with the makeString() method. @@ -96,9 +95,9 @@ def makeDict(self,s): c = e.split(self.dataDelimiterKey) out[c[0]] = c[1] return out - - - def makeString(self,a): + + + def makeString(self, a): """ Makes a string of a list or dictionary object. The method is used to generate the data which will be written into the cache. @@ -106,13 +105,13 @@ def makeString(self,a): """ out = "" if type(a) is dict: - for key,val in a.items(): - out = "%s%s%s%s%s" % (out,key,self.dataDelimiterKey,val,self.dataDelimiterEntry) + for key, val in a.items(): + out = "%s%s%s%s%s" % (out, key, self.dataDelimiterKey, val, self.dataDelimiterEntry) return out elif type(a) is list: - return "%s%s" % (self.dataDelimiterEntry.join(a),self.dataDelimiterEntry) - - def parseFileLine(self,line): + return "%s%s" % (self.dataDelimiterEntry.join(a), self.dataDelimiterEntry) + + def parseFileLine(self, line): """ Parses a Cache line and returns a tuple (classname,title,dataname,data) @@ -120,9 +119,9 @@ def parseFileLine(self,line): @type line: string """ c = line.strip().split(":") - return (c[0],c[1],c[2],c[3]) - - def readData(self,dataname,dataFile = ""): + return (c[0], c[1], c[2], c[3]) + + def readData(self, dataname, dataFile=""): """ Reads one entry out of the cache. To find the data the dataname is needed. @param dataname: the name how to find the data @@ -131,18 +130,18 @@ def readData(self,dataname,dataFile = ""): if dataFile == "": dataFile = self.dataFile try: - cf = open(dataFile,"r") + cf = open(dataFile, "r") for l in cf: cclassname, ctitle, cdataname, cdata = self.parseFileLine(l) - if cclassname == self.__class__.__name__ and ctitle == self.title and cdataname == dataname: + if cclassname == self.__class__.__name__ and ctitle == self.title and cdataname == dataname: cf.close() return cdata cf.close() return "" except: return "" - - def writeData(self,dataname,data,dataFile = ""): + + def writeData(self, dataname, data, dataFile=""): """ Writes the given data into the cache file @param dataname: the name how the data can be found again @@ -154,23 +153,23 @@ def writeData(self,dataname,data,dataFile = ""): dataFile = self.dataFile oldCache = [] # Touch the file that there is no error, if there is no file - open(dataFile,"a").close() - cf = open(dataFile,"r") - #dataTuple = (self.__class__.__name__,self.title,dataname,data) + open(dataFile, "a").close() + cf = open(dataFile, "r") + # dataTuple = (self.__class__.__name__,self.title,dataname,data) #datastring = "%s:%s:%s:%s" % (self.__class__.__name__,self.title,dataname,data) - datastring = ":".join((self.__class__.__name__,self.title,dataname,data)) + datastring = ":".join((self.__class__.__name__, self.title, dataname, data)) append = True for l in cf: cclassname, ctitle, cdataname, cdata = self.parseFileLine(l) - if cclassname == self.__class__.__name__ and ctitle == self.title and cdataname == dataname: + if cclassname == self.__class__.__name__ and ctitle == self.title and cdataname == dataname: l = datastring append = False oldCache.append(l) if append: oldCache.append(datastring) cf.close() - cf = open(dataFile,"w") + cf = open(dataFile, "w") for l in oldCache: - if len(l)>5: + if len(l) > 5: cf.write("%s\n" % (l.strip())) cf.close() diff --git a/xpstart/xpstartgui.py b/xpstart/xpstartgui.py index ddcd3ac..829567e 100644 --- a/xpstart/xpstartgui.py +++ b/xpstart/xpstartgui.py @@ -10,7 +10,7 @@ def __init__(self, parent, xppath): self.xppath = xppath tk.Frame.__init__(self, parent) - parent.title("xpstart 0.95") + parent.title("xpstart 0.96") self.END = tk.END self.fontStyle = tkFont.Font(family="Helvetica", size=9) @@ -166,7 +166,8 @@ def clickActions(self): for icao in self.doubleIcaos: output = '%s%s, ' % (output, icao) for layer_information in self.doubleIcaos[icao]: - if layer_information['layer'] == self.controller.lg.defaultSceneryLayer: + if layer_information['layer'] == self.controller.lg.defaultSceneryLayer and not icao in \ + self.controller.lg.layers['Exclusion']['icaos']: self.defaultSceneryDoubles.append(icao) self.echo(output[:-1]) if len(self.defaultSceneryDoubles) > 0: