<s> from fabric . api import * <EOL> import os <EOL> import re <EOL> versionTemplates = { <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> , '<STR_LIT>' : "<STR_LIT>" <EOL> , '<STR_LIT>' : '<STR_LIT>' <EOL> , '<STR_LIT>' : '<STR_LIT>' <EOL> , '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> _old_open = open <EOL> def open ( path , * args , ** kwargs ) : <EOL> return _old_open ( os . path . join ( env . lcwd , path ) , * args , ** kwargs ) <EOL> def _validateVersion ( v ) : <EOL> versionRe = re . compile ( '<STR_LIT>' ) <EOL> m = versionRe . match ( v ) <EOL> if not m : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> valDict = m . groupdict ( ) <EOL> for k in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : valDict [ k ] = int ( valDict [ k ] ) <EOL> return valDict <EOL> class _cloneDir ( object ) : <EOL> def __init__ ( self , gitUrl , project , default_branch ) : <EOL> self . gitUrl = gitUrl <EOL> self . project = project <EOL> self . default_branch = default_branch <EOL> def __call__ ( self , f ) : <EOL> def wrapped_f ( * args , ** kwargs ) : <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' % ( self . gitUrl , self . project ) ) <EOL> with lcd ( os . path . join ( '<STR_LIT:..>' , '<STR_LIT>' , self . project ) ) : <EOL> branch = prompt ( '<STR_LIT>' , <EOL> default = self . default_branch ) <EOL> local ( '<STR_LIT>' % branch ) <EOL> kwargs [ '<STR_LIT>' ] = branch <EOL> f ( * args , ** kwargs ) <EOL> local ( '<STR_LIT>' ) <EOL> return wrapped_f <EOL> def _getReleaseVersion ( ) : <EOL> currentVersionStr = local ( '<STR_LIT>' , capture = True ) . strip ( ) <EOL> cvd = _validateVersion ( currentVersionStr ) <EOL> if not currentVersionStr . endswith ( '<STR_LIT>' ) : <EOL> cvd [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> nextVersionStr = '<STR_LIT>' % ( cvd [ '<STR_LIT>' ] , cvd [ '<STR_LIT>' ] , cvd [ '<STR_LIT>' ] ) <EOL> print '<STR_LIT>' % ( currentVersionStr , nextVersionStr ) <EOL> return cvd <EOL> def _replaceVersionInFile ( filename , matchRe , template , versionCb ) : <EOL> with open ( filename , '<STR_LIT:r>' ) as rfile : <EOL> lines = rfile . readlines ( ) <EOL> currentVersionStr = None <EOL> for linenum , line in enumerate ( lines ) : <EOL> m = matchRe . search ( line ) <EOL> if m : <EOL> vals = m . groupdict ( ) <EOL> indent , currentVersionStr , linesep = vals [ '<STR_LIT>' ] , vals [ '<STR_LIT:version>' ] , line [ - <NUM_LIT:1> ] <EOL> break <EOL> if currentVersionStr is None : <EOL> abort ( '<STR_LIT>' % ( filename ) ) <EOL> version = versionCb ( currentVersionStr ) <EOL> nextVersionStr = '<STR_LIT>' % ( indent , template % version , linesep ) <EOL> lines [ linenum ] = nextVersionStr <EOL> with open ( filename , '<STR_LIT:w>' ) as wfile : <EOL> wfile . writelines ( lines ) <EOL> def _gitTag ( version , branch = '<STR_LIT>' ) : <EOL> with hide ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> remotes = local ( '<STR_LIT>' , capture = True ) . split ( ) <EOL> if len ( remotes ) == <NUM_LIT:0> : <EOL> abort ( '<STR_LIT>' ) <EOL> remote = ( '<STR_LIT>' if '<STR_LIT>' in remotes else <EOL> '<STR_LIT>' if '<STR_LIT>' in remotes else <EOL> '<STR_LIT>' if '<STR_LIT>' in remotes else <EOL> remotes [ <NUM_LIT:0> ] ) <EOL> if not remote in remotes : <EOL> abort ( '<STR_LIT>' % ( remote ) ) <EOL> versionTag = versionTemplates [ '<STR_LIT>' ] % version <EOL> versionMsg = versionTemplates [ '<STR_LIT>' ] % version <EOL> comment = prompt ( '<STR_LIT>' , default = '<STR_LIT>' ) <EOL> if comment != '<STR_LIT>' : <EOL> versionMsg += '<STR_LIT>' + comment <EOL> local ( '<STR_LIT>' % ( versionMsg ) ) <EOL> commit = local ( '<STR_LIT>' , capture = True ) <EOL> local ( '<STR_LIT>' % ( versionTag , versionMsg , commit ) ) <EOL> print versionTag , versionMsg , commit <EOL> return remote <EOL> @ _cloneDir ( gitUrl = '<STR_LIT>' , <EOL> project = '<STR_LIT>' , <EOL> default_branch = '<STR_LIT>' ) <EOL> def release ( branch ) : <EOL> nextVersionD = _getReleaseVersion ( ) <EOL> version_re = re . compile ( "<STR_LIT>" ) <EOL> _replaceVersionInFile ( '<STR_LIT>' , version_re , <EOL> versionTemplates [ '<STR_LIT>' ] , lambda old : nextVersionD ) <EOL> remote = _gitTag ( nextVersionD , branch = branch ) <EOL> nextVersionD [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> _replaceVersionInFile ( '<STR_LIT>' , version_re , <EOL> versionTemplates [ '<STR_LIT>' ] , lambda old : nextVersionD ) <EOL> devMsg = versionTemplates [ '<STR_LIT>' ] % nextVersionD <EOL> local ( '<STR_LIT>' % devMsg ) <EOL> local ( '<STR_LIT>' % ( remote ) ) <EOL> local ( '<STR_LIT>' % ( remote , branch ) ) </s>
