<s> import os <EOL> import sys <EOL> import json <EOL> import argparse <EOL> from calvin . csparser . parser import calvin_parser <EOL> from calvin . csparser . checker import check <EOL> from calvin . csparser . analyzer import generate_app_info <EOL> from calvin . utilities . security import Security <EOL> from calvin . utilities . calvinlogger import get_logger <EOL> _log = get_logger ( __name__ ) <EOL> def compile ( source_text , filename = '<STR_LIT>' , content = None , credentials = None , verify = True ) : <EOL> deployable = { '<STR_LIT>' : False , '<STR_LIT>' : { } , '<STR_LIT>' : { } } <EOL> errors = [ ] <EOL> warnings = [ ] <EOL> if credentials : <EOL> _log . debug ( "<STR_LIT>" ) <EOL> sec = Security ( ) <EOL> sec . set_principal ( credentials ) <EOL> if not sec . authenticate_principal ( ) : <EOL> _log . error ( "<STR_LIT>" ) <EOL> errors . append ( { '<STR_LIT>' : "<STR_LIT>" , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> return deployable , errors , warnings <EOL> if not sec . verify_signature_content ( content , "<STR_LIT>" ) : <EOL> _log . error ( "<STR_LIT>" ) <EOL> errors . append ( { '<STR_LIT>' : "<STR_LIT>" , '<STR_LIT>' : None , '<STR_LIT>' : None } ) <EOL> return deployable , errors , warnings <EOL> _log . debug ( "<STR_LIT>" ) <EOL> ir , errors , warnings = calvin_parser ( source_text , filename ) <EOL> _log . debug ( "<STR_LIT>" % ( ir , errors , warnings ) ) <EOL> if not errors : <EOL> c_errors , c_warnings = check ( ir , verify = verify ) <EOL> errors . extend ( c_errors ) <EOL> warnings . extend ( c_warnings ) <EOL> deployable = generate_app_info ( ir , verify = verify ) <EOL> if errors : <EOL> deployable [ '<STR_LIT>' ] = False <EOL> _log . debug ( "<STR_LIT>" % ( deployable , errors , warnings ) ) <EOL> return deployable , errors , warnings <EOL> def compile_file ( file , credentials = None ) : <EOL> with open ( file , '<STR_LIT:r>' ) as source : <EOL> sourceText = source . read ( ) <EOL> content = None <EOL> if credentials : <EOL> content = Security . verify_signature_get_files ( file , skip_file = True ) <EOL> if content : <EOL> content [ '<STR_LIT:file>' ] = sourceText <EOL> return compile ( sourceText , file , content = content , credentials = credentials ) <EOL> def compile_generator ( files ) : <EOL> for file in files : <EOL> deployable , errors , warnings = compile_file ( file ) <EOL> yield ( ( deployable , errors , warnings , file ) ) <EOL> def remove_debug_info ( deployable ) : <EOL> pass <EOL> def main ( ) : <EOL> long_description = """<STR_LIT>""" <EOL> argparser = argparse . ArgumentParser ( description = long_description ) <EOL> argparser . add_argument ( '<STR_LIT>' , metavar = '<STR_LIT>' , type = str , nargs = '<STR_LIT:+>' , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT>' , const = None , default = <NUM_LIT:4> , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , type = str , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> args = argparser . parse_args ( ) <EOL> def report_issues ( issues , issue_type , file = '<STR_LIT>' ) : <EOL> sorted_issues = sorted ( issues , key = lambda k : k . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> for issue in sorted_issues : <EOL> sys . stderr . write ( args . fmt . format ( script = file , issue_type = issue_type , ** issue ) + '<STR_LIT:\n>' ) <EOL> exit_code = <NUM_LIT:0> <EOL> for deployable , errors , warnings , file in compile_generator ( args . files ) : <EOL> if errors : <EOL> report_issues ( errors , '<STR_LIT>' , file ) <EOL> exit_code = <NUM_LIT:1> <EOL> if warnings and args . verbose : <EOL> report_issues ( warnings , '<STR_LIT>' , file ) <EOL> if exit_code == <NUM_LIT:1> : <EOL> continue <EOL> if not args . debug : <EOL> remove_debug_info ( deployable ) <EOL> string_rep = json . dumps ( deployable , indent = args . indent , sort_keys = args . sorted ) <EOL> if args . to_stdout : <EOL> print ( string_rep ) <EOL> else : <EOL> path , ext = os . path . splitext ( file ) <EOL> dst = path + "<STR_LIT>" <EOL> with open ( dst , '<STR_LIT:w>' ) as f : <EOL> f . write ( string_rep ) <EOL> return exit_code <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main ( ) ) </s>
