<s> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> import argparse <EOL> import os . path <EOL> import shutil <EOL> import sqlite3 <EOL> import flask <EOL> import pkg_resources <EOL> from git_code_debt . server . servlets . changes import changes <EOL> from git_code_debt . server . servlets . commit import commit <EOL> from git_code_debt . server . servlets . graph import graph <EOL> from git_code_debt . server . servlets . index import index <EOL> from git_code_debt . server . servlets . status import status <EOL> from git_code_debt . server . servlets . widget import widget <EOL> app = flask . Flask ( __name__ ) <EOL> app . register_blueprint ( changes ) <EOL> app . register_blueprint ( commit ) <EOL> app . register_blueprint ( graph ) <EOL> app . register_blueprint ( index ) <EOL> app . register_blueprint ( status ) <EOL> app . register_blueprint ( widget ) <EOL> class AppContext ( object ) : <EOL> database_path = '<STR_LIT>' <EOL> @ app . before_request <EOL> def before_request ( ) : <EOL> from git_code_debt . server . metric_config_watcher import watcher <EOL> watcher . reload_if_changed ( ) <EOL> flask . g . db = sqlite3 . connect ( AppContext . database_path ) <EOL> @ app . teardown_request <EOL> def teardown_request ( _ ) : <EOL> flask . g . db . close ( ) <EOL> def create_metric_config_if_not_exists ( ) : <EOL> """<STR_LIT>""" <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> return <EOL> print ( '<STR_LIT>' ) <EOL> shutil . copyfile ( <EOL> pkg_resources . resource_filename ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ) , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def main ( argv = None ) : <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = int , default = <NUM_LIT> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , type = int , default = <NUM_LIT:5> , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> args = parser . parse_args ( argv ) <EOL> if not os . path . exists ( args . database_path ) : <EOL> print ( '<STR_LIT>' . format ( args . database_path ) ) <EOL> print ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> return <NUM_LIT:1> <EOL> create_metric_config_if_not_exists ( ) <EOL> AppContext . database_path = args . database_path <EOL> kwargs = { <EOL> '<STR_LIT:port>' : args . port , <EOL> '<STR_LIT>' : args . debug , <EOL> } <EOL> if not args . debug : <EOL> kwargs [ '<STR_LIT>' ] = args . processes <EOL> app . run ( '<STR_LIT>' , ** kwargs ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> exit ( main ( ) ) </s>
