Пример #1
0
def _extract_reports():
    print("_extract_reports")
    global _report_dir
    print("_report_dir", _report_dir)
    loaded_modules = module.get_loaded_modules()
    for m in loaded_modules:
        if pkg_resources.resource_exists(m, "reports"):
            for fname in pkg_resources.resource_listdir(m, "reports"):
                print("%s %s" % (m, fname))
                data = pkg_resources.resource_string(m, "reports/" + fname)
                path = os.path.join(_report_dir, fname)
                f = open(path, "wb")
                f.write(data)
                f.close()
Пример #2
0
def templates_to_json(modules=None):
    templates={}
    if modules is None:
        modules=module.get_loaded_modules()
    for m in modules:
        if not pkg_resources.resource_exists(m, "templates"):
            continue
        for fname in pkg_resources.resource_listdir(m, "templates"):
            if not fname.endswith(".hbs") and not fname.endswith(".jsx"):
                continue
            tmpl_name = os.path.splitext(fname)[0]
            tmpl_src = pkg_resources.resource_string(m, "templates/" + fname).decode("utf-8")
            templates[tmpl_name]=tmpl_src
    return templates
Пример #3
0
def get_module_template_src(name):
    loaded_modules = module.get_loaded_modules()
    for m in loaded_modules:
        if not pkg_resources.resource_exists(m, "templates"):
            continue
        for fname in pkg_resources.resource_listdir(m, "templates"):
            if not fname.endswith("hbs"):
                continue
            tmpl_name = os.path.splitext(fname)[0]
            if tmpl_name!=name:
                continue
            tmpl_src = pkg_resources.resource_string(m, "templates/" + fname).decode("utf-8")
            return tmpl_src
    return None
Пример #4
0
def _extract_reports():
    print("_extract_reports")
    global _report_dir
    print("_report_dir", _report_dir)
    loaded_modules = module.get_loaded_modules()
    for m in loaded_modules:
        if pkg_resources.resource_exists(m, "reports"):
            for fname in pkg_resources.resource_listdir(m, "reports"):
                print("%s %s" % (m, fname))
                data = pkg_resources.resource_string(m, "reports/" + fname)
                path = os.path.join(_report_dir, fname)
                f = open(path, "wb")
                f.write(data)
                f.close()
Пример #5
0
def _extract_report_file(fname, report_dir):
    print("_extract_report_file", fname)
    found = False
    loaded_modules = module.get_loaded_modules()
    for m in reversed(loaded_modules):
        if pkg_resources.resource_exists(m, "reports/" + fname):
            found = True
            data = pkg_resources.resource_string(m, "reports/" + fname)
            path = os.path.join(report_dir, fname)
            f = open(path, "wb")
            f.write(data)
            f.close()
            break
    if not found:
        raise Exception("Report file not found: %s" % fname)
Пример #6
0
def _extract_report_file(fname, report_dir):
    print("_extract_report_file", fname)
    found = False
    loaded_modules = module.get_loaded_modules()
    for m in reversed(loaded_modules):
        if pkg_resources.resource_exists(m, "reports/" + fname):
            found = True
            data = pkg_resources.resource_string(m, "reports/" + fname)
            path = os.path.join(report_dir, fname)
            f = open(path, "wb")
            f.write(data)
            f.close()
            break
    if not found:
        raise Exception("Report file not found: %s" % fname)
Пример #7
0
def get_report_template(name, report_type):
    db = database.get_connection()
    res = db.get("SELECT file FROM report_template WHERE name=%s AND format=%s", name, report_type)
    if res:
        path = utils.get_file_path(res.file)
        data = open(path, "rb").read()
        return data
    loaded_modules = module.get_loaded_modules()
    for m in reversed(loaded_modules):
        f = "reports/" + name + "." + report_type
        if not pkg_resources.resource_exists(m, f):
            continue
        data = pkg_resources.resource_string(m, f)
        return data
    raise Exception("Report not found: %s" % name)
Пример #8
0
def get_report_template(name, report_type):
    db = database.get_connection()
    res = db.get(
        "SELECT file FROM report_template WHERE name=%s AND format=%s", name,
        report_type)
    if res:
        path = utils.get_file_path(res.file)
        data = open(path, "rb").read()
        return data
    loaded_modules = module.get_loaded_modules()
    for m in reversed(loaded_modules):
        f = "reports/" + name + "." + report_type
        if not pkg_resources.resource_exists(m, f):
            continue
        data = pkg_resources.resource_string(m, f)
        return data
    raise Exception("Report not found: %s" % name)
Пример #9
0
 def load_templates(self, ids, context={}):
     obj = self.browse(ids[0])
     if obj.file:
         zip_path = utils.get_file_path(obj.file)
         zf = zipfile.ZipFile(zip_path)
         for n in zf.namelist():
             if not n.startswith("templates/"):
                 continue
             if not n.endswith(".hbs"):
                 continue
             n2 = n[10:-4]
             if n2.find("..") != -1:
                 continue
             print("load template", n2)
             data = zf.read(n)
             vals = {
                 "name": n2,
                 "template": data.decode(),
                 "theme_id": obj.id,
             }
             get_model("template").merge(vals)
     else:
         theme = obj.name
         loaded_modules = module.get_loaded_modules()
         for m in reversed(loaded_modules):
             if not pkg_resources.resource_isdir(
                     m, "themes/" + theme + "/templates"):
                 continue
             for f in pkg_resources.resource_listdir(
                     m, "themes/" + theme + "/templates"):
                 if not f.endswith(".hbs"):
                     continue
                 f2 = f[:-4]
                 print("load template", f2)
                 data = pkg_resources.resource_string(
                     m, "themes/" + theme + "/templates/" + f)
                 vals = {
                     "name": f2,
                     "template": data.decode(),
                     "theme_id": obj.id,
                 }
                 get_model("template").merge(vals)
Пример #10
0
 def load_templates(self, ids, context={}):
     obj = self.browse(ids[0])
     if obj.file:
         zip_path = utils.get_file_path(obj.file)
         zf = zipfile.ZipFile(zip_path)
         for n in zf.namelist():
             if not n.startswith("templates/"):
                 continue
             if not n.endswith(".hbs"):
                 continue
             n2 = n[10:-4]
             if n2.find("..") != -1:
                 continue
             print("load template", n2)
             data = zf.read(n)
             vals = {
                 "name": n2,
                 "template": data.decode(),
                 "theme_id": obj.id,
             }
             get_model("template").merge(vals)
     else:
         theme = obj.name
         loaded_modules = module.get_loaded_modules()
         for m in reversed(loaded_modules):
             if not pkg_resources.resource_isdir(m, "themes/" + theme + "/templates"):
                 continue
             for f in pkg_resources.resource_listdir(m, "themes/" + theme + "/templates"):
                 if not f.endswith(".hbs"):
                     continue
                 f2 = f[:-4]
                 print("load template", f2)
                 data = pkg_resources.resource_string(m, "themes/" + theme + "/templates/" + f)
                 vals = {
                     "name": f2,
                     "template": data.decode(),
                     "theme_id": obj.id,
                 }
                 get_model("template").merge(vals)