Ejemplo n.º 1
0
def parse_query_parts(parts, model_cls):
    """Given a beets query string as a list of components, return the
    `Query` and `Sort` they represent.

    Like `dbcore.parse_sorted_query`, with beets query prefixes and
    special path query detection.
    """
    # Get query types and their prefix characters.
    prefixes = {':': dbcore.query.RegexpQuery}
    prefixes.update(plugins.queries())

    # 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 parts:
            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 = parts

    query, sort = dbcore.parse_sorted_query(
        model_cls, non_path_parts, prefixes
    )

    # Add path queries to aggregate query.
    if path_parts:
        query.subqueries += [PathQuery('path', s) for s in path_parts]
    return query, sort
Ejemplo n.º 2
0
def parse_query_parts(parts, model_cls):
    """Given a beets query string as a list of components, return the
    `Query` and `Sort` they represent.

    Like `dbcore.parse_sorted_query`, with beets query prefixes and
    special path query detection.
    """
    # Get query types and their prefix characters.
    prefixes = {':': dbcore.query.RegexpQuery}
    prefixes.update(plugins.queries())

    # Special-case path-like queries, which are non-field queries
    # containing path separators (/).
    path_parts = []
    non_path_parts = []
    for s in parts:
        if PathQuery.is_path_query(s):
            path_parts.append(s)
        else:
            non_path_parts.append(s)

    query, sort = dbcore.parse_sorted_query(
        model_cls, non_path_parts, prefixes
    )

    # Add path queries to aggregate query.
    # Match field / flexattr depending on whether the model has the path field
    fast_path_query = 'path' in model_cls._fields
    query.subqueries += [PathQuery('path', s, fast_path_query)
                         for s in path_parts]

    return query, sort
Ejemplo n.º 3
0
def parse_query_parts(parts, model_cls):
    """Given a beets query string as a list of components, return the
    `Query` and `Sort` they represent.

    Like `dbcore.parse_sorted_query`, with beets query prefixes and
    special path query detection.
    """
    # Get query types and their prefix characters.
    prefixes = {':': dbcore.query.RegexpQuery}
    prefixes.update(plugins.queries())

    # Special-case path-like queries, which are non-field queries
    # containing path separators (/).
    path_parts = []
    non_path_parts = []
    for s in parts:
        if PathQuery.is_path_query(s):
            path_parts.append(s)
        else:
            non_path_parts.append(s)

    query, sort = dbcore.parse_sorted_query(model_cls, non_path_parts,
                                            prefixes)

    # Add path queries to aggregate query.
    # Match field / flexattr depending on whether the model has the path field
    fast_path_query = 'path' in model_cls._fields
    query.subqueries += [
        PathQuery('path', s, fast_path_query) for s in path_parts
    ]

    return query, sort
Ejemplo n.º 4
0
def parse_query_parts(parts, model_cls):
    """Given a beets query string as a list of components, return the
    `Query` and `Sort` they represent.

    Like `dbcore.parse_sorted_query`, with beets query prefixes and
    special path query detection.
    """
    # Get query types and their prefix characters.
    prefixes = {':': dbcore.query.RegexpQuery}
    prefixes.update(plugins.queries())

    # 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 parts:
            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 = parts

    query, sort = dbcore.parse_sorted_query(model_cls, non_path_parts,
                                            prefixes)

    # Add path queries to aggregate query.
    if path_parts:
        query.subqueries += [PathQuery('path', s) for s in path_parts]
    return query, sort
Ejemplo n.º 5
0
 def psq(self, parts):
     return dbcore.parse_sorted_query(
         TestModel1,
         parts.split(),
     )
Ejemplo n.º 6
0
 def psq(self, parts):
     return dbcore.parse_sorted_query(
         ModelFixture1,
         parts.split(),
     )
Ejemplo n.º 7
0
 def psq(self, parts):
     return dbcore.parse_sorted_query(
         TestModel1,
         parts.split(),
     )