<s> """<STR_LIT>""" <EOL> from flask import Flask <EOL> from migrate . versioning . api import version_control , upgrade , downgrade , db_version , version <EOL> from sqlalchemy . sql import and_ <EOL> from models import User , Tag , Status , Format , Post , post_tags <EOL> from database import DB <EOL> from flaskjk import encrypt_password , slugify <EOL> from datetime import datetime <EOL> import sys <EOL> import getpass <EOL> import datamigrations <EOL> app = Flask ( __name__ , static_path = None ) <EOL> app . config . from_pyfile ( '<STR_LIT>' ) <EOL> app . config . from_envvar ( '<STR_LIT>' , silent = True ) <EOL> db = app . config [ '<STR_LIT>' ] <EOL> repo = '<STR_LIT>' <EOL> def vc_db ( ) : <EOL> """<STR_LIT>""" <EOL> version_control ( url = db , repository = repo ) <EOL> def upgrade_db ( v = None ) : <EOL> """<STR_LIT>""" <EOL> from_version = db_version ( url = db , repository = repo ) <EOL> to_version = v <EOL> if to_version is None : <EOL> to_version = version ( repository = repo ) <EOL> print ( "<STR_LIT>" % ( from_version , to_version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> upgrade ( url = db , repository = repo , version = v ) <EOL> print ( "<STR_LIT>" ) <EOL> datamigrations . run_upgrade_scripts ( app , from_version , to_version ) <EOL> print ( "<STR_LIT>" ) <EOL> def downgrade_db ( v ) : <EOL> """<STR_LIT>""" <EOL> from_version = db_version ( url = db , repository = repo ) <EOL> to_version = int ( v ) <EOL> print ( "<STR_LIT>" % ( from_version , to_version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> downgrade ( url = db , repository = repo , version = v ) <EOL> print ( "<STR_LIT>" ) <EOL> datamigrations . run_downgrade_scripts ( app , from_version , to_version ) <EOL> print ( "<STR_LIT>" ) <EOL> def add_initial_data ( ) : <EOL> """<STR_LIT>""" <EOL> db_session = DB ( db ) . get_session ( ) <EOL> username = raw_input ( '<STR_LIT>' ) <EOL> password = getpass . getpass ( prompt = '<STR_LIT>' ) <EOL> u = User ( username , encrypt_password ( app . config [ '<STR_LIT>' ] , password ) ) <EOL> db_session . add ( u ) <EOL> s1 = Status ( '<STR_LIT>' ) <EOL> s2 = Status ( '<STR_LIT>' ) <EOL> s3 = Status ( '<STR_LIT>' ) <EOL> db_session . add ( s1 ) <EOL> db_session . add ( s2 ) <EOL> db_session . add ( s3 ) <EOL> f = Format ( '<STR_LIT>' ) <EOL> f2 = Format ( '<STR_LIT>' ) <EOL> db_session . add ( f ) <EOL> db_session . add ( f2 ) <EOL> t1 = Tag ( '<STR_LIT>' ) <EOL> t2 = Tag ( '<STR_LIT>' ) <EOL> initial_post_summary = """<STR_LIT>""" <EOL> initial_post_content = """<STR_LIT>""" <EOL> p1 = Post ( '<STR_LIT>' , initial_post_summary , initial_post_content ) <EOL> p1 . slug = slugify ( p1 . title ) <EOL> p1 . createdate = datetime . now ( ) <EOL> p1 . lastmoddate = datetime . now ( ) <EOL> p1 . pubdate = datetime . now ( ) <EOL> p1 . format = f <EOL> p1 . status = s3 <EOL> p1 . user = u <EOL> p1 . tags = [ t1 , t2 ] <EOL> p1 . compile ( ) <EOL> db_session . add ( p1 ) <EOL> db_session . commit ( ) <EOL> def install_db ( ) : <EOL> """<STR_LIT>""" <EOL> vc_db ( ) <EOL> upgrade_db ( ) <EOL> add_initial_data ( ) <EOL> def usage ( ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT>' <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) < <NUM_LIT:2> : <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if sys . argv [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> install_db ( ) <EOL> elif sys . argv [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> upgrade_db ( ) <EOL> elif sys . argv [ <NUM_LIT:1> ] == '<STR_LIT>' and len ( sys . argv ) == <NUM_LIT:3> : <EOL> downgrade_db ( sys . argv [ <NUM_LIT:2> ] ) <EOL> else : <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:1> ) </s>
