1
0
mirror of https://github.com/daknuett/licor synced 2024-07-20 12:15:24 +00:00

moved templates to separated directories

This commit is contained in:
Daniel Knüttel 2018-01-25 12:08:37 +01:00
parent 72b3cde7bd
commit d60ab6abbb
49 changed files with 11 additions and 6 deletions

View File

@ -25,11 +25,16 @@ from string import Template
class TemplateException(Exception): class TemplateException(Exception):
pass pass
def get_resource_string(name): def get_resource_string(name, is_global = True):
""" """
Return the resource string with the given name UTF-8 encoded. Return the resource string with the given name UTF-8 encoded.
""" """
if(is_global):
return pkg_resources.resource_string(__name__,"templates/" + name).decode("UTF-8") return pkg_resources.resource_string(__name__,"templates/" + name).decode("UTF-8")
else:
start = name[0].lower()
path = "templates/" + start + "/" + name
return pkg_resources.resource_string(__name__, path).decode("UTF-8")
def get_template(name, modifiers = []): def get_template(name, modifiers = []):
@ -49,7 +54,7 @@ def get_template(name, modifiers = []):
get_template("AGPL", modifiers = ["single-file"]) get_template("AGPL", modifiers = ["single-file"])
""" """
templates_avail = json.loads(get_resource_string("licenses_avail.json")) templates_avail = get_templates_available()
if( not name in templates_avail): if( not name in templates_avail):
raise TemplateException("Unknown license: {}".format(name)) raise TemplateException("Unknown license: {}".format(name))
@ -68,11 +73,11 @@ def get_template(name, modifiers = []):
meta_name = ".".join((name, "meta")) meta_name = ".".join((name, "meta"))
data_name = ".".join((name, "tx")) data_name = ".".join((name, "tx"))
try: try:
meta = json.loads(get_resource_string(meta_name)) meta = json.loads(get_resource_string(meta_name, False))
except: except:
continue continue
data = get_resource_string(data_name) data = get_resource_string(data_name, False)
meta.update({"text": data}) meta.update({"text": data})
return meta return meta
@ -112,7 +117,7 @@ def get_template_meta(name, modifiers = []):
else: else:
meta_name = ".".join((name, "meta")) meta_name = ".".join((name, "meta"))
try: try:
meta = json.loads(get_resource_string(meta_name)) meta = json.loads(get_resource_string(meta_name, True))
except: except:
continue continue