began adding 'import' command & refactor of 'add', but committing so I can erase my disk safely

--HG--
extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%4036
This commit is contained in:
adrian.sampson 2008-06-30 18:45:00 +00:00
parent 31f8dd074a
commit f4b95ea1b5
2 changed files with 14 additions and 20 deletions

View file

@ -539,28 +539,17 @@ class Library(object):
#### main interface ####
def add(self, path, clobber=False):
def add(self, path):
"""Add a file to the library or recursively search a directory and add
all its contents."""
if os.path.isdir(path): # directory
# recurse into contents
for ent in os.listdir(path):
self.add(path + os.sep + ent, clobber)
elif os.path.isfile(path): # normal file
#fixme avoid clobbering/duplicates!
# add _if_ it's legible (otherwise ignore but say so)
try:
Item.from_path(_normpath(path), self)
except FileTypeError:
_log(path + ' of unknown type, skipping')
elif not os.path.exists(path): # no file
raise IOError('file not found: ' + path)
else: # something else: special file?
_log(path + ' special file, skipping')
for root, dirs, files in os.walk(path):
for filebase in files:
filepath = os.join(root, filebase)
try:
Item.from_path(_normpath(filepath), self)
except FileTypeError:
_log(filepath + ' of unknown type, skipping')
def get(self, query=None):
"""Returns a ResultIterator to the items matching query, which may be

7
bts.py
View file

@ -14,6 +14,10 @@ def ls(lib, criteria):
for item in lib.get(q):
print item.artist + ' - ' + item.album + ' - ' + item.title
def imp(lib, paths):
for path in paths:
pass
if __name__ == "__main__":
# parse options
usage = """usage: %prog [options] command
@ -38,11 +42,12 @@ command is one of: add, remove, update, write, list, help"""
# choose which command to invoke
avail_commands = [
(add, ['add']),
(imp, ['import', 'im', 'imp']),
#(remove, ['remove', 'rm']),
#(update, ['update', 'up']),
#(write, ['write', 'wr', 'w']),
(ls, ['list', 'ls']),
(help, ['help', 'h'])
(help, ['help', 'h']),
]
for test_command in avail_commands:
if cmd in test_command[1]: