Add dependency detection to importer

This commit is contained in:
rubenwardy 2018-05-27 22:03:54 +01:00
parent fb8aa25b71
commit fb5cba4cc8
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
3 changed files with 56 additions and 11 deletions

View File

@ -26,13 +26,25 @@ $(function() {
$(".pkg_wiz_2").show()
$(".pkg_repo").hide()
function setSpecial(id, value) {
if (value != "") {
var ele = $(id);
ele.val(value);
ele.trigger("change")
}
}
performTask("/tasks/getmeta/new/?url=" + encodeURI(repoURL)).then(function(result) {
$("#name").val(result.name || "")
setSpecial("#provides_str", result.name || "")
$("#title").val(result.title || "")
$("#repo").val(result.repo || repoURL)
$("#issueTracker").val(result.issueTracker || "")
$("#desc").val(result.description || "")
$("#shortDesc").val(result.short_description || "")
setSpecial("#harddep_str", result.depends || "")
setSpecial("#softdep_str", result.optional_depends || "")
$("#shortDesc").val(result.short_description || "")
if (result.forumId) {
$("#forums").val(result.forumId)
}

View File

@ -91,14 +91,6 @@
lookup[source[i].id] = source[i];
}
var selected_raw = result.val().split(",");
for (var i = 0; i < selected_raw.length; i++) {
var raw = selected_raw[i].trim();
if (lookup[raw]) {
selected.push(raw);
}
}
selector.click(function() { input.focus(); })
.delegate('.tag a', 'click', function() {
var id = $(this).parent().data("id");
@ -110,7 +102,6 @@
recreate();
});
function selectItem(id) {
for (var i = 0; i < selected.length; i++) {
if (selected[i] == id) {
@ -139,7 +130,22 @@
}
result.val(selected.join(","))
}
recreate();
function readFromResult() {
selected = [];
var selected_raw = result.val().split(",");
for (var i = 0; i < selected_raw.length; i++) {
var raw = selected_raw[i].trim();
if (lookup[raw] || raw.match(/^([a-z0-9_]+)$/)) {
selected.push(raw);
}
}
recreate();
}
readFromResult();
result.change(readFromResult);
input.keydown(function(e) {
if (e.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active)

View File

@ -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