コード例 #1
0
ファイル: watch.py プロジェクト: 01100001/pyroscope
    def __init__(self, config=None):
        self.config = config or {}
        self.LOG = pymagic.get_class_logger(self)
        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()
コード例 #2
0
ファイル: queue.py プロジェクト: 01100001/pyroscope
    def __init__(self, config=None):
        """ Set up queue manager.
        """
        self.config = config or {}
        self.proxy = None
        self.LOG = pymagic.get_class_logger(self)
        self.LOG.debug("Queue manager created with config %r" % self.config)

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

        self.config.quiet = bool_param("quiet", False)
        self.config.startable = matching.ConditionParser(engine.FieldDefinition.lookup, "name").parse(
            "is_open=0 is_active=0 is_complete=0 [ %s ]" % self.config.startable
        )
        self.LOG.info("Startable matcher for '%s' is: [ %s ]" % (self.config.job_name, self.config.startable))
        self.config.downloading = matching.ConditionParser(engine.FieldDefinition.lookup, "name").parse(
            "is_active=1 is_complete=0" + (" [ %s ]" % self.config.downloading if "downloading" in self.config else "")
        )
        self.LOG.info("Downloading matcher for '%s' is: [ %s ]" % (self.config.job_name, self.config.downloading))
        self.sort_key = formatting.validate_sort_fields(self.config.sort_fields) if self.config.sort_fields.strip() else None