Example #1
0
    def open(self):
        """ Open connection.
        """
        # Only connect once
        if self._rpc is not None:
            return self._rpc

        # Get connection URL from rtorrent.rc
        self.load_config()

        # Reading abilities are on the downfall, so...
        if not config.scgi_url:
            raise error.UserError(
                "You need to configure a XMLRPC connection, read"
                " https://pyrocore.readthedocs.io/en/latest/setup.html")

        # Connect and get instance ID (also ensures we're connectable)
        self._rpc = xmlrpc.RTorrentProxy(config.scgi_url)
        self.versions, self.version_info = self._rpc._set_mappings()
        self.engine_id = self._rpc.session.name()
        time_usec = self._rpc.system.time_usec()

        # Make sure xmlrpc-c works as expected
        if time_usec < 2**32:
            self.LOG.warn(
                "Your xmlrpc-c is broken (64 bit integer support missing,"
                " %r returned instead)" % (type(time_usec), ))

        # Get other manifest values
        self.engine_software = "rTorrent %s/%s" % self.versions

        if "+ssh:" in config.scgi_url:
            self.startup = int(self._rpc.system.startup_time() or time.time())
        else:
            self._session_dir = self._rpc.session.path()
            if not self._session_dir:
                raise error.UserError(
                    "You need a session directory, read"
                    " https://pyrocore.readthedocs.io/en/latest/setup.html")
            if not os.path.exists(self._session_dir):
                raise error.UserError("Non-existing session directory %r" %
                                      self._session_dir)
            self._download_dir = os.path.expanduser(
                self._rpc.directory.default())
            if not os.path.exists(self._download_dir):
                raise error.UserError("Non-existing download directory %r" %
                                      self._download_dir)
            self.startup = os.path.getmtime(
                os.path.join(self._session_dir, "rtorrent.lock"))

        # Return connection
        self.LOG.debug(repr(self))
        return self._rpc
Example #2
0
 def open(self):
     """Open connection and return proxy."""
     if not self.proxy:
         if not config.scgi_url:
             config.engine.load_config()
         if not config.scgi_url:
             self.LOG.error(
                 "You need to configure a XMLRPC connection, read"
                 " https://pyrocore.readthedocs.io/en/latest/setup.html")
         self.proxy = xmlrpc.RTorrentProxy(config.scgi_url)
         self.proxy._set_mappings()
     return self.proxy
Example #3
0
    def __init__(self, config=None):
        self.config = config or {}
        self.LOG = pymagic.get_class_logger(self)
        if 'log_level' in self.config:
            self.LOG.setLevel(config.log_level)
        self.LOG.debug("Tree watcher created with config %r" % self.config)

        self.manager = None
        self.handler = None
        self.notifier = None

        bool_param = lambda key, default: matching.truth(
            self.config.get(key, default), "job.%s.%s" %
            (self.config.job_name, key))

        if not self.config.path:
            raise error.UserError(
                "You need to set 'job.%s.path' in the configuration!" %
                self.config.job_name)

        self.config.quiet = bool_param("quiet", False)
        self.config.queued = bool_param("queued", False)
        self.config.trace_inotify = bool_param("trace_inotify", False)

        self.config.path = set([
            os.path.abspath(os.path.expanduser(path.strip()).rstrip(os.sep))
            for path in self.config.path.split(os.pathsep)
        ])
        for path in self.config.path:
            if not os.path.isdir(path):
                raise error.UserError("Path '%s' is not a directory!" % path)

        # Assemble custom commands
        self.custom_cmds = {}
        for key, val in self.config.items():
            if key.startswith("cmd."):
                _, key = key.split('.', 1)
                if key in self.custom_cmds:
                    raise error.UserError(
                        "Duplicate custom command definition '%s'"
                        " (%r already registered, you also added %r)!" %
                        (key, self.custom_cmds[key], val))
                self.custom_cmds[key] = formatting.preparse(val)
        self.LOG.debug("custom commands = %r" % self.custom_cmds)

        # Get client proxy
        self.proxy = xmlrpc.RTorrentProxy(configuration.scgi_url)
        self.proxy._set_mappings()  # pylint: disable=W0212

        if self.config.active:
            self.setup()
Example #4
0
                except (ValueError, TypeError), exc:
                    self.LOG.warn("Not a valid number: %r (%s)" % (arg, exc))
            elif arg and arg[0] == '[':
                arg = arg[1:].split(',')
                if all(i.isdigit() for i in arg):
                    arg = [int(i, 10) for i in arg]
            args.append(arg)

        # Open proxy
        if not config.scgi_url:
            config.engine.load_config()
        if not config.scgi_url:
            self.LOG.error(
                "You need to configure a XMLRPC connection, read"
                " http://code.google.com/p/pyroscope/wiki/UserConfiguration")
        proxy = xmlrpc.RTorrentProxy(config.scgi_url)
        proxy._set_mappings()

        # Make the call
        try:
            result = getattr(proxy, method)(raw_xml=self.options.xml,
                                            *tuple(args))
        except xmlrpc.ERRORS, exc:
            self.LOG.error("While calling %s(%s): %s" %
                           (method, ", ".join(repr(i) for i in args), exc))
            self.return_code = error.EX_NOINPUT if "not find" in getattr(
                exc, "faultString", "") else error.EX_DATAERR
        else:
            if not self.options.quiet:
                if self.options.repr:
                    # Pretty-print if requested, or it's a collection and not a scalar