Compare commits

..

No commits in common. "ea5fda4de12fec003e7a2375d0ffbde11b845ca0" and "de04fe734dcfd804f904c4046139731128d2062a" have entirely different histories.

2 changed files with 65 additions and 39 deletions

View File

@ -24,6 +24,7 @@ along with SAAS. If not, see <https://www.gnu.org/licenses/>.
import glob import glob
import json import json
import os import os
import shutil
import sys import sys
from urllib.parse import quote as strToHtmlFmt from urllib.parse import quote as strToHtmlFmt
import zipfile import zipfile
@ -83,7 +84,7 @@ class extractData:
infoDict = self.extractActivityInfo(infoFiles[0], bundle) infoDict = self.extractActivityInfo(infoFiles[0], bundle)
self.bundlesInfoList.append(infoDict) self.bundlesInfoList.append(infoDict)
# FIXME: create separate function for it # FIXME: create seprate function for it
# extract and copy icon # extract and copy icon
activityName = infoDict.get("name") activityName = infoDict.get("name")
if type(activityName) == str: if type(activityName) == str:
@ -105,6 +106,8 @@ class extractData:
self.iconErrorBundles.append(bundlePath) self.iconErrorBundles.append(bundlePath)
bundle.close() bundle.close()
# FIXME: uncomment below function.
# Disabled sometime during development as time consuming
self.copyBundle(bundlePath, activityName) self.copyBundle(bundlePath, activityName)
bundle.close() bundle.close()
@ -149,48 +152,72 @@ class extractData:
be created for it. be created for it.
appends keys rather than replacing where multiple map to same appends keys rather than replacing where multiple map to same
""" """
def generateIndex(self): # FIXME: Simplify logic: replace str, tuple, list etc. with 'string' & 'array'
for activity in json.loads(self.infoJson): def generateIndex(
indexDict = { self,
"name": "", infoToIndexMap={
"summary": "", "name": ("name", "string"),
"description": "", "summary": ("summary", "string"),
"tags": () "description": ("description", "string"),
} "tag": ("tags", "array"),
"tags": ("tags", "array"),
"categories": ("tags", "array"),
"category": ("tags", "array")
}
):
unexpectedInputError = (
"main.py generateIndex() : expect only str, list or tuple as "
"kwargs -> value[1] but found "
)
name = activity.get("name") i2IMap = infoToIndexMap
if name is not None:
indexDict["name"] = name
summary = activity.get("summary") for obj in json.loads(self.infoJson):
if summary is not None: indexDict = {}
indexDict["summary"] = summary for k, v in obj.items():
if k in i2IMap:
description = activity.get("description") # add new entry/key to app index
if description is not None: if k not in indexDict:
indexDict["description"] = description if i2IMap[k][1] == "string":
indexDict[i2IMap[k][0]] = v
elif i2IMap[k][1] == "array":
if v.find(';') >= 0:
indexDict[i2IMap[k][0]] = v.split(';')
else:
indexDict[i2IMap[k][0]] = v.split()
tags = [] # Append to existing entry/key to app index
tagsKeys = ["tag", "tags", "category", "categories"] else:
for key in tagsKeys: if i2IMap[k][1] == "string":
tagsString = activity.get(key) indexDict[i2IMap[k][0]] += ' '+v
if tagsString is not None: elif i2IMap[k][1] == "array":
if tagsString.find(';') != -1: if v.find(';') >= 0:
tagsList = tagsString.split(';') indexDict[i2IMap[k][0]] += v.split(';')
else: else:
tagsList = tagsString.split() indexDict[i2IMap[k][0]] += v.split()
for tag in tagsList: else:
tag = tag.casefold().capitalize() print(unexpectedInputError, i2IMap[k][1])
if tag not in tags: sys.exit(1)
tags.append(tag)
indexDict["tags"] = tuple(tags)
self.indexDictList.append(indexDict) # Create entry/key with empty value for keys not present
self.indexJs = ( # in activity.info
"search.assignIndex(" + for k, v in i2IMap.items():
json.dumps(self.indexDictList, indent=4) + if v[0] not in indexDict:
")" if v[1] == "string":
) indexDict[v[0]] = ""
elif v[1] == "array":
indexDict[v[0]] = ()
else:
print(unexpectedInputError, v[1])
sys.exit(1)
self.indexDictList.append(indexDict)
self.indexJs = (
"search.assignIndex(" +
json.dumps(self.indexDictList, indent=4) +
")"
)
def generateInfoJson(self): def generateInfoJson(self):
self.infoJson = json.dumps(self.bundlesInfoList, indent=4) self.infoJson = json.dumps(self.bundlesInfoList, indent=4)

View File

@ -1,5 +1,4 @@
import os import os
import shutil
def CallFuncInDir(Directory, Function, *args, **kwArgs): def CallFuncInDir(Directory, Function, *args, **kwArgs):