take dbfile as an argument, default to ~/.dwtt.db

This commit is contained in:
Josh Holtrop 2011-02-21 22:14:04 -05:00
parent d316405db7
commit cd1fbf332c

21
dwtt
View File

@ -5,21 +5,23 @@ import sys
import getopt import getopt
from Window import * from Window import *
from DataStore import *
PROGRAM_NAME = 'dwtt' PROGRAM_NAME = 'dwtt'
def usage(): def usage():
print '''Usage: dwtt [options] [dbfile] print '''Usage: %s [options] [dbfile]
Options: Options:
--help Show this help --help Show this help
''' ''' % PROGRAM_NAME
def main(argv): def main(argv):
dbfile = os.path.expanduser('~/.%s.db' % PROGRAM_NAME)
try: try:
opts, args = getopt.getopt(argv[1:], "", ["help"]) opts, args = getopt.getopt(argv[1:], "", ["help"])
except getopt.GetoptError: except getopt.GetoptError:
usage() usage()
sys.exit(1) return 2
for opt, arg in opts: for opt, arg in opts:
if opt == "--help": if opt == "--help":
@ -27,10 +29,17 @@ def main(argv):
sys.exit() sys.exit()
else: else:
usage() usage()
sys.exit(3) return 2
w = Window() if len(args) == 1:
dbfile = args[0]
elif len(args) > 1:
usage()
return 2
ds = DataStore(dbfile)
w = Window(ds)
w.main() w.main()
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv) sys.exit(main(sys.argv))