aboutsummaryrefslogtreecommitdiff
path: root/app/tasks/importtasks.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-05-27 22:03:54 +0100
committerrubenwardy <rw@rubenwardy.com>2018-05-27 22:04:03 +0100
commitfb5cba4cc82efa5cae4e78c5ad75575b615de378 (patch)
tree2f8c542baf23036b3f3f4dc761f2203794b5ffaf /app/tasks/importtasks.py
parentfb8aa25b710fe4b6db70a0b54b2d867b737a6cb1 (diff)
downloadcheatdb-fb5cba4cc82efa5cae4e78c5ad75575b615de378.tar.xz
Add dependency detection to importer
Diffstat (limited to 'app/tasks/importtasks.py')
-rw-r--r--app/tasks/importtasks.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py
index db992b3..022f9b3 100644
--- a/app/tasks/importtasks.py
+++ b/app/tasks/importtasks.py
@@ -55,6 +55,9 @@ class GithubURLMaker:
def getDescURL(self):
return self.baseUrl + "/description.txt"
+ def getDependsURL(self):
+ return self.baseUrl + "/depends.txt"
+
def getScreenshotURL(self):
return self.baseUrl + "/screenshot.png"
@@ -161,7 +164,7 @@ def getMeta(urlstr, author):
try:
contents = urllib.request.urlopen(urlmaker.getModConfURL()).read().decode("utf-8")
conf = parseConf(contents)
- for key in ["name", "description", "title"]:
+ for key in ["name", "description", "title", "depends", "optional_depends"]:
try:
result[key] = conf[key]
except KeyError:
@@ -179,16 +182,40 @@ def getMeta(urlstr, author):
except HTTPError:
print("description.txt does not exist!")
+ import re
+ pattern = re.compile("^([a-z0-9_]+)\??$")
+ if not "depends" in result and not "optional_depends" in result:
+ try:
+ contents = urllib.request.urlopen(urlmaker.getDependsURL()).read().decode("utf-8")
+ soft = []
+ hard = []
+ for line in contents.split("\n"):
+ line = line.strip()
+ if pattern.match(line):
+ if line[len(line) - 1] == "?":
+ soft.append( line[:-1])
+ else:
+ hard.append(line)
+
+ result["depends"] = ",".join(hard)
+ result["optional_depends"] = ",".join(soft)
+
+
+ except HTTPError:
+ print("depends.txt does not exist!")
+
if "description" in result:
desc = result["description"]
idx = desc.find(".") + 1
cutIdx = min(len(desc), 200 if idx < 5 else idx)
result["short_description"] = desc[:cutIdx]
+
info = findModInfo(author, result.get("name"), result["repo"])
if info is not None:
result["forumId"] = info.get("topicId")
+ print(result)
return result