예제 #1
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
예제 #2
0
    def check_loop_before(self, m, temp_b=None, temp_a=None):
        """
        :param Optional[List[Before]] temp_b: trail of followed packages this far
        :param Optional[List[After]] temp_a: trail of packages that cannot be encountered,
        as they are prioritized the wrong way
        :param _Module m:
        """
        if m.b_ok:
            return
        if temp_a is None:
            temp_a = []
        else:
            temp_a = temp_a[:]

        if temp_b is None:
            temp_b = []
        else:
            temp_b = temp_b[:]

        if m.m.Name() in temp_a:
            raise DeadLockPrioritizationAfter(temp_b)
        elif m.m.Name() in temp_b:
            raise DeadLockPrioritizationAfter(temp_b)

        new = self.find_triggered_before(m)
        if len(new) == 0:
            [n.mark_before_ok() for n in temp_a]
            return
        else:
            temp_b.append(m)
            [temp_a.append(a) for a in self.find_triggered_after(m.m.Name())]

            for n in new:
                if n.b_ok:
                    continue
                try:
                    self.check_loop_after(n, temp_a, temp_b)
                except DeadLockPrioritizationBefore as dlpb:
                    [
                        p.invalidate_prioritization_before()
                        for p in dlpb.packages
                    ]
                    automatia.Warn(
                        "CLB DEADLOCK in module", n.m.Name(),
                        "being before-prioritized by an earlier module")
                    automatia.Warn(
                        "all modules in this chain will lose specific prioritisation"
                    )
                except DeadLockPrioritizationAfter as dlpa:
                    [
                        p.invalidate_prioritization_after()
                        for p in dlpa.packages
                    ]
                    automatia.Warn(
                        "CLB DEADLOCK in module", n.m.Name(),
                        "referencing after-prioritisation to an "
                        "earlier module")
                    automatia.Warn(
                        "all modules in this chain will lose specific prioritisation"
                    )
예제 #3
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
예제 #4
0
 def Do(self, URL):
     """
     Straightforward, is called once this module can process the url.
     :param string URL:
     :rtype: State
     """
     automatia.Warn("[NOTIMPLEMENTED] module", self.Name(),
                    " has not implemented Do(), skipping...")
     return Continue()
예제 #5
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
예제 #6
0
def alt():
    global args
    if first_arg == "help" or first_arg == "-h":
        print_help()
    elif first_arg == "list":
        packages = resolve.load_packages()
        if len(packages) == 1:
            automatia.Inform("1 package")
        else:
            automatia.Inform(len(packages), "packages")
        automatia.Inform("|{:17s}|{:12s} @ {}".format('FriendlyName', 'Name', 'Path'))
        for p in packages:
            automatia.Inform("|\"{:16s}|\"{:11s} @ '{}'".format(p.m.FriendlyName() + '"', p.m.Name() + '"', p.pp))
    elif first_arg == "remove":
        args.remove("remove")
        packages = resolve.load_packages()
        for a in args:
            for p in packages:
                if p.m.Name() == a or p.m.FriendlyName() == a or p.pp == a:
                    resolve.perm_remove_package(p.pp)
                    automatia.Inform("Removed", p.pp)
                    break

    elif first_arg == "add":
        args.remove("add")
        resolve.load_packages()
        if len(args) == 1 and args[0] == "common":
            args = ["automatia.common.quickyt"]
        for a in args:
            m = resolve.load_package(a)
            if m is None:
                automatia.Warn(a, "is not a valid Automatia package, check debug with '-D' for technical details.")
            else:
                automatia.Inform("Added", a)
                resolve.add_package(a)
    else:
        automatia.Inform('Unknown parameter "{}"'.format(first_arg))
        print_help()
예제 #7
0
 def Name(self):
     """Returns the name of the module"""
     automatia.Warn(
         "[NOTIMPLEMENTED] module has not implemented Name(), skipping...")
     return "undefined"
예제 #8
0
 def Match(self, url):
     """Returns True when this module can process `url`"""
     automatia.Warn("[NOTIMPLEMENTED] module", self.Name(),
                    " has not implemented Match(), skipping...")
     return False