<s> """<STR_LIT>""" <EOL> import os <EOL> from coverage . misc import CoverageException <EOL> from fabric . api import lcd , local , settings <EOL> from fabric . colors import _wrap_with <EOL> from settings import ( <EOL> DATABASES , <EOL> MEDIA_ROOT , <EOL> PROJECT_ROOT , <EOL> TEST_APPS , <EOL> ) <EOL> from fabfile import fab_settings <EOL> GREEN_BG = _wrap_with ( '<STR_LIT>' ) <EOL> RED_BG = _wrap_with ( '<STR_LIT>' ) <EOL> def _get_test_apps ( all = '<STR_LIT:1>' ) : <EOL> """<STR_LIT>""" <EOL> apps = TEST_APPS <EOL> if all == '<STR_LIT:1>' : <EOL> apps . append ( '<STR_LIT>' ) <EOL> return apps <EOL> def _get_test_command ( apps = None , options = None , all = '<STR_LIT:1>' ) : <EOL> """<STR_LIT>""" <EOL> if apps is None : <EOL> apps = '<STR_LIT:U+0020>' . join ( _get_test_apps ( all = all ) ) <EOL> else : <EOL> apps = apps . split ( '<STR_LIT:U+002C>' ) <EOL> command = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( apps ) <EOL> ) <EOL> if options : <EOL> command += '<STR_LIT>' . format ( options ) <EOL> return command <EOL> def check ( ) : <EOL> """<STR_LIT>""" <EOL> flake8 ( ) <EOL> test ( ) <EOL> coverage ( <NUM_LIT:0> ) <EOL> def coverage ( html = '<STR_LIT:1>' ) : <EOL> """<STR_LIT>""" <EOL> apps = _get_test_apps ( ) <EOL> command = _get_test_command ( apps = '<STR_LIT:U+002C>' . join ( apps ) ) <EOL> local ( '<STR_LIT>' % ( '<STR_LIT:U+002C>' . join ( apps ) , command ) ) <EOL> if html == '<STR_LIT:1>' : <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> def _coverage ( html = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> not_html = not int ( html ) <EOL> settings_file = ( not_html and '<STR_LIT>' <EOL> or '<STR_LIT>' ) <EOL> try : <EOL> results = local ( '<STR_LIT>' . format ( <EOL> settings_file , '<STR_LIT:U+0020>' . join ( TEST_APPS ) ) , capture = not_html ) <EOL> except : <EOL> raise CoverageException ( <EOL> RED_BG ( "<STR_LIT>" ) ) <EOL> if not_html : <EOL> global_percentage = int ( results . split ( "<STR_LIT:\n>" ) [ - <NUM_LIT:3> ] . split ( ) [ - <NUM_LIT:1> ] [ : - <NUM_LIT:1> ] ) <EOL> files_percents = dict ( ( <EOL> line . split ( ) [ <NUM_LIT:0> ] , <EOL> int ( line . split ( ) [ <NUM_LIT:3> ] [ : - <NUM_LIT:1> ] ) , <EOL> ) for line in results . split ( "<STR_LIT:->" * <NUM_LIT> ) [ <NUM_LIT:1> ] . split ( "<STR_LIT:\n>" ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) <EOL> errors = [ ] <EOL> for name , percentage in files_percents . iteritems ( ) : <EOL> if percentage < <NUM_LIT> : <EOL> errors . append ( RED_BG ( <EOL> '<STR_LIT>' . format ( <EOL> name , percentage ) ) ) <EOL> if errors : <EOL> raise CoverageException ( <EOL> "<STR_LIT>" . format ( <EOL> "<STR_LIT>" . join ( errors ) ) ) <EOL> else : <EOL> print ( GREEN_BG ( '<STR_LIT>' . format ( <EOL> global_percentage ) ) ) <EOL> else : <EOL> local ( '<STR_LIT>' . format ( fab_settings . WWW_OPEN ) ) <EOL> def delete_db ( ) : <EOL> """<STR_LIT>""" <EOL> local ( '<STR_LIT>' ) <EOL> def dumpdata ( ) : <EOL> """<STR_LIT>""" <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> def export_db ( ) : <EOL> """<STR_LIT>""" <EOL> db_engine = DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> db_user = DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> db_name = DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> db_password = DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in db_engine : <EOL> print ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in db_engine : <EOL> local ( '<STR_LIT>' . format ( db_user , db_name ) ) <EOL> if '<STR_LIT>' in db_engine : <EOL> local ( '<STR_LIT>' . format ( db_user , <EOL> db_password , db_name ) ) <EOL> def flake8 ( ) : <EOL> """<STR_LIT>""" <EOL> local ( "<STR_LIT>" ) <EOL> def import_db ( ) : <EOL> """<STR_LIT>""" <EOL> db_engine = DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> db_user = DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> db_name = DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> db_password = DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in db_engine : <EOL> print ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in db_engine : <EOL> local ( '<STR_LIT>' . format ( db_user , db_name ) ) <EOL> if '<STR_LIT>' in db_engine : <EOL> local ( '<STR_LIT>' . format ( db_user , <EOL> db_password , db_name ) ) <EOL> def push ( ) : <EOL> """<STR_LIT>""" <EOL> check ( ) <EOL> local ( "<STR_LIT>" ) <EOL> def rebuild ( ) : <EOL> """<STR_LIT>""" <EOL> rebuild_db ( ) <EOL> rebuild_media ( ) <EOL> local ( '<STR_LIT>' ) <EOL> def rebuild_db ( ) : <EOL> """<STR_LIT>""" <EOL> delete_db ( ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> def rebuild_media ( ) : <EOL> """<STR_LIT>""" <EOL> local ( '<STR_LIT>' % MEDIA_ROOT ) <EOL> media_fixtures_path = os . path . join ( PROJECT_ROOT , <EOL> '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' % media_fixtures_path ) <EOL> local ( '<STR_LIT>' % ( media_fixtures_path , MEDIA_ROOT ) ) <EOL> def replace_media ( ) : <EOL> """<STR_LIT>""" <EOL> with lcd ( '<STR_LIT>' ) : <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' . format ( <EOL> fab_settings . PROJECT_NAME ) ) <EOL> def test ( apps = '<STR_LIT:U+002C>' . join ( TEST_APPS ) , options = None , all = '<STR_LIT:1>' ) : <EOL> """<STR_LIT>""" <EOL> if all == '<STR_LIT:1>' : <EOL> apps += '<STR_LIT>' <EOL> command = _get_test_command ( apps = apps , options = options , all = all ) <EOL> with settings ( warn_only = True ) : <EOL> result = local ( command , capture = False ) <EOL> if result . failed : <EOL> print RED_BG ( '<STR_LIT>' ) <EOL> else : <EOL> print GREEN_BG ( '<STR_LIT>' ) </s>
