示例#1
0
文件: library.py 项目: IndiGit/beets
 def items(self, query=None, sort=None):
     """Get :class:`Item` objects matching the query.
     """
     sort = sort or dbcore.sort_from_strings(
         Item, beets.config['sort_item'].as_str_seq()
     )
     return self._fetch(Item, query, sort)
示例#2
0
 def get_default_item_sort():
     """Get a :class:`Sort` object for items from the config option.
     """
     return dbcore.sort_from_strings(
         Item, beets.config['sort_item'].as_str_seq())
示例#3
0
文件: library.py 项目: Kraymer/beets
 def get_default_album_sort():
     """Get a :class:`Sort` object for albums from the config option.
     """
     return dbcore.sort_from_strings(Album, beets.config["sort_album"].as_str_seq())
示例#4
0
文件: library.py 项目: silb/beets
 def albums(self, query=None, sort=None):
     """Get :class:`Album` objects matching the query.
     """
     sort = sort or dbcore.sort_from_strings(Album, beets.config["sort_album"].as_str_seq())
     return self._fetch(Album, query, sort)
示例#5
0
 def get_default_album_sort():
     """Get a :class:`Sort` object for albums from the config option.
     """
     return dbcore.sort_from_strings(
         Album, beets.config['sort_album'].as_str_seq())
示例#6
0
def get_query_sort(val, model_cls):
    """Take a value which may be None, a query string, a query string
    list, or a Query object, and return a suitable Query object and Sort
    object.

    `model_cls` is the subclass of Model indicating which entity this
    is a query for (i.e., Album or Item) and is used to determine which
    fields are searched.
    """
    # Get query types and their prefix characters.
    prefixes = {':': dbcore.query.RegexpQuery}
    prefixes.update(plugins.queries())

    # Convert a single string into a list of space-separated
    # criteria.
    if isinstance(val, basestring):
        # A bug in Python < 2.7.3 prevents correct shlex splitting of
        # Unicode strings.
        # http://bugs.python.org/issue6988
        if isinstance(val, unicode):
            val = val.encode('utf8')
        val = [s.decode('utf8') for s in shlex.split(val)]

    if val is None:
        return (dbcore.query.TrueQuery(), None)

    elif isinstance(val, list) or isinstance(val, tuple):
        # Special-case path-like queries, which are non-field queries
        # containing path separators (/).
        if 'path' in model_cls._fields:
            path_parts = []
            non_path_parts = []
            for s in val:
                if s.find(os.sep, 0, s.find(':')) != -1:
                    # Separator precedes colon.
                    path_parts.append(s)
                else:
                    non_path_parts.append(s)
        else:
            path_parts = ()
            non_path_parts = val

        # separate query token and sort token
        query_val = [s for s in non_path_parts if not s.endswith(('+', '-'))]
        sort_val = [s for s in non_path_parts if s.endswith(('+', '-'))]

        # Parse remaining parts and construct an AndQuery.
        query = dbcore.query_from_strings(
            dbcore.AndQuery, model_cls, prefixes, query_val
        )
        sort = dbcore.sort_from_strings(model_cls, sort_val)

        # Add path queries to aggregate query.
        if path_parts:
            query.subqueries += [PathQuery('path', s) for s in path_parts]
        return query, sort

    elif isinstance(val, dbcore.Query):
        return val, None

    else:
        raise ValueError('query must be None or have type Query or str')
示例#7
0
文件: library.py 项目: Nenice/beets
 def items(self, query=None, sort=None):
     """Get :class:`Item` objects matching the query.
     """
     sort = sort or dbcore.sort_from_strings(
         Item, beets.config['sort_item'].as_str_seq())
     return self._fetch(Item, query, sort)