| |
@@ -18,15 +18,14 @@
|
| |
# Josef Skladanka <jskladan@redhat.com>
|
| |
|
| |
import os
|
| |
- import sys
|
| |
- from optparse import OptionParser
|
| |
+ from argparse import ArgumentParser
|
| |
|
| |
from alembic.config import Config
|
| |
from alembic import command as al_command
|
| |
from alembic.migration import MigrationContext
|
| |
|
| |
from oraculum import app, db, controllers
|
| |
- from oraculum.utils import db_utils, schedule, libkarma
|
| |
+ from oraculum.utils import db_utils
|
| |
|
| |
def get_alembic_config():
|
| |
# the location of the alembic ini file and alembic scripts changes when
|
| |
@@ -39,7 +38,7 @@
|
| |
return alembic_cfg
|
| |
|
| |
|
| |
- def initialize_db():
|
| |
+ def init_db():
|
| |
alembic_cfg = get_alembic_config()
|
| |
|
| |
# check to see if the db has already been initialized by checking for an
|
| |
@@ -70,36 +69,15 @@
|
| |
print("Refreshing DB Cache")
|
| |
app.config['MAX_DB_AGE'] = 0
|
| |
app.config['FORCE_CACHED_DATA'] = False
|
| |
- db_utils.refresh_data("get_actions", controllers.main.get_actions()),
|
| |
- db_utils.refresh_data("api_v1_landing_page", controllers.main.api_v1_landing_page()),
|
| |
+ db_utils.refresh_data("get_actions", controllers.main.get_actions())
|
| |
+ db_utils.refresh_data("api_v1_landing_page", controllers.main.api_v1_landing_page())
|
| |
db_utils.refresh_data("api_v1_libkarma", controllers.main.api_v1_libkarma('all'))
|
| |
|
| |
def main():
|
| |
- possible_commands = ['init_db', 'generate_config', 'upgrade_db', 'sync']
|
| |
-
|
| |
- usage = 'usage: %prog [options] command \n Possible Commands: ' + ' '.join(
|
| |
- possible_commands)
|
| |
- parser = OptionParser(usage=usage)
|
| |
- parser.add_option('-d', '--dburi', dest='dburi', help='dburi to use')
|
| |
-
|
| |
- (options, args) = parser.parse_args()
|
| |
-
|
| |
- if len(args) < 1:
|
| |
- print("need to have at least 1 command")
|
| |
- sys.exit(1)
|
| |
-
|
| |
- command = args[0]
|
| |
- if not command in possible_commands:
|
| |
- print("Invalid command: %s" % command)
|
| |
- print("Please use one of the following commands: %s" % str(possible_commands))
|
| |
- sys.exit(1)
|
| |
-
|
| |
- elif command == 'upgrade_db':
|
| |
- upgrade_db()
|
| |
- elif command == 'init_db':
|
| |
- initialize_db()
|
| |
- elif command == 'sync':
|
| |
- sync()
|
| |
+ parser = ArgumentParser()
|
| |
+ parser.add_argument("command", choices=['init_db', 'upgrade_db', 'sync'], help='Available commands')
|
| |
+ args = parser.parse_args()
|
| |
+ globals()[args.command]()
|
| |
|
| |
if __name__ == '__main__':
|
| |
main()
|
| |