Ejemplo n.º 1
0
 def rjson(mo):
     if mo.group(2).startswith('_attachments'):
         # someone  want to include from attachments
         path = os.path.join(app_dir, mo.group(2).strip())
         filenum = 0
         for filename in glob.iglob(path):
             logger.debug("process json macro: %s" % filename)
             library = ''
             try:
                 if filename.endswith('.json'):
                     library = util.read_json(filename)
                 else:
                     library = util.read(filename)
             except IOError, e:
                 raise MacroError(str(e))
             filenum += 1
             current_file = filename.split(app_dir)[1]
             fields = current_file.split('/')
             count = len(fields)
             include_to = included
             for i, field in enumerate(fields):
                 if i + 1 < count:
                     include_to[field] = {}
                     include_to = include_to[field]
                 else:
                     include_to[field] = library
         if not filenum:
             raise MacroError("Processing code: No file matching '%s'" %
                              mo.group(2))
Ejemplo n.º 2
0
 def rreq(mo):
     # just read the file and return it
     path = os.path.join(app_dir, mo.group(2).strip())
     library = ''
     filenum = 0
     for filename in glob.iglob(path):
         logger.debug("process code macro: %s" % filename)
         try:
             cnt = util.read(filename)
             if cnt.find("!code") >= 0:
                 cnt = run_code_macros(cnt, app_dir)
             library += cnt
         except IOError, e:
             raise MacroError(str(e))
         filenum += 1
Ejemplo n.º 3
0
def apply_lib(doc, funcs, app_dir, objs):
    for k, v in funcs.items():
        if not isinstance(v, basestring):
            continue
        else:
            logger.debug("process function: %s" % k)
            old_v = v
            try:
                funcs[k] = run_json_macros(doc, run_code_macros(v, app_dir),
                                           app_dir)
            except ValueError, e:
                raise MacroError("Error running !code or !json on " +
                                 "function \"%s\": %s" % (k, e))
            if old_v != funcs[k]:
                objs[md5(util.to_bytestring(funcs[k])).hexdigest()] = old_v