<s> import sys <EOL> import os <EOL> import platform <EOL> import re <EOL> import imp <EOL> import subprocess <EOL> import logging <EOL> import argparse <EOL> import string <EOL> import urlparse <EOL> import django <EOL> from random import choice <EOL> logging . basicConfig ( level = logging . INFO , <EOL> format = '<STR_LIT>' ) <EOL> cwd = os . getcwd ( ) <EOL> PASSWORD_LETTERBANK = string . letters + string . digits <EOL> PASSWORD_LETTERBANK = PASSWORD_LETTERBANK . replace ( "<STR_LIT:O>" , "<STR_LIT>" ) <EOL> def get_input ( p , d ) : <EOL> v = raw_input ( "<STR_LIT>" % ( p , d ) ) <EOL> if v : return v <EOL> return d <EOL> def do_sed ( t , n , v ) : <EOL> v = re . sub ( "<STR_LIT:/>" , r'<STR_LIT>' , v ) <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> c = "<STR_LIT>" % ( n , v , t ) <EOL> else : <EOL> c = "<STR_LIT>" % ( n , v , t ) <EOL> o = call_command ( c ) <EOL> print o <EOL> return o <EOL> def fill_field ( t , n , v ) : <EOL> return do_sed ( t , "<STR_LIT>" % n , v ) <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT:-c>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> repos = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> reloadflag = "<STR_LIT>" <EOL> if django . VERSION [ : <NUM_LIT:3> ] <= ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:0> ) : <EOL> reloadflag = "<STR_LIT>" <EOL> if args . branch_dev : <EOL> args . using_branch = "<STR_LIT>" <EOL> if args . using_branch : <EOL> print "<STR_LIT>" , args . using_branch <EOL> if not args . all_steps and not ( <EOL> args . clone_git or <EOL> args . update_git or <EOL> args . generate_settings or <EOL> args . generate_sample_data or <EOL> args . load_sample_data or <EOL> args . create_user or <EOL> args . kill_servers or <EOL> args . reset_servers or <EOL> args . run_app_server or <EOL> args . run_api_servers ) : <EOL> parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if args . all_steps : <EOL> args . clone_git = True <EOL> args . generate_settings = True <EOL> args . generate_sample_data = True <EOL> args . load_sample_data = True <EOL> args . create_user = True <EOL> args . kill_servers = True <EOL> args . run_app_server = True <EOL> args . reset_servers = True <EOL> args . run_api_servers = True <EOL> if args . clone_git : <EOL> if not args . using_branch : <EOL> args . using_branch = "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> for r in repos : <EOL> call_command ( "<STR_LIT>" + r + "<STR_LIT>" , <EOL> print_output = True ) <EOL> if args . update_git or args . clone_git : <EOL> for r in repos : <EOL> if args . using_branch : <EOL> call_command ( "<STR_LIT>" + r + "<STR_LIT>" + args . using_branch + "<STR_LIT>" ) <EOL> call_command ( "<STR_LIT>" + r + "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" , <EOL> print_output = True ) <EOL> if args . generate_settings : <EOL> print "<STR_LIT>" <EOL> api_server_base_url = get_input ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> chrome_consumer = get_input ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> chrome_secret = get_input ( "<STR_LIT>" , <EOL> '<STR_LIT>' . join ( [ choice ( PASSWORD_LETTERBANK ) for i in range ( <NUM_LIT:8> ) ] ) ) <EOL> db_password = get_input ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ui_server_base_url = get_input ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> app_server_base_url = get_input ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> standalone_mode = get_input ( <EOL> """<STR_LIT>""" , "<STR_LIT:yes>" ) <EOL> if standalone_mode == "<STR_LIT>" : <EOL> proxy_base = get_input ( "<STR_LIT>" , <EOL> "<STR_LIT:none>" ) <EOL> proxy_user = get_input ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> call_command ( "<STR_LIT>" ) <EOL> call_command ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> call_command ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , app_server_base_url ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , app_server_base_url ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , ui_server_base_url ) <EOL> call_command ( "<STR_LIT>" ) <EOL> call_command ( "<STR_LIT>" ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , <EOL> os . path . join ( cwd , "<STR_LIT>" ) ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , <EOL> os . path . join ( cwd , "<STR_LIT>" ) ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , <EOL> os . path . join ( cwd , "<STR_LIT>" ) ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , api_server_base_url ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , api_server_base_url ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , app_server_base_url ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , api_server_base_url ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , chrome_consumer ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , chrome_secret ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , db_password ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , chrome_consumer ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , chrome_secret ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , db_password ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , db_password ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' . join ( [ choice ( PASSWORD_LETTERBANK ) for i in range ( <NUM_LIT:8> ) ] ) ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' . join ( [ choice ( PASSWORD_LETTERBANK ) for i in range ( <NUM_LIT:8> ) ] ) ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' . join ( [ choice ( PASSWORD_LETTERBANK ) for i in range ( <NUM_LIT:8> ) ] ) ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , ui_server_base_url ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if standalone_mode == "<STR_LIT>" : <EOL> print "<STR_LIT>" <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:True>' ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , proxy_user ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , proxy_base ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:False>' ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> fill_field ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> if args . run_app_server or args . run_api_servers : <EOL> args . kill_servers = True <EOL> server_settings = imp . load_source ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> app_settings = imp . load_source ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> app_server = app_settings . SMART_APP_SERVER_BASE <EOL> api_server = server_settings . SITE_URL_PREFIX <EOL> ui_server = server_settings . SMART_UI_SERVER_LOCATION <EOL> if args . kill_servers : <EOL> call_command ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" , failure_okay = True ) <EOL> if args . generate_sample_data : <EOL> call_command ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" , print_output = True ) <EOL> if args . run_app_server : <EOL> port = get_port ( app_server ) <EOL> print "<STR_LIT>" , port <EOL> call_command ( "<STR_LIT>" % ( reloadflag , port ) , <EOL> print_output = True ) <EOL> call_command ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" <EOL> if args . reset_servers : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> call_command ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" , print_output = True ) <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> call_command ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" , print_output = True ) <EOL> if args . load_sample_data : <EOL> call_command ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , print_output = True ) <EOL> if args . create_user : <EOL> print "<STR_LIT>" <EOL> given_name = get_input ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> family_name = get_input ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> email = get_input ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> password = get_input ( "<STR_LIT>" , "<STR_LIT:password>" ) <EOL> call_command ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> given_name + "<STR_LIT:U+0020>" + <EOL> family_name + "<STR_LIT:U+0020>" + <EOL> email + "<STR_LIT:U+0020>" + <EOL> password + "<STR_LIT>" <EOL> "<STR_LIT>" , print_output = True ) <EOL> if args . run_api_servers : <EOL> port = get_port ( api_server ) <EOL> print "<STR_LIT>" , port <EOL> call_command ( "<STR_LIT>" % ( reloadflag , port ) , <EOL> print_output = True ) <EOL> print "<STR_LIT>" <EOL> port = get_port ( ui_server ) <EOL> print "<STR_LIT>" , port <EOL> call_command ( "<STR_LIT>" % ( reloadflag , port ) , <EOL> print_output = True ) <EOL> call_command ( "<STR_LIT>" ) <EOL> def get_port ( url ) : <EOL> server = urlparse . urlparse ( url ) <EOL> port = server . port <EOL> if not port : <EOL> port = ( server . scheme == "<STR_LIT:http>" and <NUM_LIT> or server . scheme == "<STR_LIT>" and <NUM_LIT> ) <EOL> return port <EOL> def call_command ( command , print_output = False , failure_okay = False ) : <EOL> print command <EOL> ret = "<STR_LIT>" <EOL> if print_output : <EOL> ret = os . system ( command ) <EOL> assert failure_okay or os . WEXITSTATUS ( ret ) == <NUM_LIT:0> , "<STR_LIT>" <EOL> else : <EOL> try : <EOL> ret = subprocess . check_output ( command , shell = True , <EOL> stderr = subprocess . STDOUT ) <EOL> except subprocess . CalledProcessError : <EOL> if not failure_okay : <EOL> assert False , "<STR_LIT>" <EOL> return ret <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
