예제 #1
0
    def resolve_priority(self):
        result = self.Priority()
        if not isinstance(result, tuple):
            result = (result, )

        p_num = 0
        a = []
        b = []

        automatia.Debug(self.Name(), "priority output:", result)

        for r in result:
            if isinstance(r, (int, str)):
                p_num = r
            elif isinstance(r, priority.After):
                if r.multi:
                    [a.append(A) for A in r.after]
                else:
                    a.append(r)
            elif isinstance(r, priority.Before):
                if r.multi:
                    [b.append(B) for B in r.before]
                else:
                    b.append(r)
            else:
                automatia.Warn("found unknown type", type(r), "from module",
                               self.Name(), "while resolving "
                               "priorities.")
        return p_num, a, b
예제 #2
0
def check_packages(packages):
    """

    :param dict[str, bool] packages:
    :rtype: list[_Module]
    """

    modules = []
    for package, off in packages.items():
        M = load_package(package)
        if M is None:
            if off:
                continue
            automatia.Warn(
                package,
                "has failed to load, possibly this module has been removed, or a faulty version "
                "has been installed")
            automatia.Warn(package,
                           "will now be removed from the module list.")
            remove_package(package)
        else:
            if not off:
                add_package(package)
                automatia.Debug("found package", package, "again")
            modules.append(M)
    return modules
예제 #3
0
def load_package(package):
    try:
        m = load_module(package)
        i = m.a()
        if not isinstance(i, automatia.AutomatiaModule):
            raise TypeError
        return _Module(i, package)
    except ImportError:
        automatia.Debug(package, "ImportError")
        return None
    except AttributeError:
        automatia.Debug(package, "AttributeError")
        return None
    except KeyError:
        automatia.Debug(package, "KeyError")
        return None
    except TypeError:
        automatia.Debug(package, "TypeError")
        return None
예제 #4
0
    def do(self, m):
        """:param _Module m:"""
        if m.ischecked():
            return

        automatia.Debug("Module:", m.m.FriendlyName())

        for a in m.a:
            automatia.Debug("[NEEDAFTER]", a)
            if not self.hasrun(a):
                return

        if self.trigger_before(m.m.Name()):
            self.innerloop(self.find_triggered_before(m.m.Name()), m.m.Name())

        r = m.check(self._param.get())

        if r:
            automatia.Debug("Running module", m, "with", self._param.get())
            automatia.Inform("Resolving", self._param.get(),
                             'with "{}"'.format(m.Name()))
            result = m.do(self._param.get())
            if not isinstance(result, State):
                automatia.Warn(m, "has returned an non-State object:", result)
                automatia.Warn("Automatia will now exit out of precaution")
                raise automatia.FinishFinal
            else:
                if isinstance(result, Finish):
                    raise automatia.FinishFinal
                elif isinstance(result, Result):
                    raise automatia.FinishResult(result.get(), m)
                elif isinstance(result, Continue):
                    return
                elif isinstance(result, Fail):
                    automatia.Error(m, "has returned a Fail")
                    automatia.Error(">", result.explain())
                    automatia.Error()
                    automatia.Error("Exiting...")
                    raise automatia.FinishNow
        else:
            if self.trigger_after(m.m.Name()):
                self.reset()
                raise ReturnToMainLoop
예제 #5
0
def main():
    automatia.setcli()

    print("########### AUTOMATIA CLI")

    if first_arg is None:
        automatia.Debug("No first arg")
        print_help()
        return
    elif not util.is_url(first_arg):
        automatia.Debug("First arg not an url")
        alt()
        return

    params = param.make_params(sys.argv)

    packages = resolve.load_packages()
    s = shelf.Shelf()
    s.walk(packages)
    automatia.Debug("Modules:", s)
    automatia.Debug("Params", params)

    def do(p):
        try:
            s.run(p)
        except automatia.FinishNow:
            exit(1)
        except automatia.FinishFinal:
            return
        except automatia.FinishResult as fr:
            if reflect.BoolQuery('"{}" wants to re-issue a new URL: "{}"\nRe-issue new URL?'.format(fr.m.Name(),
                                                                                                    fr.URL), True):
                do(param.Param(fr.URL, p.cmds[:]))

    try:
        for p in params:
            do(p)
    except KeyboardInterrupt:
        print(" ")
        automatia.Inform("Interrupted by user")
        exit(0)

    automatia.Debug("Finished")
예제 #6
0
    def register_triggers(self, after, before):
        """
        :param list[After] after:
        :param list[Before] before:
        """

        automatia.Debug("register_triggers:", after, before)

        for a in after:
            if a.after not in self.triggers["after"]:
                self.triggers["after"].append(a.after)

        for b in before:
            if b.before not in self.triggers["before"]:
                self.triggers["before"].append(b.before)
예제 #7
0
def load_packages():
    global installed_packages
    global resolved_packages

    try:
        with open(home + "/.automatia/modlist.json") as jsonfile:
            data = json.load(jsonfile)
    except IOError:
        data = {}

    automatia.Debug("modlist.json:", data)

    installed_packages = data or dict()

    resolved_packages = check_packages(installed_packages)
    return resolved_packages
예제 #8
0
 def hasrun(self, package):
     for m in self._all:
         automatia.Debug("[CHECKAGAINST]", m)
         if package.isafter(m.m.Name()):
             return m.ischecked()
     return package not in self._names
예제 #9
0
 def reset(self):
     automatia.Debug("Reset Cursor")
     self.y_cur = None
     self.x_cur = 0
예제 #10
0
 def innerloop(self, modules=list(), name=""):
     for m in modules:
         automatia.Debug("[BEFORE]", m.m.Name(),
                         "requested priority before", name)
         self.do(m)