This repository has been archived by the owner on Apr 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
manage.py
106 lines (77 loc) · 2.73 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
# encoding: utf-8
import subprocess
import sys
from flask_script import Manager
from flask_script.commands import ShowUrls
from application import create_app
from utils.commands import GEventServer, ProfileServer
from utils.init_db import init_db
from utils.init_data import main as init_data
manager = Manager(create_app)
manager.add_option('-c', '--config', dest='mode', required=False)
manager.add_command("showurls", ShowUrls())
manager.add_command("gevent", GEventServer())
manager.add_command("profile", ProfileServer())
@manager.shell
def make_shell_context():
import application.models as ms
from application.extensions import redis
return dict(app=manager.app, Models=ms, rds=redis)
@manager.option('-c', '--config', help='enviroment config')
def create_db(config):
create_app(config)
init_db()
@manager.option('-c', '--config', help='enviroment config')
def drop_db(config):
from application.extensions import redis
create_app(config)
redis.flushall()
@manager.option('-c', '--config', help='enviroment config')
@manager.option('-l', '--location', help='wordpress backpack file path')
def wpimport(config=None, location=None):
create_app(config)
init_data(location)
@manager.option('-c', '--config', help='enviroment config')
def esindex(config=None):
from datetime import datetime
from elasticsearch import Elasticsearch
import application.models as Models
create_app(config)
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
# 插入
for post in Models.Post.objects.all():
d = post.to_json()
d.update({"timestamp": datetime.utcnow()})
es.index(index="mdpress", doc_type="post", id=post.id,
body=d)
@manager.option('-c', '--config', help='enviroment config')
def image_backup(config=None):
from utils.backup_images import backup
create_app(config)
backup()
@manager.option('-c', '--config', help='enviroment config')
def simple_run(config):
app = create_app(config)
app.run(debug=True)
@manager.option('-c', '--config', help='enviroment config')
def worker(config):
from application.extensions import celery
app = create_app(config)
app.app_context().push()
@manager.option('-c', '--config', help='enviroment config')
def run_fcgi(config):
from flup.server.fcgi import WSGIServer
app = create_app(config)
server = WSGIServer(app, bindAddress='/tmp/mdpress.sock')
server.run()
@manager.command
def lint():
"""Runs code linter."""
lint = subprocess.call(['flake8', '--ignore=E402,F403,E501', 'application/',
'manage.py', 'tests/']) == 0
if lint:
print('OK')
sys.exit(lint)
if __name__ == "__main__":
manager.run()