Compare commits

5 Commits

3 changed files with 53 additions and 69 deletions
+51 -68
View File
@@ -24,7 +24,6 @@ along with SAAS. If not, see <https://www.gnu.org/licenses/>.
import glob
import json
import os
import shutil
import sys
from urllib.parse import quote as strToHtmlFmt
import zipfile
@@ -84,9 +83,12 @@ class extractData:
infoDict = self.extractActivityInfo(infoFiles[0], bundle)
self.bundlesInfoList.append(infoDict)
# FIXME: create seprate function for it
# FIXME: create separate function for it
# extract and copy icon
activityName = infoDict.get("name")
activityVersion = infoDict.get("activity_version")
if activityVersion is None:
activityVersion = ''
if type(activityName) == str:
iconRelativePath = infoDict.get("icon")
if type(iconRelativePath) == str:
@@ -106,9 +108,8 @@ class extractData:
self.iconErrorBundles.append(bundlePath)
bundle.close()
# FIXME: uncomment below function.
# Disabled sometime during development as time consuming
self.copyBundle(bundlePath, activityName)
self.copyBundle(
bundlePath, activityName+'-'+activityVersion)
bundle.close()
def findBundles(self):
@@ -121,14 +122,15 @@ class extractData:
iconsDir = "../icons/"
bundlesDir = "../bundles/"
for appInfo in self.indexDictList:
pathName = strToHtmlFmt(appInfo["name"], safe='')
appName = strToHtmlFmt(appInfo["name"], safe='')
appVersion = strToHtmlFmt(appInfo["version"], safe='')
html = (
'<!DOCTYPE html>\n<html>\n<head>\n<title>' + appInfo["name"] +
'</title>\n<meta charset="utf-8"/>\n<link rel="stylesheet" '
'type="text/css" href="../css/main.css"/>\n</head>\n<body>\n'
'</body>\n<h1>' + appInfo["name"] + '</h1>\n<p><img src="' +
str(iconsDir + pathName + '.svg') + '"></img></p>\n'
str(iconsDir + appName + '.svg') + '"></img></p>\n'
'<div id=summary><h2>Summary</h2>\n<p>' + appInfo["summary"] +
'</p>\n</div>\n<div id=description><h2>Description</h2>\n<p>' +
appInfo["description"] + '</p>\n</div>\n<div id=tags><h2>Tags'
@@ -138,7 +140,7 @@ class extractData:
html += '<li>' + tag + '</li>\n'
html += (
'</ul>\n</div>\n<h2 id="downloadButton"><a href="' +
str(bundlesDir + pathName + '.xo') +
str(bundlesDir + appName + appVersion + '.xo') +
'">Download</a></h2>\n<br>\n</body>\n</html>'
)
@@ -152,72 +154,53 @@ class extractData:
be created for it.
appends keys rather than replacing where multiple map to same
"""
# FIXME: Simplify logic: replace str, tuple, list etc. with 'string' & 'array'
def generateIndex(
self,
infoToIndexMap={
"name": ("name", "string"),
"summary": ("summary", "string"),
"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 "
)
def generateIndex(self):
for activity in json.loads(self.infoJson):
indexDict = {
"name": "",
"summary": "",
"description": "",
"tags": (),
"version": "-"
}
i2IMap = infoToIndexMap
name = activity.get("name")
if name is not None:
indexDict["name"] = name
for obj in json.loads(self.infoJson):
indexDict = {}
for k, v in obj.items():
if k in i2IMap:
summary = activity.get("summary")
if summary is not None:
indexDict["summary"] = summary
# add new entry/key to app index
if k not in indexDict:
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()
description = activity.get("description")
if description is not None:
indexDict["description"] = description
# Append to existing entry/key to app index
else:
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()
else:
print(unexpectedInputError, i2IMap[k][1])
sys.exit(1)
tags = []
tagsKeys = ["tag", "tags", "category", "categories"]
for key in tagsKeys:
tagsString = activity.get(key)
if tagsString is not None:
if tagsString.find(';') != -1:
tagsList = tagsString.split(';')
else:
tagsList = tagsString.split()
for tag in tagsList:
tag = tag.casefold().capitalize()
if tag not in tags:
tags.append(tag)
indexDict["tags"] = tuple(tags)
# Create entry/key with empty value for keys not present
# in activity.info
for k, v in i2IMap.items():
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)
activityVersion = activity.get("activity_version")
if activityVersion is not None:
indexDict["version"] += activityVersion
self.indexDictList.append(indexDict)
self.indexJs = (
"search.assignIndex(" +
json.dumps(self.indexDictList, indent=4) +
")"
)
self.indexDictList.append(indexDict)
self.indexJs = (
"search.assignIndex(" +
json.dumps(self.indexDictList, indent=4) +
")"
)
def generateInfoJson(self):
self.infoJson = json.dumps(self.bundlesInfoList, indent=4)
+1
View File
@@ -1,4 +1,5 @@
import os
import shutil
def CallFuncInDir(Directory, Function, *args, **kwArgs):
+1 -1
View File
@@ -64,7 +64,7 @@ var search = {
for (var tag of app.tags)
html += '<li>'+ tag +'</li>\n';
html += '</ul>\n</div>\n<h2 id="downloadButton"><a href="' +
'./bundles/' + app.name + '.xo' +
'./bundles/' + app.name + app.version+ '.xo' +
'">Download</a></h2>\n';
return html;
},