Example #1
0
    def __init__(self, config=None):
        """ Set up queue manager.
        """
        self.config = config or {}
        self.proxy = None
        self.last_start = 0
        self.LOG = pymagic.get_class_logger(self)
        if 'log_level' in self.config:
            self.LOG.setLevel(config.log_level)
        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(
                "[ %s ] [ %s ]" % (config_ini.torque['queue_startable_base'],
                                   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
Example #2
0
 def __init__(self, config_dir=None):
     """ Create loader instance.
     """
     self.config_dir = config_dir or os.path.join(os.path.expanduser("~"),
                                                  ".pyroscope")
     self.LOG = pymagic.get_class_logger(self)
     self._loaded = False
Example #3
0
 def __init__(self, config=None):
     """ Set up filter config.
     """
     self.config = config or {}
     self.LOG = pymagic.get_class_logger(self)
     self.LOG.debug("%s created with config %r" %
                    (self.__class__.__name__, self.config))
Example #4
0
 def __init__(self, config=None):
     """ Set up statistics logger.
     """
     self.config = config or Bunch()
     self.LOG = pymagic.get_class_logger(self)
     self.LOG.debug("Statistics logger created with config %r" %
                    self.config)
Example #5
0
    def __init__(self):
        """ Initialize CLI.
        """
        self.startup = time.time()
        self.LOG = pymagic.get_class_logger(self)

        # Get version number
        self.version = self.VERSION
        if not self.version:
            # Take version from package
            provider = pkg_resources.get_provider(__name__)
            pkg_info = provider.get_metadata("PKG-INFO")

            if not pkg_info:
                pkg_info = "Version: 0.0.0\n"
                try:
                    # Development setup
                    pkg_path = os.path.join(
                        __file__.split(__name__.replace(
                            '.', os.sep))[0],  # containing path
                        __name__.split(".")[0]  # package name
                    )
                    if os.path.exists(pkg_path + ".egg-info"):
                        pkg_path += ".egg-info"
                    else:
                        pkg_path = glob.glob(pkg_path + "-*-py%d.%d.egg-info" %
                                             sys.version_info[:2])
                        if len(pkg_path) == 1:
                            pkg_path = pkg_path[0]
                        else:
                            self.LOG.warn("Found %d candidate versions" %
                                          len(pkg_path))
                            pkg_path = None
                    if pkg_path:
                        with closing(open(os.path.join(pkg_path,
                                                       "PKG-INFO"))) as handle:
                            pkg_info = handle.read()
                    else:
                        self.LOG.warn("Software version cannot be determined!")
                except IOError:
                    self.LOG.warn("Software version cannot be determined!")

            pkg_info = dict(
                line.split(": ", 1) for line in pkg_info.splitlines()
                if ": " in line)
            self.version = pkg_info.get("Version", "DEV")

        self.args = None
        self.options = None
        self.return_code = 0
        self.parser = OptionParser(
            "%prog [options] " + self.ARGS_HELP + "\n\n"
            "%prog " + self.version +
            (", " + self.COPYRIGHT if self.COPYRIGHT else "") + "\n\n" +
            textwrap.dedent(self.__doc__.rstrip()).lstrip('\n') +
            '\n'.join(self.ADDITIONAL_HELP) +
            "\n\nFor more details, see the full documentation at" +
            "\n\n    https://pyrocore.readthedocs.io/",
            version="%prog " + self.version)
Example #6
0
 def __init__(self, filename, datapath=None):
     """ Initialize metafile.
     """
     self.filename = filename
     self.progress = None
     self.datapath = datapath
     self.ignore = self.IGNORE_GLOB[:]
     self.LOG = pymagic.get_class_logger(self)
Example #7
0
 def __init__(self, filename, datapath=None):
     """ Initialize metafile.
     """
     self.filename = filename
     self.progress = None
     self.datapath = datapath
     self.ignore = self.IGNORE_GLOB[:]
     self.LOG = pymagic.get_class_logger(self)
Example #8
0
    def __init__(self, config=None):
        """ Set up statistics logger.
        """
        self.config = config or Bunch()
        self.influxdb = Bunch(config_ini.influxdb)
        self.influxdb.timeout = float(self.influxdb.timeout or '0.250')

        self.LOG = pymagic.get_class_logger(self)
        self.LOG.debug("InfluxDB statistics feed created with config %r" % self.config)
Example #9
0
    def __init__(self, config=None):
        """ Set up InfluxDB logger.
        """
        self.config = config or Bunch()
        self.influxdb = Bunch(config_ini.influxdb)
        self.influxdb.timeout = float(self.influxdb.timeout or '0.250')

        self.LOG = pymagic.get_class_logger(self)
        self.LOG.debug("InfluxDB statistics feed created with config %r" % self.config)
Example #10
0
    def __init__(self):
        """ Initialize CLI.
        """
        self.startup = time.time()
        self.LOG = pymagic.get_class_logger(self)

        # Get version number
        self.version = self.VERSION
        if not self.version:
            # Take version from package
            provider = pkg_resources.get_provider(__name__)
            pkg_info = provider.get_metadata("PKG-INFO")

            if not pkg_info:
                pkg_info = "Version: 0.0.0\n"
                try:
                    # Development setup
                    pkg_path = os.path.join(
                        __file__.split(__name__.replace('.', os.sep))[0], # containing path
                        __name__.split(".")[0] # package name
                    )
                    if os.path.exists(pkg_path + ".egg-info"):
                        pkg_path += ".egg-info"
                    else:
                        pkg_path = glob.glob(pkg_path + "-*-py%d.%d.egg-info" % sys.version_info[:2])
                        if len(pkg_path) == 1:
                            pkg_path = pkg_path[0]
                        else:
                            self.LOG.warn("Found %d candidate versions" % len(pkg_path))
                            pkg_path = None
                    if pkg_path:
                        with closing(open(os.path.join(pkg_path, "PKG-INFO"))) as handle:
                            pkg_info = handle.read()
                    else:
                        self.LOG.warn("Software version cannot be determined!")
                except IOError:
                    self.LOG.warn("Software version cannot be determined!")

            pkg_info = dict(line.split(": ", 1)
                for line in pkg_info.splitlines()
                if ": " in line
            )
            self.version = pkg_info.get("Version", "DEV")

        self.args = None
        self.options = None
        self.return_code = 0
        self.parser = OptionParser(
            "%prog [options] " + self.ARGS_HELP + "\n\n"
            "%prog " + self.version + (", " + self.COPYRIGHT if self.COPYRIGHT else "") + "\n\n"
            + textwrap.dedent(self.__doc__.rstrip()).lstrip('\n')
            + '\n'.join(self.ADDITIONAL_HELP),
            version="%prog " + self.version)
Example #11
0
    def __init__(self, paths, fileapp=None, **kw):
        self.LOG = pymagic.get_class_logger(self)
        self.paths = []
        self.fileapp = fileapp or static.FileApp
        self.fileapp_kw = kw

        for path in paths:
            path = os.path.abspath(path).rstrip(os.path.sep) + os.path.sep
            if os.path.isdir(path):
                self.paths.append(path)
            else:
                self.LOG.warn("Static HTTP directory %r not found, ignoring it" % path)
Example #12
0
    def __init__(self, paths, fileapp=None, **kw):
        self.LOG = pymagic.get_class_logger(self)
        self.paths = []
        self.fileapp = fileapp or static.FileApp
        self.fileapp_kw = kw

        for path in paths:
            path = os.path.abspath(path).rstrip(os.path.sep) + os.path.sep
            if os.path.isdir(path):
                self.paths.append(path)
            else:
                self.LOG.warn(
                    "Static HTTP directory %r not found, ignoring it" % path)
Example #13
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 #14
0
    def __init__(self, url, mapping=None):
        self.LOG = pymagic.get_class_logger(self)
        self._url = url
        self._transport = xmlrpc2scgi.transport_from_url(url)
        self._versions = ("", "")
        self._version_info = ()
        self._use_deprecated = True
        self._mapping = mapping or config.xmlrpc
        self._fix_mappings()

        # Statistics (traffic w/o HTTP overhead)
        self._requests = 0
        self._outbound = 0L
        self._outbound_max = 0L
        self._inbound = 0L
        self._inbound_max = 0L
        self._latency = 0.0
        self._net_latency = 0.0
Example #15
0
    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()
Example #16
0
    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
Example #17
0
    def __init__(self, url, mapping=None):
        self.LOG = pymagic.get_class_logger(self)
        self._url = os.path.expandvars(url)
        try:
            self._transport = xmlrpc2scgi.transport_from_url(self._url)
        except socket.gaierror as exc:
            raise XmlRpcError("Bad XMLRPC URL {0}: {1}", self._url, exc)
        self._versions = ("", "")
        self._version_info = ()
        self._use_deprecated = True
        self._mapping = mapping or config.xmlrpc
        self._fix_mappings()

        # Statistics (traffic w/o HTTP overhead)
        self._requests = 0
        self._outbound = 0
        self._outbound_max = 0
        self._inbound = 0
        self._inbound_max = 0
        self._latency = 0.0
        self._net_latency = 0.0
Example #18
0
    def __init__(self):
        """ Initialize CLI.
        """
        self.startup = time.time()
        self.LOG = pymagic.get_class_logger(self)

        # Get version number
        self.version = self.VERSION
        if not self.version:
            # Take version from package
            provider = pkg_resources.get_provider(__name__)
            pkg_meta = (provider.get_metadata("PKG-INFO")
                        or provider.get_metadata("METADATA")
                        or self._get_pkg_meta())
            pkg_dict = dict(
                line.split(": ", 1) for line in pkg_meta.splitlines()
                if ": " in line)
            self.version = pkg_dict.get("Version", "DEV")

        where = os.path.commonprefix(
            [__file__, os.path.realpath(sys.argv[0]), sys.prefix])
        where = (where + os.sep).replace(os.path.expanduser('~' + os.sep),
                                         '~' + os.sep).rstrip(os.sep)
        self.version_info = '{}{}{} on Python {}'.format(
            self.version, ' from ' if where else '', where,
            sys.version.split()[0])

        self.args = None
        self.options = None
        self.return_code = 0
        self.parser = OptionParser(
            "%prog [options] " + self.ARGS_HELP + "\n\n"
            "%prog " + self.version_info +
            ('\n' + self.COPYRIGHT if self.COPYRIGHT else "") + "\n\n" +
            textwrap.dedent(self.__doc__.rstrip()).lstrip('\n') +
            '\n'.join(self.ADDITIONAL_HELP) +
            "\n\nFor more details, see the full documentation at" +
            "\n\n    https://pyrocore.readthedocs.io/",
            version="%prog " + self.version_info)
Example #19
0
 def __init__(self):
     self.LOG = pymagic.get_class_logger(self)
     self.routes = []
Example #20
0
 def __init__(self, config=None):
     """ Set up statistics logger.
     """
     self.config = config or Bunch()
     self.LOG = pymagic.get_class_logger(self)
     self.LOG.debug("Statistics logger created with config %r" % self.config)
Example #21
0
 def __init__(self):
     """ Initialize torrent backend engine.
     """
     self.LOG = pymagic.get_class_logger(self)
     self.engine_id = "N/A"  # ID of the instance we're connecting to
     self.engine_software = "N/A"  # Name and version of software
Example #22
0
 def __init__(self):
     self.LOG = pymagic.get_class_logger(self)
     self.routes = []
Example #23
0
 def __init__(self):
     """ Initialize torrent backend engine.
     """
     self.LOG = pymagic.get_class_logger(self)
     self.engine_id = "N/A"          # ID of the instance we're connecting to
     self.engine_software = "N/A"    # Name and version of software
Example #24
0
 def __init__(self, config=None):
     """ Set up remote watcher.
     """
     self.config = config or {}
     self.LOG = pymagic.get_class_logger(self)
     self.LOG.debug("Remote watcher created with config %r" % self.config)
Example #25
0
 def __init__(self, **kwargs):
     self.LOG = pymagic.get_class_logger(self)
     self.cfg = Bunch(kwargs)
Example #26
0
 def test_get_class_logger(self):
     logger = pymagic.get_class_logger(self)
     assert logger.name == "tests.test_pymagic.LogTest"
Example #27
0
 def __init__(self, config=None):
     """ Set up remote watcher.
     """
     self.config = config or {}
     self.LOG = pymagic.get_class_logger(self)
     self.LOG.debug("Remote watcher created with config %r" % self.config)
Example #28
0
 def __init__(self, **kwargs):
     self.LOG = pymagic.get_class_logger(self)
     self.cfg = Bunch(kwargs)
Example #29
0
 def __init__(self, config_dir=None):
     """ Create loader instance.
     """
     self.config_dir = config_dir or os.path.join(os.path.expanduser("~"), ".pyroscope")
     self.LOG = pymagic.get_class_logger(self)
     self._loaded = False
Example #30
0
 def test_get_class_logger(self):
     logger = pymagic.get_class_logger(self)
     assert logger.name == "tests.test_pymagic.LogTest"