#NEWLINE# def build_changelog( docs_path , package_name = 'mezzanine' ) : #NEWLINE# #INDENT# '\n    Converts Mercurial commits into a changelog in RST format.\n    ' #NEWLINE# project_path = os . path . join ( docs_path , '..' ) #NEWLINE# version_file = os . path . join ( package_name , '__init__.py' ) #NEWLINE# version_var = '__version__' #NEWLINE# changelog_filename = 'CHANGELOG' #NEWLINE# changelog_file = os . path . join ( project_path , changelog_filename ) #NEWLINE# versions = OrderedDict ( ) #NEWLINE# repo = None #NEWLINE# ignore = ( 'AUTHORS' , 'formatting' , 'typo' , 'pep8' , 'pep 8' , 'whitespace' , 'README' , 'trans' , 'print debug' , 'debugging' , 'tabs' , 'style' , 'sites' , 'ignore' , 'tweak' , 'cleanup' , 'minor' , 'for changeset' , '.com``' , 'oops' , 'syntax' ) #NEWLINE# hotfixes = { #NEWLINE# #INDENT# '40cbc47b8d8a' : '1.0.9' , #NEWLINE# 'a25749986abc' : '1.0.10' , #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# from mercurial import ui , hg , error #NEWLINE# from mercurial.commands import tag #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ui = ui . ui ( ) #NEWLINE# repo = hg . repository ( ui , project_path ) #NEWLINE# #UNINDENT# except error . RepoError : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# if ( repo is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# changesets = [ repo . changectx ( changeset ) for changeset in repo . changelog ] #NEWLINE# for cs in sorted ( changesets , reverse = True , key = _changeset_date ) : #NEWLINE# #INDENT# files = cs . files ( ) #NEWLINE# new_version = False #NEWLINE# description = cs . description ( ) . decode ( 'utf-8' ) #NEWLINE# description = description . rstrip ( '.' ) . replace ( '\n' , '. ' ) #NEWLINE# while ( '  ' in description ) : #NEWLINE# #INDENT# description = description . replace ( '  ' , ' ' ) #NEWLINE# #UNINDENT# description = description . replace ( '. . ' , '. ' ) . replace ( '...' , ',' ) #NEWLINE# while ( '..' in description ) : #NEWLINE# #INDENT# description = description . replace ( '..' , '.' ) #NEWLINE# #UNINDENT# description = description . replace ( ':.' , ':' ) . replace ( "n'. t" , "n't" ) #NEWLINE# words = description . split ( ) #NEWLINE# for ( i , word ) in enumerate ( words ) : #NEWLINE# #INDENT# if ( ( set ( '._' ) & set ( word [ : ( - 1 ) ] ) ) and ( set ( letters ) & set ( word ) ) and ( '`' not in word ) and ( not word [ 0 ] . isdigit ( ) ) ) : #NEWLINE# #INDENT# last = '' #NEWLINE# if ( word [ ( - 1 ) ] in ',.' ) : #NEWLINE# #INDENT# ( last , word ) = ( word [ ( - 1 ) ] , word [ : ( - 1 ) ] ) #NEWLINE# #UNINDENT# words [ i ] = ( '``%s``%s' % ( word , last ) ) #NEWLINE# #UNINDENT# #UNINDENT# description = ' ' . join ( words ) #NEWLINE# if ( version_file in files ) : #NEWLINE# #INDENT# for line in cs [ version_file ] . data ( ) . split ( '\n' ) : #NEWLINE# #INDENT# if line . startswith ( version_var ) : #NEWLINE# #INDENT# exec ( line ) #NEWLINE# if ( locals ( ) [ version_var ] == '0.1.0' ) : #NEWLINE# #INDENT# locals ( ) [ version_var ] = '1.0.0' #NEWLINE# break #NEWLINE# #UNINDENT# versions [ locals ( ) [ version_var ] ] = { #NEWLINE# #INDENT# 'changes' : [ ] , #NEWLINE# 'date' : _changeset_date ( cs ) . strftime ( '%b %d, %Y' ) , #NEWLINE# #UNINDENT# } #NEWLINE# new_version = ( len ( files ) == 1 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# hotfix = hotfixes . get ( cs . hex ( ) [ : 12 ] ) #NEWLINE# if ( hotfix or new_version ) : #NEWLINE# #INDENT# if hotfix : #NEWLINE# #INDENT# version_tag = hotfix #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# version_tag = locals ( ) [ version_var ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# version_tag = None #NEWLINE# #UNINDENT# #UNINDENT# if ( version_tag and ( version_tag not in cs . tags ( ) ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# tag ( ui , repo , version_tag , rev = cs . hex ( ) ) #NEWLINE# print ( ( 'Tagging version %s' % version_tag ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# merge = ( len ( cs . parents ( ) ) > 1 ) #NEWLINE# branch_closed = ( len ( files ) == 0 ) #NEWLINE# changelog_update = ( changelog_filename in files ) #NEWLINE# ignored = [ w for w in ignore if ( w . lower ( ) in description . lower ( ) ) ] #NEWLINE# too_few_words = ( len ( description . split ( ) ) <= 3 ) #NEWLINE# if ( merge or new_version or branch_closed or changelog_update or ignored or too_few_words ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# version = None #NEWLINE# try : #NEWLINE# #INDENT# version = locals ( ) [ version_var ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# if ( not hotfix ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# user = cs . user ( ) . decode ( 'utf-8' ) . split ( '<' ) [ 0 ] . strip ( ) #NEWLINE# entry = ( '%s - %s' % ( description , user ) ) #NEWLINE# if ( hotfix or ( entry not in changelog_filename [ version ] [ 'changes' ] ) ) : #NEWLINE# #INDENT# if hotfix : #NEWLINE# #INDENT# versions [ hotfix ] = { #NEWLINE# #INDENT# 'changes' : [ entry ] , #NEWLINE# 'date' : _changeset_date ( cs ) . strftime ( '%b %d, %Y' ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# versions [ version ] [ 'changes' ] . insert ( 0 , entry ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# with open ( changelog_file , 'w' ) as f : #NEWLINE# #INDENT# for ( version , version_info ) in versions . items ( ) : #NEWLINE# #INDENT# header = ( 'Version %s (%s)' % ( version , version_info [ 'date' ] ) ) #NEWLINE# f . write ( ( '%s\n' % header ) ) #NEWLINE# f . write ( ( '%s\n' % ( '-' * len ( header ) ) ) ) #NEWLINE# f . write ( '\n' ) #NEWLINE# if version_info [ 'changes' ] : #NEWLINE# #INDENT# for change in version_info [ 'changes' ] : #NEWLINE# #INDENT# f . write ( ( '  * %s\n' % change ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# f . write ( '  * No changes listed.\n' ) #NEWLINE# #UNINDENT# f . write ( '\n' )