Add more metadata to importer

This commit is contained in:
rubenwardy
2018-05-12 17:28:04 +01:00
parent 2b0f61b453
commit db3d63d91a
2 changed files with 22 additions and 10 deletions

View File

@@ -30,6 +30,12 @@ class GithubURLMaker:
def isValid(self):
return self.baseUrl is not None
def getRepoURL(self):
return "https://github.com/" + self.user + "/" + self.repo + ".git"
def getIssueTrackerURL(self):
return "https://github.com/" + self.user + "/" + self.repo + "/issues/"
def getModConfURL(self):
return self.baseUrl + "/mod.conf"
@@ -70,10 +76,11 @@ def getMeta(urlstr):
if not urlmaker.isValid():
raise TaskError("Error! Url maker not valid")
print(urlmaker.getModConfURL())
result = {}
result["repo"] = urlmaker.getRepoURL()
result["issueTracker"] = urlmaker.getIssueTrackerURL()
try:
contents = urllib.request.urlopen(urlmaker.getModConfURL()).read().decode("utf-8")
conf = parseConf(contents)
@@ -82,11 +89,12 @@ def getMeta(urlstr):
result[key] = conf[key]
except KeyError:
pass
print(conf)
except OSError:
print("mod.conf does not exist")
if "name" in result:
result["title"] = result["name"].replace("_", " ").title()
if not "description" in result:
try:
contents = urllib.request.urlopen(urlmaker.getDescURL()).read().decode("utf-8")
@@ -94,6 +102,12 @@ def getMeta(urlstr):
except OSError:
print("description.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]
return result
@celery.task()