def main(args): start_time = time.time() db.index(datapath = MUSIC_DIR, dbpath = DBPATH) #db.tag(dbpath=DBPATH, querystring=" ".join(args[1:]), tags=["inbox", "fisk"]) matches = db.search(dbpath=DBPATH, querystring=" ".join(args[1:])) for match in matches: print u"{tracknumber} {artist} – »{title}« from {album} {year} ({length} s). Last modified {mtime}. Tagged {tags}.".format(**match['data']) print "N: Found %i tracks in in %f ms.\n" % (len(matches), (time.time() - start_time)*1000)
def with_index(f): from db.xapian_music import index from shutil import rmtree as remove MUSIC_DIR = os.path.join(TESTDIR, "music_dir") DBPATH = os.path.join(TESTDIR, "music.db") index(MUSIC_DIR, DBPATH) try: f(DBPATH) finally: remove(DBPATH)