示例#1
0
 def __init__(self, meta, var, name=None, tmpdir=None, recursion_path=None, set_os_environ=True):
     # Don't put the empty list directly in the function definition
     # as default arguments, as modifications of this "empty" list
     # will be done in-place so that it will not be truly empty
     # next time
     if recursion_path is None:
         recursion_path = []
     recursion_path.append(var)
     funcimports = {}
     for func in (meta.get_flag(var, "import", oelite.meta.FULL_EXPANSION) or "").split():
         # print "importing func", func
         if func in funcimports:
             continue
         if func in recursion_path:
             raise Exception("circular import %s -> %s" % (recursion_path, func))
         python_function = PythonFunction(meta, func, tmpdir=tmpdir, recursion_path=recursion_path)
         funcimports[func] = python_function.function
     g = meta.get_pythonfunc_globals()
     g.update(funcimports)
     l = {}
     self.code = meta.get_pythonfunc_code(var)
     eval(self.code, g, l)
     self.function = l[var]
     self.set_os_environ = set_os_environ
     super(PythonFunction, self).__init__(meta, var, name, tmpdir)
     return
示例#2
0
文件: function.py 项目: kimrhh/core
 def __init__(self, meta, var, name=None, tmpdir=None, recursion_path=None,
              set_os_environ=True):
     # Don't put the empty list directly in the function definition
     # as default arguments, as modifications of this "empty" list
     # will be done in-place so that it will not be truly empty
     # next time
     if recursion_path is None:
         recursion_path = []
     recursion_path.append(var)
     funcimports = {}
     for func in (meta.get_flag(var, "import",
                                oelite.meta.FULL_EXPANSION)
                  or "").split():
         #print "importing func", func
         if func in funcimports:
             continue
         if func in recursion_path:
             raise Exception("circular import %s -> %s"%(recursion_path, func))
         python_function = PythonFunction(meta, func, tmpdir=tmpdir,
                                          recursion_path=recursion_path)
         funcimports[func] = python_function.function
     g = meta.get_pythonfunc_globals()
     g.update(funcimports)
     l = {}
     self.code = meta.get_pythonfunc_code(var)
     eval(self.code, g, l)
     self.function = l[var]
     self.set_os_environ = set_os_environ
     super(PythonFunction, self).__init__(meta, var, name, tmpdir)
     return
示例#3
0
文件: task.py 项目: kimrhh/core
    def meta(self):
        if self._meta is not None:
            return self._meta
        meta = self.recipe.meta.copy()
        # Filter meta-data, enforcing restrictions on which tasks to
        # emit vars to and not including other task functions.
        emit_prefixes = (meta.get("META_EMIT_PREFIX") or "").split()

        def colon_split(s):
            import string

            return string.split(s, ":", 1)

        emit_prefixes = map(colon_split, emit_prefixes)
        for var in meta.keys():
            emit_flag = meta.get_flag(var, "emit")
            emit = (emit_flag or "").split()
            taskfunc_match = self.TASKFUNC_RE.match(var)
            if taskfunc_match:
                if taskfunc_match.group(0) not in emit:
                    emit.append(taskfunc_match.group(0))
            for emit_task, emit_prefix in emit_prefixes:
                if not var.startswith(emit_prefix):
                    continue
                if emit_task == "":
                    if emit_flag is None:
                        emit_flag = ""
                    continue
                if not emit_task.startswith("do_"):
                    emit_task = "do_" + emit_task
                if not emit_task in emit:
                    emit.append(emit_task)
            if (emit or emit_flag == "") and not self.name in emit:
                del meta[var]
                continue
            omit = meta.get_flag(var, "omit")
            if omit is not None and self.name in omit.split():
                del meta[var]
                continue

        self._meta = meta
        return meta
示例#4
0
    def meta(self):
        if self._meta is not None:
            return self._meta
        meta = self.recipe.meta.copy()
        # Filter meta-data, enforcing restrictions on which tasks to
        # emit vars to and not including other task functions.
        emit_prefixes = (meta.get("META_EMIT_PREFIX") or "").split()

        def colon_split(s):
            import string
            return string.split(s, ":", 1)

        emit_prefixes = map(colon_split, emit_prefixes)
        for var in meta.keys():
            emit_flag = meta.get_flag(var, "emit")
            emit = (emit_flag or "").split()
            taskfunc_match = self.TASKFUNC_RE.match(var)
            if taskfunc_match:
                if taskfunc_match.group(0) not in emit:
                    emit.append(taskfunc_match.group(0))
            for emit_task, emit_prefix in emit_prefixes:
                if not var.startswith(emit_prefix):
                    continue
                if emit_task == "":
                    if emit_flag is None:
                        emit_flag = ""
                    continue
                if not emit_task.startswith("do_"):
                    emit_task = "do_" + emit_task
                if not emit_task in emit:
                    emit.append(emit_task)
            if (emit or emit_flag == "") and not self.name in emit:
                del meta[var]
                continue
            omit = meta.get_flag(var, "omit")
            if omit is not None and self.name in omit.split():
                del meta[var]
                continue

        self._meta = meta
        return meta
示例#5
0
    def filter_meta(self):
        meta = self._meta
        assert (meta is not None)
        # Filter meta-data, enforcing restrictions on which tasks to
        # emit vars to and not including other task functions.
        emit_prefixes = (meta.get("META_EMIT_PREFIX") or "").split()

        def emit_prefix_pair(s):
            task, prefix = s.split(":", 1)
            if task:
                task = "do_" + task
            return (task, prefix)

        # To avoid looping over the entire ~20 element list of pairs
        # for every variable, split that list according to the first
        # character of the prefix, and fetch the appropriate list
        # based on var[0].
        emit_prefix_table = {}
        for s in emit_prefixes:
            p = emit_prefix_pair(s)
            c = p[1][0]
            if c in emit_prefix_table:
                emit_prefix_table[c].append(p)
            else:
                emit_prefix_table[c] = [p]
        for var in meta.keys():
            emit_flag = meta.get_flag(var, "emit")
            emit = (emit_flag or "").split()
            taskfunc_match = self.TASKFUNC_RE.match(var)
            if taskfunc_match:
                emit.append(taskfunc_match.group(0))
            for emit_task, emit_prefix in emit_prefix_table.get(var[0], []):
                if not var.startswith(emit_prefix):
                    continue
                if emit_task == "":
                    if emit_flag is None:
                        emit_flag = ""
                    continue
                emit.append(emit_task)
            if (emit or emit_flag == "") and not self.name in emit:
                del meta[var]
                continue
示例#6
0
 def filter_meta(self):
     meta = self._meta
     assert(meta is not None)
     # Filter meta-data, enforcing restrictions on which tasks to
     # emit vars to and not including other task functions.
     emit_prefixes = (meta.get("META_EMIT_PREFIX") or "").split()
     def emit_prefix_pair(s):
         task, prefix = s.split(":", 1)
         if task:
             task = "do_" + task
         return (task, prefix)
     # To avoid looping over the entire ~20 element list of pairs
     # for every variable, split that list according to the first
     # character of the prefix, and fetch the appropriate list
     # based on var[0].
     emit_prefix_table = {}
     for s in emit_prefixes:
         p = emit_prefix_pair(s)
         c = p[1][0]
         if c in emit_prefix_table:
             emit_prefix_table[c].append(p)
         else:
             emit_prefix_table[c] = [p]
     for var in meta.keys():
         emit_flag = meta.get_flag(var, "emit")
         emit = (emit_flag or "").split()
         taskfunc_match = self.TASKFUNC_RE.match(var)
         if taskfunc_match:
             emit.append(taskfunc_match.group(0))
         for emit_task, emit_prefix in emit_prefix_table.get(var[0], []):
             if not var.startswith(emit_prefix):
                 continue
             if emit_task == "":
                 if emit_flag is None:
                     emit_flag = ""
                 continue
             emit.append(emit_task)
         if (emit or emit_flag == "") and not self.name in emit:
             del meta[var]
             continue