Esempio n. 1
0
        def hook_function(**kwargs):
            if command is None or len(command) == 0:
                self._log.error('invalid command "{0}"', command)
                return

            # Use a string formatter that works on Unicode strings.
            formatter = CodingFormatter(arg_encoding())

            command_pieces = shlex_split(command)

            for i, piece in enumerate(command_pieces):
                command_pieces[i] = formatter.format(piece,
                                                     event=event,
                                                     **kwargs)

            self._log.debug(u'running command "{0}" for event {1}',
                            u' '.join(command_pieces), event)

            try:
                subprocess.check_call(command_pieces)
            except subprocess.CalledProcessError as exc:
                self._log.error(u'hook for {0} exited with status {1}', event,
                                exc.returncode)
            except OSError as exc:
                self._log.error(u'hook for {0} failed: {1}', event, exc)
Esempio n. 2
0
        def hook_function(**kwargs):
            if command is None or len(command) == 0:
                self._log.error('invalid command "{0}"', command)
                return

            # Use a string formatter that works on Unicode strings.
            if six.PY2:
                formatter = CodingFormatter(arg_encoding())
            else:
                formatter = string.Formatter()

            command_pieces = shlex_split(command)

            for i, piece in enumerate(command_pieces):
                command_pieces[i] = formatter.format(piece,
                                                     event=event,
                                                     **kwargs)

            self._log.debug(u'running command "{0}" for event {1}',
                            u' '.join(command_pieces), event)

            try:
                subprocess.Popen(command_pieces).wait()
            except OSError as exc:
                self._log.error(u'hook for {0} failed: {1}', event, exc)
Esempio n. 3
0
def edit(filename, log):
    """Open `filename` in a text editor.
    """
    cmd = util.shlex_split(util.editor_command())
    cmd.append(filename)
    log.debug(u'invoking editor command: {!r}', cmd)
    try:
        subprocess.call(cmd)
    except OSError as exc:
        raise ui.UserError(u'could not run editor command {!r}: {}'.format(
            cmd[0], exc))
Esempio n. 4
0
def parse_query_string(s, model_cls):
    """Given a beets query string, return the `Query` and `Sort` they
    represent.

    The string is split into components using shell-like syntax.
    """
    assert isinstance(s, unicode), u"Query is not unicode: {0!r}".format(s)
    try:
        parts = util.shlex_split(s)
    except ValueError as exc:
        raise dbcore.InvalidQueryError(s, exc)
    return parse_query_parts(parts, model_cls)
Esempio n. 5
0
def parse_query_string(s, model_cls):
    """Given a beets query string, return the `Query` and `Sort` they
    represent.

    The string is split into components using shell-like syntax.
    """
    assert isinstance(s, unicode), u"Query is not unicode: {0!r}".format(s)
    try:
        parts = util.shlex_split(s)
    except ValueError as exc:
        raise dbcore.InvalidQueryError(s, exc)
    return parse_query_parts(parts, model_cls)
Esempio n. 6
0
def edit(filename, log):
    """Open `filename` in a text editor.
    """
    cmd = util.shlex_split(util.editor_command())
    cmd.append(filename)
    log.debug(u'invoking editor command: {!r}', cmd)
    try:
        subprocess.call(cmd)
    except OSError as exc:
        raise ui.UserError(u'could not run editor command {!r}: {}'.format(
            cmd[0], exc
        ))
Esempio n. 7
0
        def hook_function(**kwargs):
                if command is None or len(command) == 0:
                    self._log.error('invalid command "{0}"', command)
                    return

                formatter = CodingFormatter(_arg_encoding())
                command_pieces = shlex_split(command)

                for i, piece in enumerate(command_pieces):
                    command_pieces[i] = formatter.format(piece, event=event,
                                                         **kwargs)

                self._log.debug(u'running command "{0}" for event {1}',
                                u' '.join(command_pieces), event)

                try:
                    subprocess.Popen(command_pieces).wait()
                except OSError as exc:
                    self._log.error(u'hook for {0} failed: {1}', event, exc)
Esempio n. 8
0
def play(command_str, selection, paths, open_args, log, item_type='track',
         keep_open=False):
    """Play items in paths with command_str and optional arguments. If
    keep_open, return to beets, otherwise exit once command runs.
    """
    # Print number of tracks or albums to be played, log command to be run.
    item_type += 's' if len(selection) > 1 else ''
    ui.print_(u'Playing {0} {1}.'.format(len(selection), item_type))
    log.debug(u'executing command: {} {!r}', command_str, open_args)

    try:
        if keep_open:
            command = util.shlex_split(command_str)
            command = command + open_args
            subprocess.call(command)
        else:
            util.interactive_open(open_args, command_str)
    except OSError as exc:
        raise ui.UserError(
            "Could not play the query: {0}".format(exc))
Esempio n. 9
0
def edit(filename):
    """Open `filename` in a text editor.
    """
    cmd = util.shlex_split(util.editor_command())
    cmd.append(filename)
    subprocess.call(cmd)
Esempio n. 10
0
def edit(filename):
    """Open `filename` in a text editor.
    """
    cmd = util.shlex_split(util.editor_command())
    cmd.append(filename)
    subprocess.call(cmd)