Compare commits
3 Commits
de04fe734d
...
ea5fda4de1
Author | SHA1 | Date | |
---|---|---|---|
|
ea5fda4de1 | ||
|
c10fedcd44 | ||
|
eaaaae65b0 |
@ -24,7 +24,6 @@ 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
|
||||||
@ -84,7 +83,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 seprate function for it
|
# FIXME: create separate 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:
|
||||||
@ -106,8 +105,6 @@ 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()
|
||||||
|
|
||||||
@ -152,72 +149,48 @@ 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
|
||||||
"""
|
"""
|
||||||
# FIXME: Simplify logic: replace str, tuple, list etc. with 'string' & 'array'
|
def generateIndex(self):
|
||||||
def generateIndex(
|
for activity in json.loads(self.infoJson):
|
||||||
self,
|
indexDict = {
|
||||||
infoToIndexMap={
|
"name": "",
|
||||||
"name": ("name", "string"),
|
"summary": "",
|
||||||
"summary": ("summary", "string"),
|
"description": "",
|
||||||
"description": ("description", "string"),
|
"tags": ()
|
||||||
"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 "
|
|
||||||
)
|
|
||||||
|
|
||||||
i2IMap = infoToIndexMap
|
name = activity.get("name")
|
||||||
|
if name is not None:
|
||||||
|
indexDict["name"] = name
|
||||||
|
|
||||||
for obj in json.loads(self.infoJson):
|
summary = activity.get("summary")
|
||||||
indexDict = {}
|
if summary is not None:
|
||||||
for k, v in obj.items():
|
indexDict["summary"] = summary
|
||||||
if k in i2IMap:
|
|
||||||
|
|
||||||
# add new entry/key to app index
|
description = activity.get("description")
|
||||||
if k not in indexDict:
|
if description is not None:
|
||||||
if i2IMap[k][1] == "string":
|
indexDict["description"] = description
|
||||||
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()
|
|
||||||
|
|
||||||
# Append to existing entry/key to app index
|
tags = []
|
||||||
else:
|
tagsKeys = ["tag", "tags", "category", "categories"]
|
||||||
if i2IMap[k][1] == "string":
|
for key in tagsKeys:
|
||||||
indexDict[i2IMap[k][0]] += ' '+v
|
tagsString = activity.get(key)
|
||||||
elif i2IMap[k][1] == "array":
|
if tagsString is not None:
|
||||||
if v.find(';') >= 0:
|
if tagsString.find(';') != -1:
|
||||||
indexDict[i2IMap[k][0]] += v.split(';')
|
tagsList = tagsString.split(';')
|
||||||
else:
|
else:
|
||||||
indexDict[i2IMap[k][0]] += v.split()
|
tagsList = tagsString.split()
|
||||||
else:
|
for tag in tagsList:
|
||||||
print(unexpectedInputError, i2IMap[k][1])
|
tag = tag.casefold().capitalize()
|
||||||
sys.exit(1)
|
if tag not in tags:
|
||||||
|
tags.append(tag)
|
||||||
|
indexDict["tags"] = tuple(tags)
|
||||||
|
|
||||||
# Create entry/key with empty value for keys not present
|
self.indexDictList.append(indexDict)
|
||||||
# in activity.info
|
self.indexJs = (
|
||||||
for k, v in i2IMap.items():
|
"search.assignIndex(" +
|
||||||
if v[0] not in indexDict:
|
json.dumps(self.indexDictList, indent=4) +
|
||||||
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)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
def CallFuncInDir(Directory, Function, *args, **kwArgs):
|
def CallFuncInDir(Directory, Function, *args, **kwArgs):
|
||||||
|
Loading…
Reference in New Issue
Block a user