Example #1
0
 def add_resolved_remote_dep(self, dep):
     # print(colored("New remote dep! {}, type: {}".format(dep, type(dep)), "green"))
     if isinstance(dep, dict):
         k = list(dep.keys())[0]
         proxy_lst = []
         try:
             if isinstance(dep[k], list):
                 for u in dep[k]:
                     if u not in self._resolved_remote_deps:
                         (name, _, _) = utils.uri_split(u)
                         proxy_lst.append(
                             utils.get_pyro4proxy(u,
                                                  name.split(".")[0]))
                         self._resolved_remote_deps.append(u)
                 if k in self.deps and isinstance(self.deps[k], list):
                     self.deps[k].extend(proxy_lst)
                 else:
                     self.deps[k] = proxy_lst
             else:
                 if dep[k] not in self._resolved_remote_deps:
                     (name, _, _) = utils.uri_split(dep[k])
                     self.deps[k] = utils.get_pyro4proxy(
                         dep[k],
                         name.split(".")[0])
                     self._resolved_remote_deps.append(dep[k])
             if self._unr_remote_deps is not None:
                 if k in self._unr_remote_deps:
                     self._unr_remote_deps.remove(k)
         except Exception as ex:
             template = "[control.add_resolved_remote_dep()] An exception of type {0} occurred. Arguments:\n{1!r}"
             print(template.format(type(ex).__name__, ex.args))
         self.check_remote_deps()
     else:
         print("Error in control.add_resolved_remote_dep(): No dict", dep)
Example #2
0
 def get_proxy_without_uri(self, obj, passw=None):
     target = obj.split(".")
     if (target[0] and target[1] and target[0].count("*") == 0
             and target[1].count("*") == 0):
         if passw is None:
             passw = target[0]
         try:
             Pyro4.config.BROADCAST_ADDRS = self.broadcast_ns
             ns = Pyro4.locateNS()
             proxy = utils.get_pyro4proxy(ns.lookup(target[0]), passw)
             bot_uris = proxy.get_uris()
             for x in bot_uris:
                 (name, ip, port) = utils.uri_split(x)
                 if name.split(".")[1] == target[1]:
                     proxy = utils.get_pyro4proxy(x, passw)
                     return proxy
         except Exception:
             # print "Error al resolver ", obj
             raise
     else:
         if self.usingBB:
             # TODO: var ns is not initialized here
             ns.proxy(target, passw)
         else:
             print(
                 colored(
                     "--- Para usar esta funcionalidad se necesita de BigBrother ---",
                     "red"))
             return None
     return None
Example #3
0
    def start_pyro4bot_object(self, d, proc_pipe):
        """Start PYRO4BOT component."""
        (name_ob, ip, ports) = utils.uri_split(d["pyro4id"])
        try:
            # Daemon proxy for sensor
            daemon = Pyro4.Daemon(host=ip,
                                  port=utils.get_free_port(ports, ip=ip))
            daemon._pyroHmacKey = self.node["password"].encode()

            proc_pipe.send("CONTINUE")
            deps = utils.prepare_proxys(d, self.node["password"])

            # assinging tty out and err for object
            default_tty = utils.get_tty()
            utils.set_tty_err(d["tty_err"])

            # Preparing class for pyro4
            pyro4bot_class = control.Pyro4bot_Loader(globals()[d["cls"]],
                                                     **deps)
            new_object = pyro4bot_class()

            # Associate object to the daemon
            uri = daemon.register(new_object, objectId=name_ob)

            # Get and save exposed methods
            exposed = Pyro4.core.DaemonObject(daemon).get_metadata(
                name_ob, True)

            # Hide methods from Control
            safe_exposed = {}
            for k in exposed.keys():
                safe_exposed[k] = list(
                    set(exposed[k]) - set(dir(control.Control)))
            safe_exposed["methods"].extend(["__docstring__", "__exposed__"])
            new_object.exposed.update(safe_exposed)

            setproctitle.setproctitle("PYRO4BOT." + name_ob)
            # Save dosctring documentation inside sensor object
            new_object.docstring.update(
                self.get_docstring(new_object, safe_exposed))

            daemon.requestLoop()
            # getting tty default to exit
            utils.set_tty_out(default_tty)
            utils.set_tty_err(default_tty)

            print("[%s] Shutting %s" %
                  (colored("Down", 'green'), d["pyro4id"]))
        except Exception as e:
            proc_pipe.send("FAIL")
            print("ERROR: creating sensor robot object: " + d["pyro4id"])
            print(utils.format_exception(e))
Example #4
0
 def get_proxy(self, obj, passw=None):
     if isinstance(obj, basestring):
         obj = [obj]
     if (self.get_ns()):
         for d in obj:
             try:
                 if (d.count('PYRO:') == 1 and d.count('@') == 1 and
                         d.count(":") == 2 and d.count(".") in range(3, 5)):
                     (name, _, _) = utils.uri_split(d)
                     if ("." in name):
                         name = name.split(".")[0]
                     if (passw is None):
                         passw = name
                     return utils.get_pyro4proxy(d, passw)
                 elif (d.count(".") == 1):  # simplebot.component
                     return (self.get_proxy_without_uri(d, passw))
                 else:
                     print "Objeto no valido"
             except Exception:
                 return None