Skip to content

Commit

Permalink
Merge pull request #16 from lyckade/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
lyckade committed Aug 11, 2014
2 parents a2f8e87 + 9622057 commit 960eb57
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 95 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,4 @@ cache*
Log.txt
scenerypacks_info.txt
warnings.htm
data.dat
81 changes: 43 additions & 38 deletions xpstart/scenery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -57,69 +55,68 @@ 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(".")
if "." in objFile and fileElements[1] in self.objTypes and fileElements[0] not in exceptionFiles:
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(" ")
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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)


Loading

0 comments on commit 960eb57

Please sign in to comment.