Improved code readability and logic. Mainly: wrapped single call statements in self-explanatory function names, replaced os.chdir calls with absolute path operations as these could down the line potentially cause major bugs, also replace CallFuncInDir calls and instead use absolute paths there as well as its easier to understand

prototype-backendless-search-and-website-generator
Manish 4 years ago
parent 89f91410e9
commit badc7cc4d5

@ -21,10 +21,7 @@ from GeneralFunctions.InputOutput import (
WriteTextFiles, WriteTextFiles,
WriteBinaryToFile WriteBinaryToFile
) )
from GeneralFunctions.OS import ( from GeneralFunctions.OS import CreateDir
CallFuncInDir,
CreateDir
)
""" FIXME: paths hard coded unix style & most likely will not work on winodws. """ FIXME: paths hard coded unix style & most likely will not work on winodws.
@ -42,18 +39,16 @@ class extractData:
return infoFiles return infoFiles
def copyBundle(self, bundleSrc, activityName): def copyBundle(self, bundleSrc, activityName):
CallFuncInDir( shutil.copy2(
self.websiteDir, bundleSrc,
shutil.copy2, self.websiteDir+"bundles/"+activityName+".xo"
self.bundlesDir+bundleSrc,
"bundles/"+activityName+".xo"
) )
def createDirectories(self): def createDirectories(self):
assert(CreateDir("app")) assert(CreateDir(self.websiteDir+"app"))
assert(CreateDir("icons")) assert(CreateDir(self.websiteDir+"icons"))
assert(CreateDir("bundles")) assert(CreateDir(self.websiteDir+"bundles"))
assert(CreateDir("js")) assert(CreateDir(self.websiteDir+"js"))
def extractActivityInfo(self, infoFilePath, zipFile): def extractActivityInfo(self, infoFilePath, zipFile):
infoList = [] infoList = []
@ -85,16 +80,11 @@ class extractData:
if iconAbsolutePath in bundle.namelist(): if iconAbsolutePath in bundle.namelist():
icon = bundle.read(iconAbsolutePath) icon = bundle.read(iconAbsolutePath)
iconPath = ( iconPath = (
"icons/" + self.websiteDir+"icons/" +
activityName activityName
+ ".svg" + ".svg"
) )
CallFuncInDir( WriteBinaryToFile(iconPath, icon)
self.websiteDir,
WriteBinaryToFile,
iconPath,
icon
)
else: else:
# Conitnue without icon since non-fatal error # Conitnue without icon since non-fatal error
self.iconErroredBundles.append(bundlePath) self.iconErroredBundles.append(bundlePath)
@ -105,6 +95,12 @@ class extractData:
self.copyBundle(bundlePath, activityName) self.copyBundle(bundlePath, activityName)
bundle.close() bundle.close()
def findBundles(self):
self.activityBundles = glob.glob(
self.bundlesDir+"**/*.xo",
recursive=True
)
def generateAppsHtmlPages(self): def generateAppsHtmlPages(self):
iconsDir = "../icons/" iconsDir = "../icons/"
bundlesDir = "../bundles/" bundlesDir = "../bundles/"
@ -130,7 +126,10 @@ class extractData:
'"><h2>Download<h2></a>\n</body>\n</html>' '"><h2>Download<h2></a>\n</body>\n</html>'
) )
WriteTextFiles("./app/" + appInfo["name"] + ".html", html) WriteTextFiles(
self.websiteDir+"./app/" + appInfo["name"] + ".html",
html
)
""" Only those which are specified in map will be added to index. """ Only those which are specified in map will be added to index.
If an entry or value does not exist in infoJSON than emprty entry will If an entry or value does not exist in infoJSON than emprty entry will
@ -155,7 +154,6 @@ class extractData:
) )
i2IMap = infoToIndexMap i2IMap = infoToIndexMap
self.indexDictList = []
for obj in json.loads(self.infoJson): for obj in json.loads(self.infoJson):
indexDict = {} indexDict = {}
@ -228,10 +226,9 @@ class extractData:
self.erroredBundles = [] self.erroredBundles = []
self.iconErroredBundles = [] self.iconErroredBundles = []
CallFuncInDir(self.websiteDir, self.createDirectories) self.createDirectories()
os.chdir(bundlesDir) self.findBundles()
self.activityBundles = glob.glob("**/*.xo", recursive=True)
self.purgeBundlesNotZipFile() self.purgeBundlesNotZipFile()
@ -241,8 +238,6 @@ class extractData:
self.generateIndex() self.generateIndex()
os.chdir(websiteDir)
self.generateAppsHtmlPages() self.generateAppsHtmlPages()
self.writeFiles() self.writeFiles()
@ -262,15 +257,24 @@ class extractData:
""" Files which are not continously written during the process """ Files which are not continously written during the process
Eg. Html, icon and bundles are written while processing each bundle Eg. Html, icon and bundles are written while processing each bundle
""" """
WriteTextFiles("info.json", self.infoJson) WriteTextFiles(self.websiteDir+"info.json", self.infoJson)
WriteTextFiles("./js/index.js", self.indexJs) WriteTextFiles(self.websiteDir+"js/index.js", self.indexJs)
WriteTextFiles( WriteTextFiles(
"bundlesNotExactlyOneInfoFile.txt", self.websiteDir+"bundlesNotExactlyOneInfoFile.txt",
self.bundlesNotExactlyOneInfoFile self.bundlesNotExactlyOneInfoFile
) )
WriteTextFiles("bundlesNotZipFiles.txt", self.bundlesNotZipFiles) WriteTextFiles(
WriteTextFiles("erroredBundles.txt", self.erroredBundles) self.websiteDir+"bundlesNotZipFiles.txt",
WriteTextFiles("iconErroredBundles.txt", self.iconErroredBundles) self.bundlesNotZipFiles
)
WriteTextFiles(
self.websiteDir+"erroredBundles.txt",
self.erroredBundles
)
WriteTextFiles(
self.websiteDir+"iconErroredBundles.txt",
self.iconErroredBundles
)
def processArguments(): def processArguments():

Loading…
Cancel
Save