Improved readability for assert statements, simplified code for extractData.generateIndex(), fixed some spelling errors
This commit is contained in:
parent
c217e39ad9
commit
edf1341952
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
""" Run as:
|
""" Run as:
|
||||||
python3 thisscript.py "/bundles/directoty" "/website/template/root/directory/
|
python3 thisscript.py "/bundles/directory" "/website/template/root/directory/
|
||||||
All sub-directories of bundles directory will be scanned for activity
|
All sub-directories of bundles directory will be scanned for activity
|
||||||
bundles i.e. .xo files.
|
bundles i.e. .xo files.
|
||||||
"""
|
"""
|
||||||
@ -24,7 +24,7 @@ from GeneralFunctions.InputOutput import (
|
|||||||
from GeneralFunctions.OS import CreateDir
|
from GeneralFunctions.OS import 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 Windows.
|
||||||
Use code written for IMM to handle it.
|
Use code written for IMM to handle it.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -45,10 +45,10 @@ class extractData:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def createDirectories(self):
|
def createDirectories(self):
|
||||||
assert(CreateDir(self.websiteDir+"app"))
|
assert CreateDir(self.websiteDir+"app")
|
||||||
assert(CreateDir(self.websiteDir+"icons"))
|
assert CreateDir(self.websiteDir+"icons")
|
||||||
assert(CreateDir(self.websiteDir+"bundles"))
|
assert CreateDir(self.websiteDir+"bundles")
|
||||||
assert(CreateDir(self.websiteDir+"js"))
|
assert CreateDir(self.websiteDir+"js")
|
||||||
|
|
||||||
def extractActivityInfo(self, infoFilePath, zipFile):
|
def extractActivityInfo(self, infoFilePath, zipFile):
|
||||||
infoList = []
|
infoList = []
|
||||||
@ -86,12 +86,12 @@ class extractData:
|
|||||||
)
|
)
|
||||||
WriteBinaryToFile(iconPath, icon)
|
WriteBinaryToFile(iconPath, icon)
|
||||||
else:
|
else:
|
||||||
# Conitnue without icon since non-fatal error
|
# Continue without icon since non-fatal error
|
||||||
self.iconErrorBundles.append(bundlePath)
|
self.iconErrorBundles.append(bundlePath)
|
||||||
|
|
||||||
bundle.close()
|
bundle.close()
|
||||||
# FIXME: uncomment below function.
|
# FIXME: uncomment below function.
|
||||||
# Disabled sometime during devlopment as time consuming
|
# Disabled sometime during development as time consuming
|
||||||
self.copyBundle(bundlePath, activityName)
|
self.copyBundle(bundlePath, activityName)
|
||||||
bundle.close()
|
bundle.close()
|
||||||
|
|
||||||
@ -132,20 +132,21 @@ class extractData:
|
|||||||
)
|
)
|
||||||
|
|
||||||
""" 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 empty entry will
|
||||||
be created for it.
|
be created for it.
|
||||||
appends keys rather than replacing where mutiple map to same
|
appends keys rather than replacing where multiple map to same
|
||||||
"""
|
"""
|
||||||
|
# FIXME: Simplify logic: replace str, tuple, list etc. with 'string' & 'array'
|
||||||
def generateIndex(
|
def generateIndex(
|
||||||
self,
|
self,
|
||||||
infoToIndexMap={
|
infoToIndexMap={
|
||||||
"name": ("name", str),
|
"name": ("name", "string"),
|
||||||
"summary": ("summary", str),
|
"summary": ("summary", "string"),
|
||||||
"description": ("description", str),
|
"description": ("description", "string"),
|
||||||
"tag": ("tags", list),
|
"tag": ("tags", "array"),
|
||||||
"tags": ("tags", list),
|
"tags": ("tags", "array"),
|
||||||
"categories": ("tags", list),
|
"categories": ("tags", "array"),
|
||||||
"category": ("tags", list)
|
"category": ("tags", "array")
|
||||||
}
|
}
|
||||||
):
|
):
|
||||||
unexpectedInputError = (
|
unexpectedInputError = (
|
||||||
@ -162,10 +163,9 @@ class extractData:
|
|||||||
|
|
||||||
# add new entry/key to app index
|
# add new entry/key to app index
|
||||||
if k not in indexDict:
|
if k not in indexDict:
|
||||||
if i2IMap[k][1] == str:
|
if i2IMap[k][1] == "string":
|
||||||
indexDict[i2IMap[k][0]] = v
|
indexDict[i2IMap[k][0]] = v
|
||||||
elif (i2IMap[k][1] == list
|
elif i2IMap[k][1] == "array":
|
||||||
or i2IMap[k][1] == tuple):
|
|
||||||
if v.find(';') >= 0:
|
if v.find(';') >= 0:
|
||||||
indexDict[i2IMap[k][0]] = v.split(';')
|
indexDict[i2IMap[k][0]] = v.split(';')
|
||||||
else:
|
else:
|
||||||
@ -173,10 +173,9 @@ class extractData:
|
|||||||
|
|
||||||
# Append to existing entry/key to app index
|
# Append to existing entry/key to app index
|
||||||
else:
|
else:
|
||||||
if i2IMap[k][1] == str:
|
if i2IMap[k][1] == "string":
|
||||||
indexDict[i2IMap[k][0]] += ' '+v
|
indexDict[i2IMap[k][0]] += ' '+v
|
||||||
elif (i2IMap[k][1] == list
|
elif i2IMap[k][1] == "array":
|
||||||
or i2IMap[k][1] == tuple):
|
|
||||||
if v.find(';') >= 0:
|
if v.find(';') >= 0:
|
||||||
indexDict[i2IMap[k][0]] += v.split(';')
|
indexDict[i2IMap[k][0]] += v.split(';')
|
||||||
else:
|
else:
|
||||||
@ -186,12 +185,12 @@ class extractData:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Create entry/key with empty value for keys not present
|
# Create entry/key with empty value for keys not present
|
||||||
# in activty.info
|
# in activity.info
|
||||||
for k, v in i2IMap.items():
|
for k, v in i2IMap.items():
|
||||||
if v[0] not in indexDict:
|
if v[0] not in indexDict:
|
||||||
if v[1] == str:
|
if v[1] == "string":
|
||||||
indexDict[v[0]] = ""
|
indexDict[v[0]] = ""
|
||||||
elif (v[1] == list or v[1] == tuple):
|
elif v[1] == "array":
|
||||||
indexDict[v[0]] = ()
|
indexDict[v[0]] = ()
|
||||||
else:
|
else:
|
||||||
print(unexpectedInputError, v[1])
|
print(unexpectedInputError, v[1])
|
||||||
@ -210,9 +209,9 @@ class extractData:
|
|||||||
def __init__(self, bundlesDir, websiteDir):
|
def __init__(self, bundlesDir, websiteDir):
|
||||||
""" FIXME: WARNING:: some files may be missing such as some app
|
""" FIXME: WARNING:: some files may be missing such as some app
|
||||||
may not have icon (use a placeholder icon for them)
|
may not have icon (use a placeholder icon for them)
|
||||||
Some bundles are not succesfully processed (html page + bundle copy)
|
Some bundles are not successfully processed (html page + bundle copy)
|
||||||
but are not in error logs as well. There are 495 bundles in
|
but are not in error logs as well. There are 495 bundles in
|
||||||
Tony's repo, 479 sucessfully processed but showing fatal error of
|
Tony's repo, 479 successfully processed but showing fatal error of
|
||||||
12 only, i.e. 4 missing.
|
12 only, i.e. 4 missing.
|
||||||
"""
|
"""
|
||||||
self.bundlesDir = bundlesDir
|
self.bundlesDir = bundlesDir
|
||||||
@ -254,7 +253,7 @@ class extractData:
|
|||||||
self.activityBundles = activityBundles
|
self.activityBundles = activityBundles
|
||||||
|
|
||||||
def writeFiles(self):
|
def writeFiles(self):
|
||||||
""" Files which are not continously written during the process
|
""" Files which are not continuously 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(self.websiteDir+"info.json", self.infoJson)
|
WriteTextFiles(self.websiteDir+"info.json", self.infoJson)
|
||||||
|
Loading…
Reference in New Issue
Block a user