add manage stript

This commit is contained in:
vanzhiganov 2017-09-17 18:07:15 +03:00
parent db65b4e7e9
commit 76518a2354
21 changed files with 246 additions and 3 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
.env/
*.pyc
celerybeat-schendule
tmp/associations/
tmp/nonces/

BIN
celerybeat-schedule Normal file

Binary file not shown.

1
celerybeat.pid Normal file
View file

@ -0,0 +1 @@
13741

18
manage.py Normal file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env python
# coding: utf-8
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand
from wots import app, db
migrate = Migrate(app, db)
# Инициализируем менеджер
manager = Manager(app)
# Регистрируем команду, реализованную в виде потомка класса Command
manager.add_command('db', MigrateCommand)
# managet.add_command('wot_harvers_all')
if __name__ == '__main__':
manager.run()

1
migrations/README Executable file
View file

@ -0,0 +1 @@
Generic single-database configuration.

45
migrations/alembic.ini Normal file
View file

@ -0,0 +1,45 @@
# A generic, single database configuration.
[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
qualname =
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

87
migrations/env.py Executable file
View file

@ -0,0 +1,87 @@
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
import logging
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
config.set_main_option('sqlalchemy.url',
current_app.config.get('SQLALCHEMY_DATABASE_URI'))
target_metadata = current_app.extensions['migrate'].db.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
engine = engine_from_config(config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
connection = engine.connect()
context.configure(connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

24
migrations/script.py.mako Executable file
View file

@ -0,0 +1,24 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View file

@ -0,0 +1,32 @@
"""empty message
Revision ID: 3477657c864b
Revises: 34b1309f878a
Create Date: 2017-09-17 16:36:33.516664
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '3477657c864b'
down_revision = '34b1309f878a'
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
'wot_accounts',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user', sa.Integer(), nullable=True),
sa.Column('account_id', sa.Integer(), nullable=False),
sa.Column('nickname', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['user'], ['user.id']),
)
def downgrade():
op.drop_table('wot_accounts')

1
run_app.py Normal file → Executable file
View file

@ -1,3 +1,4 @@
#!/usr/bin/env python
from wots import app

1
run_celery.py Normal file → Executable file
View file

@ -1,2 +1,3 @@
#!/usr/bin/env python
from wots import celery

9
test_auth.py Normal file
View file

@ -0,0 +1,9 @@
import json
import requests
application_id = '502910c1c785c3c7ca2e83c9e89bde02'
nofollow = 1
url = 'https://api.worldoftanks.ru/wot/auth/login/'
redirect_url = 'http://truesoft.org:5000/login'
print requests.get('{}?application_id={}&nofollow={}&redirect_uri={}'.format(url, application_id, nofollow, redirect_url)).text

3
test_tasks.py Normal file
View file

@ -0,0 +1,3 @@
from wotstats.tasks import *
hello()

View file

@ -1,3 +1,3 @@
from wotstats.init import init_app
app, celery = init_app()
app, celery, db = init_app()

View file

@ -34,7 +34,7 @@ def init_app():
openid = session['openid']
g.user = User.query.filter_by(openid=openid).first()
return app, celery
return app, celery, db
def init_celery(app):

View file

@ -0,0 +1,18 @@
from sqlalchemy.dialects.postgresql import ARRAY, HSTORE
from wotstats.database import db
class WotAccounts(db.Model):
id = db.Column(db.Integer, primary_key=True)
user = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
account_id = db.Column(db.Integer, nullable=False)
nickname = db.Column(db.String(128), nullable=False)
def __init__(self, account_id, nickname):
self.account_id = account_id
self.nickname = nickname
def __repr__(self):
return '<WotAccounts user={} account_id={} nickname={}>'.format(
self.name, self.account_id, self.nickname)

View file

@ -14,7 +14,7 @@ from wotstats.lib import parse_wargaming_openid_url
pages_account = Blueprint('pages_account', __name__, url_prefix='/account', template_folder='templates')
def __get_player_personal_data():
log.debug(session['openid'])
log.debug(session)
user_id = parse_wargaming_openid_url(session['openid'])[0]
__ = requests.get(