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)
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())
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())
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)
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())
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')
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)