[copr] master: Start using flask-script; it also substitues runapp.py (1b2c502)
bkabrda at fedoraproject.org
bkabrda at fedoraproject.org
Tue Jan 15 11:05:59 UTC 2013
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 1b2c5028461b3c05409541fc34242748439ed9bc
Author: Bohuslav Kabrda <bkabrda at redhat.com>
Date: Mon Jan 14 09:30:11 2013 +0100
Start using flask-script; it also substitues runapp.py
>---------------------------------------------------------------
coprs_frontend/manage.py | 95 ++++++++++++++++++++--------------------------
coprs_frontend/runapp.py | 2 -
2 files changed, 41 insertions(+), 56 deletions(-)
diff --git a/coprs_frontend/manage.py b/coprs_frontend/manage.py
index 7716e86..cd53522 100755
--- a/coprs_frontend/manage.py
+++ b/coprs_frontend/manage.py
@@ -1,64 +1,51 @@
#!/usr/bin/env python
-import argparse
import os
-from coprs import app, db
+import flask
+from flask.ext.script import Manager, Command, Option
-class DBManager(object):
- def __init__(self, db):
- self.db = db
+from coprs import app, db
- def create_sqlite_file(self):
- if app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):
+class CreateSqliteFileCommand(Command):
+ 'Create the sqlite DB file (not the tables). Used for alembic, "create_db" does this automatically.'
+ def run(self):
+ if flask.current_app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):
# strip sqlite:///
- datadir_name = os.path.dirname(app.config['SQLALCHEMY_DATABASE_URI'][10:])
+ datadir_name = os.path.dirname(flask.current_app.config['SQLALCHEMY_DATABASE_URI'][10:])
if not os.path.exists(datadir_name):
os.makedirs(datadir_name)
- def create_db(self, alembic_ini=None):
- self.create_sqlite_file()
- self.db.create_all()
- if alembic_ini is not None:
- # then, load the Alembic configuration and generate the
- # version table, "stamping" it with the most recent rev:
- from alembic.config import Config
- from alembic import command
- alembic_cfg = Config(alembic_ini)
- command.stamp(alembic_cfg, "head")
-
- def delete_db(self):
- self.db.drop_all()
-
-parser = argparse.ArgumentParser(description = 'Manage the app')
-parser.add_argument('-s', '--create-sqlite-file',
- required = False,
- help = 'Create the sqlite DB file (not the tables). User for alembic, the -c does this automatically.',
- action = 'store_true')
-
-parser.add_argument('-c', '--create-db',
- required = False,
- help = 'Create the DB scheme',
- action = 'store_true')
-
-parser.add_argument('-d', '--delete-db',
- required = False,
- help = 'Delete DB',
- action = 'store_true')
-
-parser.add_argument('-f', '--alembic',
- required = False,
- help = 'Path to the alembic configuration file (alembic.ini)')
-
-args = parser.parse_args()
-
-manager = DBManager(db)
-if args.create_sqlite_file:
- manager.create_sqlite_file()
-elif args.create_db:
- if not args.alembic:
- print "Please provide the path to the alembic configuration file."
- else:
- manager.create_db(args.alembic)
-elif args.delete_db:
- manager.delete_db()
+class CreateDBCommand(Command):
+ 'Create the DB scheme'
+ def run(self, alembic_ini=None):
+ CreateSqliteFileCommand().run()
+ db.create_all()
+
+ # load the Alembic configuration and generate the
+ # version table, "stamping" it with the most recent rev:
+ from alembic.config import Config
+ from alembic import command
+ alembic_cfg = Config(alembic_ini)
+ command.stamp(alembic_cfg, "head")
+
+ option_list = (
+ Option('--alembic',
+ '-f',
+ dest='alembic_ini',
+ help='Path to the alembic configuration file (alembic.ini)',
+ required=True),
+ )
+
+class DropDBCommand(Command):
+ 'Delete DB'
+ def run(self):
+ db.drop_all()
+
+manager = Manager(app)
+manager.add_command('create_sqlite_file', CreateSqliteFileCommand())
+manager.add_command('create_db', CreateDBCommand())
+manager.add_command('drop_db', DropDBCommand())
+
+if __name__ == '__main__':
+ manager.run()
diff --git a/coprs_frontend/runapp.py b/coprs_frontend/runapp.py
deleted file mode 100644
index eaa0fa2..0000000
--- a/coprs_frontend/runapp.py
+++ /dev/null
@@ -1,2 +0,0 @@
-from coprs import app
-app.run()
More information about the copr-devel
mailing list