]> git.phdru.name Git - bookmarks_db.git/blob - convert_st.py
Rename CWD to PROG_DIR
[bookmarks_db.git] / convert_st.py
1 #! /usr/bin/env python
2 """Convert a bkmk database to a different storage.
3
4 This file is a part of Bookmarks database and Internet robot.
5 """
6
7 __author__ = "Oleg Broytman <phd@phdru.name>"
8 __copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
9 __license__ = "GNU GPL"
10
11 import sys
12
13
14 def run():
15    from getopt import getopt
16    optlist, args = getopt(sys.argv[1:], "s")
17
18    report_stats = 1
19
20    for _opt, _arg in optlist:
21       if _opt == '-s':
22          report_stats = 0
23    try:
24       del _opt, _arg
25    except NameError:
26       pass
27
28    if len(args) <> 1:
29       sys.stderr.write("convert_st: too many or too few arguments\n")
30       sys.stderr.write("Usage: convert_st [-s] new_storage\n")
31       sys.exit(1)
32
33    from storage import storage, import_storage
34    storage = storage()
35
36    new_storage = import_storage(args[0])
37    new_storage = new_storage()
38
39    if report_stats:
40       sys.stdout.write("Loading %s: " % storage.filename)
41       sys.stdout.flush()
42
43    root_folder = storage.load()
44
45    if report_stats:
46       print "Ok"
47       sys.stdout.write("Converting to %s: " % new_storage.filename)
48       sys.stdout.flush()
49
50    new_storage.store(root_folder)
51
52    if report_stats:
53       print "Ok"
54
55
56 if __name__ == '__main__':
57    run()