Exemplo n.º 1
0
 def _gen_fileconfig(self):
     config = OrderedDict({self.SELF_SECTION: OrderedDict()})
     for name, item in self.loweritems():
         if self.is_section(name):
             fc = self._to_fileconfig(item, name)
             config.update(fc)
         else:
             fv = self._to_filevalue(item.get())
             config[self.SELF_SECTION][name] = fv
     return config
Exemplo n.º 2
0
 def _to_fileconfig(self, section, section_name):
     config = OrderedDict()
     for name, item in section.loweritems():
         if section.is_section(name):
             sub_name = '{0}{1}{2}'.format(section_name, self.SECTION_SEP,
                                           name)
             fc = self._to_fileconfig(item, sub_name)
             config.update(fc)
         else:
             fv = self._to_filevalue(item.get())
             config.setdefault(section_name, OrderedDict())[name] = fv
     return config
Exemplo n.º 3
0
    def get_all_packages(self, root=None, owner=None, tags=None):
        """
        Return dict with package information

        :param root: optional root to filter
        :param owner: optional user id
        :param tags: optional tag list
        """
        qry = (
            'SELECT pid, name, folder, root, owner, site, comment, password, '
            'added, tags, status, shared, packageorder FROM packages{} '
            'ORDER BY root, packageorder')

        if root is None:
            stats = self.get_package_stats(owner=owner)
            if owner is None:
                self.c.execute(qry.format(""))
            else:
                self.c.execute(qry.format(" WHERE owner=?"), (owner, ))
        else:
            stats = self.get_package_stats(root=root, owner=owner)
            if owner is None:
                self.c.execute(qry.format(' WHERE root=? OR pid=?'),
                               (root, root))
            else:
                self.c.execute(
                    qry.format(' WHERE (root=? OR pid=?) AND owner=?'),
                    (root, root, owner))

        data = OrderedDict()
        for r in self.c.fetchall():
            data[r[0]] = PackageInfo(r[0], r[1], r[2], r[3], r[4], r[5], r[6],
                                     r[7], r[8], r[9].split(","), r[10], r[11],
                                     r[12], stats.get(r[0], _zero_stats))
        return data
Exemplo n.º 4
0
    def get_all_files(self, package=None, search=None, state=None, owner=None):
        """
        Return dict with file information

        :param package: optional package to filter out
        :param search: or search string for file name
        :param unfinished: filter by dlstatus not finished
        :param owner: only specific owner
        """
        qry = ('SELECT fid, name, owner, size, status, media, added, '
               'fileorder, url, plugin, hash, dlstatus, error, package '
               'FROM files WHERE ')

        arg = []

        if state is not None and state != DownloadState.All:
            qry += "dlstatus IN ({0}) AND ".format(statestring(state))
        if owner is not None:
            qry += 'owner=? AND '
            arg.append(owner)

        if package is not None:
            arg.append(package)
            qry += 'package=? AND '
        if search is not None:
            search = "%%{0}%%".format(search.strip("%"))
            arg.append(search)
            qry += "name LIKE ? "

        # make qry valid
        if qry.endswith("WHERE "):
            qry = qry[:-6]
        if qry.endswith("AND "):
            qry = qry[:-4]

        self.c.execute(qry + "ORDER BY package, fileorder", arg)

        data = OrderedDict()
        for r in self.c.fetchall():
            finfo = FileInfo(r[0], r[1], r[13], r[2],
                             r[3], r[4], r[5], r[6], r[7])
            if r[11] > 0:  # dl status != NA
                finfo.download = DownloadInfo(
                    r[8],
                    r[9],
                    r[10],
                    r[11],
                    self.__manager.status_msg[r[11]],
                    r[12])
            data[r[0]] = finfo

        return data
Exemplo n.º 5
0
    def __init__(self, file, version):
        self.filename = file
        self.version = convert.to_version(version, version)

        # Meta data information
        self.config = OrderedDict()
        # The actual config values
        self.values = {}

        self.check_version()

        self.load_default()
        self.parse(self.filename)
Exemplo n.º 6
0
    def add_config_section(self, section, label, desc, expl, config):
        """
        Adds a section to the config.
        `config` is a list of config tuple as used in plugin api defined as
        the order of the config elements is preserved with OrderedDict
        """
        d = OrderedDict()

        for entry in config:
            name, data = to_configdata(entry)
            d[name] = data

        data = SectionTuple(gettext(label), gettext(desc), gettext(expl), d)
        self.config[section] = data
Exemplo n.º 7
0
    def __init__(self, core, parser):
        # No __init__ call to super class is needed!

        self.pyload = core

        # The config parser, holding the core config
        self.parser = parser

        # similar to parser, separated meta data and values
        self.config = OrderedDict()

        # Value cache for multiple user configs
        # Values are populated from db on first access
        # Entries are saved as (user, section) keys
        self.values = {}
Exemplo n.º 8
0
 def __init__(self, core):
     BaseManager.__init__(self, core)
     self.tasks = OrderedDict()  # task store, for all outgoing tasks
     self.last_clients = {}
     self.ids = 0  # uniue interaction ids
Exemplo n.º 9
0
 def __init__(self, core):
     self.lock = Lock()
     self.pyload = core
     self.tasks = OrderedDict()  #: task store, for all outgoing tasks
     self.last_clients = {}
     self.ids = 0  #: uniue interaction ids