<s> import sys <EOL> import re <EOL> import pprint <EOL> import os <EOL> try : <EOL> import json <EOL> except ImportError , e : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> exit ( <NUM_LIT:2> ) <EOL> builders = [ '<STR_LIT>' ] <EOL> md_header = """<STR_LIT>""" <EOL> def main ( argv ) : <EOL> if len ( sys . argv ) < <NUM_LIT:3> : <EOL> print "<STR_LIT>" + sys . argv [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> exit ( <NUM_LIT:1> ) <EOL> jenkins_output_file = sys . argv [ <NUM_LIT:1> ] <EOL> artifact_file_location = sys . argv [ <NUM_LIT:2> ] <EOL> build_number = sys . argv [ <NUM_LIT:3> ] <EOL> ubuntu_version = sys . argv [ <NUM_LIT:4> ] <EOL> if not os . path . isfile ( jenkins_output_file ) : <EOL> print "<STR_LIT>" + jenkins_output_file + "<STR_LIT>" + sys . argv [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> exit ( <NUM_LIT:1> ) <EOL> if not os . path . isdir ( artifact_file_location ) : <EOL> print "<STR_LIT>" + artifact_file_location + "<STR_LIT>" + sys . argv [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> exit ( <NUM_LIT:1> ) <EOL> pp = pprint . PrettyPrinter ( indent = <NUM_LIT:4> ) <EOL> amis = { } <EOL> artifact_file_md = "<STR_LIT>" <EOL> artifact_file_json = "<STR_LIT>" <EOL> fo = open ( jenkins_output_file , '<STR_LIT:r>' ) <EOL> for line in fo : <EOL> for builder in builders : <EOL> if re . match ( '<STR_LIT>' , builder ) : <EOL> instance_type = '<STR_LIT>' <EOL> else : <EOL> instance_type = '<STR_LIT>' <EOL> if instance_type not in amis : <EOL> amis [ instance_type ] = { } <EOL> string_to_search_for = "<STR_LIT>" + builder + '<STR_LIT>' <EOL> if re . match ( string_to_search_for , line ) : <EOL> temp_line = re . sub ( string_to_search_for , '<STR_LIT>' , line ) <EOL> data = temp_line . split ( "<STR_LIT>" ) <EOL> for block in data : <EOL> if block != '<STR_LIT>' : <EOL> block = re . sub ( '<STR_LIT>' , '<STR_LIT>' , block ) <EOL> ( region , ami_id ) = block . split ( '<STR_LIT::>' ) <EOL> amis [ instance_type ] [ region ] = ami_id <EOL> fo . close ( ) <EOL> name = '<STR_LIT>' + ubuntu_version + '<STR_LIT:->' + build_number <EOL> ubuntu_version = '<STR_LIT>' <EOL> amazon_console_prefix = '<STR_LIT>' <EOL> md_fo = open ( artifact_file_location + '<STR_LIT:/>' + artifact_file_md , '<STR_LIT>' ) <EOL> md_fo . write ( md_header ) <EOL> for instance_type in amis : <EOL> for region in amis [ instance_type ] : <EOL> ami_id = amis [ instance_type ] [ region ] <EOL> line_to_write = '<STR_LIT:|>' + region + '<STR_LIT:|>' + name + '<STR_LIT:|>' + ubuntu_version + '<STR_LIT:|>' + instance_type + '<STR_LIT:|>' + '<STR_LIT:[>' + ami_id + '<STR_LIT>' + amazon_console_prefix + region + '<STR_LIT>' + ami_id + '<STR_LIT>' <EOL> md_fo . write ( line_to_write ) <EOL> md_fo . close ( ) <EOL> json_fo = open ( artifact_file_location + '<STR_LIT:/>' + artifact_file_json , '<STR_LIT>' ) <EOL> json_fo . write ( json . dumps ( amis , indent = <NUM_LIT:4> , sort_keys = True ) ) <EOL> json_fo . close ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( sys . argv ) </s>
