mirror of
https://github.com/YunoHost/tartiflette.git
synced 2024-09-03 20:06:08 +02:00
Simplify / improve manage.py
This commit is contained in:
parent
3f1b44aa45
commit
01cf55c602
1 changed files with 21 additions and 23 deletions
44
manage.py
44
manage.py
|
@ -4,61 +4,59 @@ from flask_script import Manager, Shell, Command, Server
|
||||||
from app import db, create_app
|
from app import db, create_app
|
||||||
|
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
manager = Manager(app)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
manager = Manager(app)
|
|
||||||
manager.add_command('shell', Shell(make_context=lambda:{"app":app, "db":db}))
|
manager.add_command('shell', Shell(make_context=lambda:{"app":app, "db":db}))
|
||||||
manager.add_command('nuke', Nuke(db))
|
|
||||||
manager.add_command('init', Init(db))
|
|
||||||
manager.add_command('update-appci', Update(db, "appci"))
|
|
||||||
manager.add_command('update-pr', Update(db, "pr"))
|
|
||||||
manager.add_command("runserver", Server())
|
manager.add_command("runserver", Server())
|
||||||
manager.run()
|
manager.run()
|
||||||
|
|
||||||
|
@manager.add_command
|
||||||
class Update(Command):
|
class Update(Command):
|
||||||
|
name = "update"
|
||||||
|
capture_all_args = True
|
||||||
|
|
||||||
def __init__(self, db, what):
|
def run(self, args=None):
|
||||||
self.db = db
|
|
||||||
self.what = what
|
|
||||||
|
|
||||||
def run(self):
|
valid_what = ["appci", "pr", "appobservatory"]
|
||||||
|
what = args[0] if args else None
|
||||||
|
assert what in valid_what, "Please specify what to update among %s" % ', '.join(valid_what)
|
||||||
|
|
||||||
if self.what == "appci":
|
if what == "appci":
|
||||||
from app.models.appci import AppCI
|
from app.models.appci import AppCI
|
||||||
AppCI.update()
|
AppCI.update()
|
||||||
elif self.what == "pr":
|
elif what == "pr":
|
||||||
from app.models.pr import Repo
|
from app.models.pr import Repo
|
||||||
for repo in Repo.query.all():
|
for repo in Repo.query.all():
|
||||||
repo.update()
|
repo.update()
|
||||||
|
elif what == "appobservatory":
|
||||||
|
from app.models.unlistedapps import UnlistedApp
|
||||||
|
UnlistedApp.update()
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@manager.add_command
|
||||||
class Nuke(Command):
|
class Nuke(Command):
|
||||||
"""Nuke the database (except the platform table)"""
|
"""Nuke the database (except the platform table)"""
|
||||||
|
name = "nuke"
|
||||||
def __init__(self, db):
|
|
||||||
self.db = db
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
import app.models.appci
|
import app.models.appci
|
||||||
import app.models.pr
|
import app.models.pr
|
||||||
|
import app.models.unlistedapps
|
||||||
|
|
||||||
print("> Droping tables...")
|
print("> Droping tables...")
|
||||||
self.db.drop_all()
|
db.drop_all()
|
||||||
print("> Creating tables...")
|
print("> Creating tables...")
|
||||||
self.db.create_all()
|
db.create_all()
|
||||||
print("> Comitting sessions...")
|
print("> Comitting sessions...")
|
||||||
self.db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@manager.add_command
|
||||||
class Init(Command):
|
class Init(Command):
|
||||||
|
name = "init"
|
||||||
def __init__(self, db):
|
|
||||||
self.db = db
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
import app.models
|
import app.models
|
||||||
|
|
Loading…
Reference in a new issue