37 lines
796 B
Text
37 lines
796 B
Text
|
#!/usr/local/bin/python
|
||
|
|
||
|
import anydbm
|
||
|
import getopt
|
||
|
import operator
|
||
|
import os
|
||
|
import sys
|
||
|
|
||
|
def usage():
|
||
|
print >>sys.stderr, "usage: dbtool {-a entry|-d entry|-l}"
|
||
|
|
||
|
try:
|
||
|
optlist, args = getopt.getopt(sys.argv[1:], "a:d:lk")
|
||
|
except getopt.GetoptError, err:
|
||
|
print >>sys.stderr, str(err)
|
||
|
usage()
|
||
|
sys.exit(64)
|
||
|
if len(args) != 0 or len(optlist) != 1:
|
||
|
usage()
|
||
|
sys.exit(64)
|
||
|
|
||
|
downloaddb = anydbm.open(os.path.expanduser("~") + "/.tivo/downloads.db", "c")
|
||
|
|
||
|
for (o, a) in optlist:
|
||
|
if o == "-l":
|
||
|
for i in sorted(downloaddb.keys()):
|
||
|
print "%s:\t%s" % (i, downloaddb[i])
|
||
|
elif o == "-k":
|
||
|
for (k, v) in sorted(downloaddb.items(), key=operator.itemgetter(1)):
|
||
|
print "%s:\t%s" % (k, v)
|
||
|
elif o == "-d":
|
||
|
del downloaddb[a]
|
||
|
elif o == "-a":
|
||
|
downloaddb[a] = "manually added"
|
||
|
|
||
|
downloaddb.close()
|