diff --git a/odoo/scripts/databases.py b/odoo/scripts/databases.py index c62e351..e5fed46 100644 --- a/odoo/scripts/databases.py +++ b/odoo/scripts/databases.py @@ -32,17 +32,17 @@ def restore(odoo, args): else: connection = odoo password = args.password - connection.db.restore(password, args.database_target, dump_file, - args.restore_copy) + connection.db.restore(password, args.database_target or args.database, + dump_file, args.restore_copy) def main(): """ Main function with argument parsing """ parser = argparse.ArgumentParser(description='Odoo database creation ' 'according to their names') parser = common.parser(parser) - parser.add_argument('-a', '--action', type=str, default='create', - help='action for the database,' + - 'default to create (others are drop, duplicate, dump)') + parser.add_argument('-a', '--action', type=str, required=True, + help=('action for the database : create, drop, ' + 'duplicate, dump or restore')) parser.add_argument('-d', '--database', type=str, required=True, help='the targetted database') parser.add_argument('-pw', '--password', type=str, required=True, @@ -78,12 +78,15 @@ def main(): # Databases actions dblist = odoo.db.list() - if args.action == 'create': + if args.action == 'create' or args.action == 'restore': if args.database in dblist: print 'database already exists' else: - odoo.db.create(args.password, args.database, str2bool(args.demo), - args.lang, args.database_password) + if args.action == 'create': + odoo.db.create(args.password, args.database, str2bool(args.demo), + args.lang, args.database_password) + elif args.action == 'restore': + restore(odoo, args) else: if args.database not in dblist: print 'database not found' @@ -98,8 +101,6 @@ def main(): odoo.db.duplicate(args.password, args.database, name) elif args.action == 'dump': dump(odoo, args) - elif args.action == 'restore': - restore(odoo, args) if __name__ == "__main__": main()