-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
67 lines (48 loc) · 1.9 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
import os
from app import create_app
from flask_script import Manager, Shell
from flask_migrate import MigrateCommand, Migrate
from app.models import User, Vocabulary, UserInfo
import psycopg2
app = create_app("default")
manager = Manager(app)
from app import db
migrate = Migrate(app, db)
def make_shell_context():
return dict(app=app, db=db, User=User, Vocabulary=Vocabulary,
UserInfo=UserInfo)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command("db", MigrateCommand)
@manager.command
def test():
"""Run the unit tests."""
import unittest
test = unittest.TestLoader().discover("test")
unittest.TextTestRunner(verbosity=2).run(tests)
@manager.command
def get_info():
fileName = 'users.xml'
message = '<users>\n'
tableNames = ['users', 'userinfo', 'vocabulary']
conn = psycopg2.connect("dbname='flaskhasher_dev' user='postgres' host='localhost' password='your_password'")
with open(fileName, 'w+') as outfile:
cursor = conn.cursor()
outfile.write('<?xml version="1.0" ?>\n')
outfile.write(message)
for tableName in tableNames:
columnList = []
cursor.execute("SELECT column_name from information_schema.columns where table_name = '%s'" % tableName)
columns = cursor.fetchall()
for column in columns:
columnList.append(column[0])
cursor.execute("select * from %s" % tableName)
rows = cursor.fetchall()
for row in rows:
outfile.write(' <row>\n')
for i in range(len(columnList)):
outfile.write(' <%s>%s</%s>\n' % (columnList[i], row[i],
columnList[i]))
outfile.write(' </row>\n')
outfile.write(message)
if __name__ == "__main__":
manager.run()