proxadmin/manage.py

71 lines
1.5 KiB
Python
Raw Normal View History

2017-03-08 13:53:09 -05:00
#!/usr/bin/env python
import os
import subprocess, shlex
2017-03-08 20:31:16 -05:00
from app import app, db
2017-03-08 13:53:09 -05:00
from flask_script import Manager, Shell, Command
from flask_migrate import Migrate, MigrateCommand
def make_shell_context():
return dict(app=app,
db=db,
User=User,
Role=Role,
Permission=Permission,
Deployment=Deployment)
migrate = Migrate(app, db)
2017-03-09 11:44:20 -05:00
2017-03-08 13:53:09 -05:00
manager = Manager(app)
manager.add_command('shell', Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
@manager.command
def deploy():
"""Run deployment tasks."""
from flask_migrate import upgrade
2017-06-01 18:27:17 -04:00
from app.models import Role, User
2017-03-08 13:53:09 -05:00
# migrate database to latest revision
upgrade()
# create user roles
Role.insert_roles()
@manager.command
2017-06-01 18:27:17 -04:00
def sampledata():
"""Deploy Sample Data"""
pass
2017-03-08 13:53:09 -05:00
def run_scheduler():
command_line = 'python3 /home/proxadmin/appserver/proxmaster-panel/schedulerd.py'
args = shlex.split(command_line)
p = subprocess.Popen(args)
@manager.command
def charge_deployments():
from app.models import Product, Deployment, User
Deployment.charge()
@manager.command
def charge_contracts():
from app.models import Service, Contract, User
Contract.charge()
@manager.command
def charge_domains():
from app.models import Domain, User
Domain.charge()
@manager.command
def runserver():
2017-06-01 18:27:17 -04:00
#print('Starting Scheduler...')
2017-03-08 13:53:09 -05:00
#run_scheduler()
print('Starting Flask...')
app.run()
if __name__ == '__main__':
manager.run()