beets/bts.py
adrian.sampson 2651b1c2b5 cleaned up gratuitous comment blocks and unnecessary shebang lines
--HG--
extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%404
2008-05-14 09:41:15 +00:00

46 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python
from optparse import OptionParser
from beets import Library
def add(lib, paths):
for path in paths:
lib.add(path)
lib.save()
if __name__ == "__main__":
# parse options
usage = """usage: %prog [options] command
command is one of: add, remove, update, write, list, help"""
op = OptionParser(usage=usage)
op.add_option('-l', '--library', dest='libpath', metavar='PATH',
default='library.blb',
help='work on the specified library file')
op.remove_option('--help')
opts, args = op.parse_args()
# make sure we have a command
if len(args) < 1:
op.error('no command specified')
cmd = args.pop(0)
lib = Library(opts.libpath)
# make a "help" command
def help(*args): op.print_help()
# choose which command to invoke
avail_commands = [
(add, ['add']),
#(remove, ['remove', 'rm']),
#(update, ['update', 'up']),
#(write, ['write', 'wr', 'w']),
#(list, ['list', 'ls']),
(help, ['help', 'h'])
]
for test_command in avail_commands:
if cmd in test_command[1]:
(test_command[0])(lib, args)
op.exit()
# no command matched
op.error('invalid command "' + cmd + '"')