|
@@ -24,7 +24,7 @@ import os
|
|
|
import argparse
|
|
|
import sys
|
|
|
import re
|
|
|
-
|
|
|
+import shutil
|
|
|
|
|
|
_saveconfig = True
|
|
|
|
|
@@ -54,7 +54,7 @@ def parser_options():
|
|
|
" one found in the config file, or the one given"
|
|
|
" as command line argument."))
|
|
|
parser.add_argument('-O', '--output', dest='output',
|
|
|
- default=os.path.expanduser('~/.pwman/pwman-newdb.db'),
|
|
|
+ #default=os.path.expanduser('~/.pwman/pwman-newdb.db'),
|
|
|
help=("The name of the newly created database after "
|
|
|
"converting."))
|
|
|
parser.add_argument('-t', '--test', help=("Run pwman from current"
|
|
@@ -153,29 +153,38 @@ def get_db_version(config, dbtype, args):
|
|
|
|
|
|
|
|
|
def auto_convert():
|
|
|
- #1) Display a message saying that the database will be converted
|
|
|
- # This step is done already in get_db_version
|
|
|
- dbconvertor = PwmanConvertDB(args, config)
|
|
|
-
|
|
|
- #2) copy the old database : cp ~/.pwman3/pwman.db ~/.pwman3/pwman.backup-2013-11-23-23:15.db
|
|
|
- #3) Display a message about the backup file path
|
|
|
- # These steps are done by PwmanConvertDB.backup_old_db()
|
|
|
- dbconvertor.backup_old_db()
|
|
|
-
|
|
|
- #4) convert the old database to the new format in ~/.pwman3/pwman.db
|
|
|
- # This step is done by PwmanConvertDB.create_new_db()
|
|
|
- # PwmanConvertDB.convert_nodes()
|
|
|
- # PwmanConvertDB.save_new_nodes_to_db()
|
|
|
- # PwmanConvertDB.save_old_key()
|
|
|
-
|
|
|
- #5) Display a message about the result of the conversion
|
|
|
- # add message here ...
|
|
|
+ try:
|
|
|
+ #1) Display a message saying that the database will be converted
|
|
|
+ # This step is done already in get_db_version
|
|
|
+ dbconvertor = PwmanConvertDB(args, config)
|
|
|
|
|
|
+ #2) copy the old database : cp ~/.pwman3/pwman.db ~/.pwman3/pwman.backup-2013-11-23-23:15.db
|
|
|
+ #3) Display a message about the backup file path
|
|
|
+ # These steps are done by PwmanConvertDB.backup_old_db()
|
|
|
+ dbconvertor.backup_old_db()
|
|
|
+
|
|
|
+ #4) convert the old database to the new format in ~/.pwman3/pwman.db
|
|
|
+ # This step is done by PwmanConvertDB.create_new_db()
|
|
|
+ # PwmanConvertDB.convert_nodes()
|
|
|
+ # PwmanConvertDB.save_new_nodes_to_db()
|
|
|
+ # PwmanConvertDB.save_old_key()
|
|
|
+ dbconvertor.read_old_db()
|
|
|
+ dbconvertor.create_new_db()
|
|
|
+ dbconvertor.convert_nodes()
|
|
|
+ dbconvertor.save_new_nodes_to_db()
|
|
|
+ dbconvertor.save_old_key()
|
|
|
+ #5) Display a message about the result of the conversion
|
|
|
+ # add message here ...
|
|
|
+ #5b) close connection
|
|
|
+ dbconvertor.db.close()
|
|
|
+ print("Your datbase %s was successfully converted " % dbconvertor.dbname)
|
|
|
+ #5c) rename the newly created db to the old name!
|
|
|
+ shutil.move(dbconvertor.newdb_name, dbconvertor.dbname)
|
|
|
+ #6) Start the pwman3 normally if all went ok
|
|
|
+ return True
|
|
|
+ except Exception, e:
|
|
|
+ raise e
|
|
|
|
|
|
- #5b) close connection
|
|
|
- #5c) rename the newly created db to the old name!
|
|
|
- #6) Start the pwman3 normally if all went ok
|
|
|
- return
|
|
|
|
|
|
def main(args):
|
|
|
PwmanCliNew, OSX = get_ui_platform(sys.platform)
|
|
@@ -190,6 +199,7 @@ def main(args):
|
|
|
|
|
|
if dbver < 0.4:
|
|
|
auto_convert()
|
|
|
+ dbver = 0.4
|
|
|
|
|
|
db = pwman.data.factory.create(dbtype, dbver)
|
|
|
cli = PwmanCliNew(db, xselpath, CLICallback)
|