<s> from __future__ import with_statement <EOL> import re <EOL> import argparse <EOL> from collections import defaultdict <EOL> JIRA_URL = '<STR_LIT>' <EOL> GITHUB_URL = '<STR_LIT>' <EOL> def parse_changes_file ( file_path , versions = None ) : <EOL> """<STR_LIT>""" <EOL> contributors_map = defaultdict ( set ) <EOL> in_entry = False <EOL> active_version = None <EOL> active_tickets = [ ] <EOL> with open ( file_path , '<STR_LIT:r>' ) as fp : <EOL> for line in fp : <EOL> line = line . strip ( ) <EOL> match = re . search ( r'<STR_LIT>' <EOL> '<STR_LIT>' , line ) <EOL> if match : <EOL> active_version = match . groups ( ) [ <NUM_LIT:0> ] <EOL> if versions and active_version not in versions : <EOL> continue <EOL> if line . startswith ( '<STR_LIT:->' ) or line . startswith ( '<STR_LIT>' ) : <EOL> in_entry = True <EOL> active_tickets = [ ] <EOL> if in_entry and line == '<STR_LIT>' : <EOL> in_entry = False <EOL> if in_entry : <EOL> match = re . search ( r'<STR_LIT>' , line ) <EOL> if match : <EOL> active_tickets = match . groups ( ) [ <NUM_LIT:0> ] <EOL> active_tickets = active_tickets . split ( '<STR_LIT:U+002CU+0020>' ) <EOL> active_tickets = [ ticket for ticket in active_tickets if <EOL> ticket . startswith ( '<STR_LIT>' ) or <EOL> ticket . startswith ( '<STR_LIT>' ) ] <EOL> match = re . search ( r'<STR_LIT>' , line ) <EOL> if match : <EOL> contributors = match . groups ( ) [ <NUM_LIT:0> ] <EOL> contributors = contributors . split ( '<STR_LIT:U+002C>' ) <EOL> contributors = [ name . strip ( ) for name in contributors ] <EOL> for name in contributors : <EOL> name = name . title ( ) <EOL> contributors_map [ name ] . update ( set ( active_tickets ) ) <EOL> return contributors_map <EOL> def convert_to_markdown ( contributors_map , include_tickets = False ) : <EOL> def compare ( item1 , item2 ) : <EOL> lastname1 = item1 . split ( '<STR_LIT:U+0020>' ) [ - <NUM_LIT:1> ] . lower ( ) <EOL> lastname2 = item2 . split ( '<STR_LIT:U+0020>' ) [ - <NUM_LIT:1> ] . lower ( ) <EOL> return cmp ( lastname1 , lastname2 ) <EOL> names = contributors_map . keys ( ) <EOL> names = sorted ( names , cmp = compare ) <EOL> result = [ ] <EOL> for name in names : <EOL> tickets = contributors_map [ name ] <EOL> tickets_string = [ ] <EOL> for ticket in tickets : <EOL> if '<STR_LIT:->' not in ticket : <EOL> continue <EOL> number = ticket . split ( '<STR_LIT:->' ) [ <NUM_LIT:1> ] <EOL> if ticket . startswith ( '<STR_LIT>' ) : <EOL> url = JIRA_URL % ( number ) <EOL> elif ticket . startswith ( '<STR_LIT>' ) or ticket . startswith ( '<STR_LIT>' ) : <EOL> url = GITHUB_URL % ( number ) <EOL> values = { '<STR_LIT>' : ticket , '<STR_LIT:url>' : url } <EOL> tickets_string . append ( '<STR_LIT>' % values ) <EOL> tickets_string = '<STR_LIT:U+002CU+0020>' . join ( tickets_string ) <EOL> if include_tickets : <EOL> line = '<STR_LIT>' % { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : tickets_string } <EOL> else : <EOL> line = '<STR_LIT>' % { '<STR_LIT:name>' : name } <EOL> result . append ( line . strip ( ) ) <EOL> result = '<STR_LIT:\n>' . join ( result ) <EOL> return result <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , required = True , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , nargs = '<STR_LIT:+>' , <EOL> type = str , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> contributors_map = parse_changes_file ( file_path = args . changes_path , <EOL> versions = args . versions ) <EOL> markdown = convert_to_markdown ( contributors_map = contributors_map , <EOL> include_tickets = args . include_tickets ) <EOL> print ( markdown ) </s>
