]> git.phdru.name Git - bookmarks_db.git/blob - convert_st.py
TODO: Configuration file
[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 bkmk_objects import parse_params, set_params
34    from storage import storage, import_storage
35
36    storage = storage()
37
38    storage_name, storage_params = parse_params(args[0])
39    new_storage = import_storage(storage_name)
40    set_params(new_storage, storage_params)
41    new_storage = new_storage()
42
43    if report_stats:
44       sys.stdout.write("Loading %s: " % storage.filename)
45       sys.stdout.flush()
46
47    root_folder = storage.load()
48
49    if report_stats:
50       print "Ok"
51       sys.stdout.write("Converting to %s: " % new_storage.filename)
52       sys.stdout.flush()
53
54    new_storage.store(root_folder)
55
56    if report_stats:
57       print "Ok"
58
59
60 if __name__ == '__main__':
61    run()