beets/bts.py
adrian.sampson ee7bb4b9e8 initial import
--HG--
extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%402
2008-05-14 01:42:56 +00:00

42 lines
No EOL
1.2 KiB
Python
Executable file

#!/usr/bin/env python
from optparse import OptionParser
from beets import Library
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 = [
(lib.add, ['add']),
(lib.remove, ['remove', 'rm']),
(lib.update, ['update', 'up']),
(lib.write, ['write', 'wr', 'w']),
(lib.list, ['list', 'ls']),
(help, ['help', 'h'])
]
for test_command in avail_commands:
if cmd in test_command[1]:
(test_command[0])(*args)
op.exit()
# no command matched
op.error('invalid command "' + cmd + '"')