Пример #1
0
def process_args(args):
    from blaplay.blautil import bladbus
    # FIXME: bladbus needs to be treated differently
    global cli_queue

    # Print information about the current track.
    if args["format"]:
        bladbus.query_bus(args["format"][0])

    # Parse URIs given on the command-line.
    if args["URI"]:
        if args["append"]:
            action = "append"
        elif args["new"]:
            action = "new"
        else:
            action = "replace"

        def normpath(uri):
            return os.path.normpath(os.path.abspath(uri))
        # TODO: make cli_queue a FIFO we write to here. then connect a handler
        #       which monitors the FIFO in the main thread and adds tracks as
        #       they arrive
        isfile = os.path.isfile
        cli_queue = (action, filter(isfile, map(normpath, args["URI"])))
    else:
        cli_queue = ("raise_window", None)

    # Player commands
    for cmd in ["play_pause", "stop", "next", "previous"]:
        if args[cmd]:
            bladbus.query_bus(cmd)
Пример #2
0
                    raise

    # We use a lock file to ensure blaplay operates as singleton. However, the
    # lock is only valid as long as the file descriptor is alive. That's why we
    # need to keep it open (and referenced) which is why we assign it to a
    # global.
    global lock_file
    lock_file = open(blaconst.PIDFILE, "w")
    try:
        fcntl.lockf(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
    except IOError:
        print_i("%s is already running" % blaconst.APPNAME)
        from blaplay.blautil import bladbus
        global cli_queue
        try:
            bladbus.query_bus(*cli_queue)
        except TypeError:
            pass
        else:
            cli_queue = None
        raise SystemExit
    lock_file.write(str(os.getpid()))

def main():
    init_signals()

    args = parse_args()

    init_logging(args)

    process_args(args)