Add support for README files when importing meta

Fixes #87
This commit is contained in:
rubenwardy 2021-02-28 02:36:31 +00:00
parent da81df535a
commit ff2f7caee1
6 changed files with 40 additions and 20 deletions

@ -279,8 +279,6 @@ def create_edit(author=None, name=None):
form.license.data = None
form.media_license.data = None
else:
# form.harddep_str.data = ",".join([str(x) for x in package.getSortedHardDependencies() ])
# form.softdep_str.data = ",".join([str(x) for x in package.getSortedOptionalDependencies() ])
form.tags.data = list(package.tags)
form.content_warnings.data = list(package.content_warnings)

@ -14,7 +14,7 @@ $("textarea.markdown").each(function() {
let timeout_id = null;
new EasyMDE({
this.easy_mde = new EasyMDE({
element: this,
hideIcons: ["image"],
showIcons: ["code", "table"],

@ -25,6 +25,14 @@ $(function() {
const ele = $(id);
ele.val(value);
ele.trigger("change");
// EasyMDE doesn't always refresh the codemirror correctly
if (ele[0].easy_mde) {
setTimeout(() => {
ele[0].easy_mde.value(value);
ele[0].easy_mde.codemirror.refresh()
}, 100);
}
}
}
@ -33,12 +41,9 @@ $(function() {
setField("#title", result.title);
setField("#repo", result.repo || repoURL);
setField("#issueTracker", result.issueTracker);
setField("#desc", result.description);
setField("#short_desc", result.short_description);
// setField("#harddep_str", result.depends);
// setField("#softdep_str", result.optional_depends);
setField("#short_desc", result.short_description);
setField("#forums", result.forumId);
setField("#desc", result.desc);
setField("#short_desc", result.short_desc);
setField("#forums", result.forums);
if (result.type && result.type.length > 2) {
$("#type").val(result.type);
}

@ -26,7 +26,7 @@ from app.utils import randomString, post_bot_message, addSystemNotification, add
from app.utils.git import clone_repo, get_latest_tag, get_latest_commit, get_temp_dir
from .minetestcheck import build_tree, MinetestCheckError, ContentType
from ..logic.LogicError import LogicError
from ..logic.packages import do_edit_package
from ..logic.packages import do_edit_package, ALIASES
@celery.task()
@ -37,17 +37,31 @@ def getMeta(urlstr, author):
except MinetestCheckError as err:
raise TaskError(str(err))
result = {"name": tree.name, "provides": tree.getModNames(), "type": tree.type.name}
for key in ["depends", "optional_depends"]:
result[key] = tree.fold("meta", key)
result = {"name": tree.name, "type": tree.type.name}
for key in ["title", "repo", "issueTracker", "forumId", "description", "short_description"]:
result[key] = tree.get(key)
for mod in result["provides"]:
result["depends"].discard(mod)
result["optional_depends"].discard(mod)
result["forums"] = result.get("forumId")
readme_path = tree.getReadMePath()
if readme_path:
with open(readme_path, "r") as f:
result["long_description"] = f.read()
try:
with open(os.path.join(tree.baseDir, ".cdb.json"), "r") as f:
data = json.loads(f.read())
for key, value in data.items():
result[key] = value
except LogicError as e:
raise TaskError(e.message)
except IOError:
pass
for alias, to in ALIASES.items():
if alias in result:
result[to] = result[alias]
for key, value in result.items():
if isinstance(value, set):

@ -63,6 +63,11 @@ class PackageTreeNode:
elif self.type == ContentType.MODPACK:
self.add_children_from_mod_dir(None)
def getReadMePath(self):
for filename in os.listdir(self.baseDir):
path = os.path.join(self.baseDir, filename)
if os.path.isfile(path) and filename.lower().startswith("readme."):
return path
def getMetaFileName(self):
if self.type == ContentType.GAME:
@ -76,7 +81,6 @@ class PackageTreeNode:
else:
return None
def read_meta(self):
result = {}
@ -146,7 +150,6 @@ class PackageTreeNode:
"Invalid dependency name '{}' for mod at {}, names must only contain a-z0-9_." \
.format(dep, self.relative))
# Check dependencies
checkDependencies(result["depends"])
checkDependencies(result["optional_depends"])

@ -15,7 +15,7 @@
{% if enable_wizard %}
<script src="/static/libs/url.min.js"></script>
<script src="/static/polltask.js"></script>
<script src="/static/package_create.js?v=4"></script>
<script src="/static/package_create.js?v=5"></script>
{% endif %}
<script src="/static/package_edit.js?v=4"></script>
{% endblock %}