<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import shutil <EOL> import urllib2 <EOL> import tempfile <EOL> import subprocess <EOL> import argparse <EOL> from flask import json <EOL> from setuptools . package_index import PackageIndex <EOL> from setuptools . archive_util import unpack_archive <EOL> flask_svc_url = '<STR_LIT>' <EOL> if sys . platform == '<STR_LIT>' : <EOL> _tempdir = '<STR_LIT>' <EOL> else : <EOL> _tempdir = tempfile . gettempdir ( ) <EOL> tdir = _tempdir + '<STR_LIT>' <EOL> flaskdir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT:..>' ) ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> RESULT_TEMPATE = u'''<STR_LIT>''' <EOL> def log ( msg , * args ) : <EOL> print '<STR_LIT>' , msg % args <EOL> class TestResult ( object ) : <EOL> def __init__ ( self , name , folder , statuscode , interpreters ) : <EOL> intrptr = os . path . join ( folder , '<STR_LIT>' <EOL> % interpreters [ <NUM_LIT:0> ] ) <EOL> self . statuscode = statuscode <EOL> self . folder = folder <EOL> self . success = statuscode == <NUM_LIT:0> <EOL> def fetch ( field ) : <EOL> try : <EOL> c = subprocess . Popen ( [ intrptr , '<STR_LIT>' , <EOL> '<STR_LIT>' + field ] , cwd = folder , <EOL> stdout = subprocess . PIPE ) <EOL> return c . communicate ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> except OSError : <EOL> return '<STR_LIT:?>' <EOL> self . name = name <EOL> self . license = fetch ( '<STR_LIT>' ) <EOL> self . author = fetch ( '<STR_LIT>' ) <EOL> self . version = fetch ( '<STR_LIT:version>' ) <EOL> self . logs = { } <EOL> for interpreter in interpreters : <EOL> logfile = os . path . join ( folder , '<STR_LIT>' <EOL> % interpreter ) <EOL> if os . path . isfile ( logfile ) : <EOL> self . logs [ interpreter ] = open ( logfile ) . read ( ) <EOL> else : <EOL> self . logs [ interpreter ] = '<STR_LIT>' <EOL> def create_tdir ( ) : <EOL> try : <EOL> shutil . rmtree ( tdir ) <EOL> except Exception : <EOL> pass <EOL> os . mkdir ( tdir ) <EOL> def package_flask ( ) : <EOL> distfolder = tdir + '<STR_LIT>' <EOL> c = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , distfolder ] , cwd = flaskdir ) <EOL> c . wait ( ) <EOL> return os . path . join ( distfolder , os . listdir ( distfolder ) [ <NUM_LIT:0> ] ) <EOL> def get_test_command ( checkout_dir ) : <EOL> if os . path . isfile ( checkout_dir + '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> def fetch_extensions_list ( ) : <EOL> req = urllib2 . Request ( flask_svc_url , headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } ) <EOL> d = urllib2 . urlopen ( req ) . read ( ) <EOL> data = json . loads ( d ) <EOL> for ext in data [ '<STR_LIT>' ] : <EOL> yield ext <EOL> def checkout_extension ( name ) : <EOL> log ( '<STR_LIT>' , name ) <EOL> root = os . path . join ( tdir , name ) <EOL> os . mkdir ( root ) <EOL> checkout_path = PackageIndex ( ) . download ( name , root ) <EOL> unpack_archive ( checkout_path , root ) <EOL> path = None <EOL> for fn in os . listdir ( root ) : <EOL> path = os . path . join ( root , fn ) <EOL> if os . path . isdir ( path ) : <EOL> break <EOL> log ( '<STR_LIT>' , path ) <EOL> return path <EOL> tox_template = """<STR_LIT>""" <EOL> def create_tox_ini ( checkout_path , interpreters , flask_dep ) : <EOL> tox_path = os . path . join ( checkout_path , '<STR_LIT>' ) <EOL> if not os . path . exists ( tox_path ) : <EOL> with open ( tox_path , '<STR_LIT:w>' ) as f : <EOL> f . write ( tox_template % { <EOL> '<STR_LIT>' : '<STR_LIT:U+002C>' . join ( interpreters ) , <EOL> '<STR_LIT>' : tdir , <EOL> '<STR_LIT>' : flask_dep <EOL> } ) <EOL> return tox_path <EOL> def iter_extensions ( only_approved = True ) : <EOL> for ext in fetch_extensions_list ( ) : <EOL> if ext [ '<STR_LIT>' ] or not only_approved : <EOL> yield ext [ '<STR_LIT:name>' ] <EOL> def test_extension ( name , interpreters , flask_dep ) : <EOL> checkout_path = checkout_extension ( name ) <EOL> log ( '<STR_LIT>' , checkout_path ) <EOL> test_command = get_test_command ( checkout_path ) <EOL> log ( '<STR_LIT>' , test_command ) <EOL> f = open ( checkout_path + '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> f . write ( test_command + '<STR_LIT>' ) <EOL> f . close ( ) <EOL> create_tox_ini ( checkout_path , interpreters , flask_dep ) <EOL> rv = subprocess . call ( [ '<STR_LIT>' , '<STR_LIT:-c>' , '<STR_LIT>' ] , cwd = checkout_path ) <EOL> return TestResult ( name , checkout_path , rv , interpreters ) <EOL> def run_tests ( extensions , interpreters ) : <EOL> results = { } <EOL> create_tdir ( ) <EOL> log ( '<STR_LIT>' ) <EOL> flask_dep = package_flask ( ) <EOL> log ( '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' , tdir ) <EOL> for name in extensions : <EOL> log ( '<STR_LIT>' , name ) <EOL> result = test_extension ( name , interpreters , flask_dep ) <EOL> if result . success : <EOL> log ( '<STR_LIT>' ) <EOL> else : <EOL> log ( '<STR_LIT>' ) <EOL> results [ name ] = result <EOL> return results <EOL> def render_results ( results , approved ) : <EOL> from jinja2 import Template <EOL> items = results . values ( ) <EOL> items . sort ( key = lambda x : x . name . lower ( ) ) <EOL> rv = Template ( RESULT_TEMPATE , autoescape = True ) . render ( results = items , <EOL> approved = approved ) <EOL> fd , filename = tempfile . mkstemp ( suffix = '<STR_LIT>' ) <EOL> os . fdopen ( fd , '<STR_LIT:w>' ) . write ( rv . encode ( '<STR_LIT:utf-8>' ) + '<STR_LIT:\n>' ) <EOL> return filename <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT:all>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> if args . extension is not None : <EOL> only_approved = False <EOL> extensions = [ args . extension ] <EOL> else : <EOL> only_approved = not args . all <EOL> extensions = iter_extensions ( only_approved ) <EOL> results = run_tests ( extensions , [ x . strip ( ) for x in args . env . split ( '<STR_LIT:U+002C>' ) ] ) <EOL> filename = render_results ( results , only_approved ) <EOL> if args . browse : <EOL> import webbrowser <EOL> webbrowser . open ( '<STR_LIT>' + filename . lstrip ( '<STR_LIT:/>' ) ) <EOL> print '<STR_LIT>' , filename <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
