<s> import sys <EOL> import os <EOL> from os . path import join , dirname , normpath , abspath , exists , basename <EOL> import re <EOL> from glob import glob <EOL> import codecs <EOL> import webbrowser <EOL> import mklib <EOL> assert mklib . __version_info__ >= ( <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT:2> ) <EOL> from mklib . common import MkError <EOL> from mklib import Task , mk <EOL> from mklib import sh <EOL> class bugs ( Task ) : <EOL> """<STR_LIT>""" <EOL> def make ( self ) : <EOL> webbrowser . open ( "<STR_LIT>" ) <EOL> class site ( Task ) : <EOL> """<STR_LIT>""" <EOL> def make ( self ) : <EOL> webbrowser . open ( "<STR_LIT>" ) <EOL> class pypi ( Task ) : <EOL> """<STR_LIT>""" <EOL> def make ( self ) : <EOL> webbrowser . open ( "<STR_LIT>" ) <EOL> class cut_a_release ( Task ) : <EOL> """<STR_LIT>""" <EOL> proj_name = "<STR_LIT>" <EOL> version_py_path = "<STR_LIT>" <EOL> version_module = "<STR_LIT>" <EOL> _changes_parser = re . compile ( r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' % proj_name , re . M | re . S ) <EOL> def make ( self ) : <EOL> DRY_RUN = False <EOL> version = self . _get_version ( ) <EOL> if not DRY_RUN : <EOL> answer = query_yes_no ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % version , <EOL> default = "<STR_LIT>" ) <EOL> if answer != "<STR_LIT:yes>" : <EOL> self . log . info ( "<STR_LIT>" ) <EOL> return <EOL> print "<STR_LIT>" <EOL> self . log . info ( "<STR_LIT>" , version ) <EOL> changes_path = join ( self . dir , "<STR_LIT>" ) <EOL> changes_txt = changes_txt_before = codecs . open ( changes_path , '<STR_LIT:r>' , '<STR_LIT:utf-8>' ) . read ( ) <EOL> changes_sections = self . _changes_parser . findall ( changes_txt ) <EOL> top_ver = changes_sections [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> if top_ver != version : <EOL> raise MkError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( top_ver , version ) ) <EOL> top_nyr = changes_sections [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> if not top_nyr : <EOL> answer = query_yes_no ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> default = "<STR_LIT:yes>" ) <EOL> if answer != "<STR_LIT>" : <EOL> self . log . info ( "<STR_LIT>" ) <EOL> return <EOL> print "<STR_LIT>" <EOL> top_body = changes_sections [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> if top_body . strip ( ) == "<STR_LIT>" : <EOL> raise MkError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> changes_txt = changes_txt . replace ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> if not DRY_RUN and changes_txt != changes_txt_before : <EOL> self . log . info ( "<STR_LIT>" ) <EOL> f = codecs . open ( changes_path , '<STR_LIT:w>' , '<STR_LIT:utf-8>' ) <EOL> f . write ( changes_txt ) <EOL> f . close ( ) <EOL> sh . run ( '<STR_LIT>' <EOL> % ( changes_path , version ) , self . log . debug ) <EOL> curr_tags = set ( t for t in _capture_stdout ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) . split ( '<STR_LIT:\n>' ) if t ) <EOL> if not DRY_RUN and version not in curr_tags : <EOL> self . log . info ( "<STR_LIT>" ) <EOL> sh . run ( '<STR_LIT>' % ( version , version ) , <EOL> self . log . debug ) <EOL> sh . run ( '<STR_LIT>' , self . log . debug ) <EOL> self . log . info ( "<STR_LIT>" ) <EOL> if not DRY_RUN : <EOL> mk ( "<STR_LIT>" ) <EOL> next_version = self . _get_next_version ( version ) <EOL> self . log . info ( "<STR_LIT>" , next_version ) <EOL> marker = "<STR_LIT>" % ( self . proj_name , version ) <EOL> if marker not in changes_txt : <EOL> raise MkError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( marker , changes_path ) ) <EOL> changes_txt = changes_txt . replace ( "<STR_LIT>" % ( self . proj_name , version ) , <EOL> "<STR_LIT>" % ( <EOL> self . proj_name , next_version , self . proj_name , version ) ) <EOL> if not DRY_RUN : <EOL> f = codecs . open ( changes_path , '<STR_LIT:w>' , '<STR_LIT:utf-8>' ) <EOL> f . write ( changes_txt ) <EOL> f . close ( ) <EOL> ver_path = join ( self . dir , normpath ( self . version_py_path ) ) <EOL> ver_content = codecs . open ( ver_path , '<STR_LIT:r>' , '<STR_LIT:utf-8>' ) . read ( ) <EOL> version_tuple = self . _tuple_from_version ( version ) <EOL> next_version_tuple = self . _tuple_from_version ( next_version ) <EOL> marker = "<STR_LIT>" % ( version_tuple , ) <EOL> if marker not in ver_content : <EOL> raise MkError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( marker , ver_path ) ) <EOL> ver_content = ver_content . replace ( marker , <EOL> "<STR_LIT>" % ( next_version_tuple , ) ) <EOL> if not DRY_RUN : <EOL> f = codecs . open ( ver_path , '<STR_LIT:w>' , '<STR_LIT:utf-8>' ) <EOL> f . write ( ver_content ) <EOL> f . close ( ) <EOL> if not DRY_RUN : <EOL> sh . run ( '<STR_LIT>' % ( <EOL> changes_path , ver_path ) ) <EOL> sh . run ( '<STR_LIT>' ) <EOL> def _tuple_from_version ( self , version ) : <EOL> def _intify ( s ) : <EOL> try : <EOL> return int ( s ) <EOL> except ValueError : <EOL> return s <EOL> return tuple ( _intify ( b ) for b in version . split ( '<STR_LIT:.>' ) ) <EOL> def _get_next_version ( self , version ) : <EOL> last_bit = version . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] <EOL> try : <EOL> last_bit = int ( last_bit ) <EOL> except ValueError : <EOL> last_bit = int ( re . split ( '<STR_LIT>' , last_bit , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] ) <EOL> return version [ : - len ( str ( last_bit ) ) ] + str ( last_bit + <NUM_LIT:1> ) <EOL> def _get_version ( self ) : <EOL> lib_dir = join ( dirname ( abspath ( __file__ ) ) , "<STR_LIT>" ) <EOL> sys . path . insert ( <NUM_LIT:0> , lib_dir ) <EOL> try : <EOL> mod = __import__ ( self . version_module ) <EOL> return mod . __version__ <EOL> finally : <EOL> del sys . path [ <NUM_LIT:0> ] <EOL> class clean ( Task ) : <EOL> """<STR_LIT>""" <EOL> def make ( self ) : <EOL> patterns = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> for pattern in patterns : <EOL> p = join ( self . dir , pattern ) <EOL> for path in glob ( p ) : <EOL> sh . rm ( path , log = self . log ) <EOL> class sdist ( Task ) : <EOL> """<STR_LIT>""" <EOL> def make ( self ) : <EOL> sh . run_in_dir ( "<STR_LIT>" <EOL> % _setup_command_prefix ( ) , <EOL> self . dir , self . log . debug ) <EOL> class pypi_upload ( Task ) : <EOL> """<STR_LIT>""" <EOL> def make ( self ) : <EOL> sh . run_in_dir ( "<STR_LIT>" <EOL> % _setup_command_prefix ( ) , <EOL> self . dir , self . log . debug ) <EOL> sys . path . insert ( <NUM_LIT:0> , join ( self . dir , "<STR_LIT>" ) ) <EOL> url = "<STR_LIT>" <EOL> import webbrowser <EOL> webbrowser . open_new ( url ) <EOL> class todo ( Task ) : <EOL> """<STR_LIT>""" <EOL> def make ( self ) : <EOL> for path in _paths_from_path_patterns ( [ '<STR_LIT:.>' ] , <EOL> excludes = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) : <EOL> self . _dump_pattern_in_path ( "<STR_LIT>" , path ) <EOL> def _dump_pattern_in_path ( self , pattern , path ) : <EOL> os . system ( "<STR_LIT>" % ( pattern , path ) ) <EOL> def query_yes_no ( question , default = "<STR_LIT:yes>" ) : <EOL> """<STR_LIT>""" <EOL> valid = { "<STR_LIT:yes>" : "<STR_LIT:yes>" , "<STR_LIT:y>" : "<STR_LIT:yes>" , "<STR_LIT>" : "<STR_LIT:yes>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:n>" : "<STR_LIT>" } <EOL> if default == None : <EOL> prompt = "<STR_LIT>" <EOL> elif default == "<STR_LIT:yes>" : <EOL> prompt = "<STR_LIT>" <EOL> elif default == "<STR_LIT>" : <EOL> prompt = "<STR_LIT>" <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % default ) <EOL> while <NUM_LIT:1> : <EOL> sys . stdout . write ( question + prompt ) <EOL> choice = raw_input ( ) . lower ( ) <EOL> if default is not None and choice == '<STR_LIT>' : <EOL> return default <EOL> elif choice in valid . keys ( ) : <EOL> return valid [ choice ] <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> def _should_include_path ( path , includes , excludes ) : <EOL> """<STR_LIT>""" <EOL> from os . path import basename <EOL> from fnmatch import fnmatch <EOL> base = basename ( path ) <EOL> if includes : <EOL> for include in includes : <EOL> if fnmatch ( base , include ) : <EOL> try : <EOL> log . debug ( "<STR_LIT>" , path , include ) <EOL> except ( NameError , AttributeError ) : <EOL> pass <EOL> break <EOL> else : <EOL> try : <EOL> log . debug ( "<STR_LIT>" , path ) <EOL> except ( NameError , AttributeError ) : <EOL> pass <EOL> return False <EOL> for exclude in excludes : <EOL> if fnmatch ( base , exclude ) : <EOL> try : <EOL> log . debug ( "<STR_LIT>" , path , exclude ) <EOL> except ( NameError , AttributeError ) : <EOL> pass <EOL> return False <EOL> return True <EOL> def _walk ( top , topdown = True , onerror = None , follow_symlinks = False ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> from os . path import join , isdir , islink , abspath <EOL> try : <EOL> names = os . listdir ( top ) <EOL> except OSError , err : <EOL> if onerror is not None : <EOL> onerror ( err ) <EOL> return <EOL> dirs , nondirs = [ ] , [ ] <EOL> if follow_symlinks : <EOL> for name in names : <EOL> if isdir ( join ( top , name ) ) : <EOL> dirs . append ( name ) <EOL> else : <EOL> nondirs . append ( name ) <EOL> else : <EOL> for name in names : <EOL> path = join ( top , name ) <EOL> if islink ( path ) : <EOL> nondirs . append ( name ) <EOL> elif isdir ( path ) : <EOL> dirs . append ( name ) <EOL> else : <EOL> nondirs . append ( name ) <EOL> if topdown : <EOL> yield top , dirs , nondirs <EOL> for name in dirs : <EOL> path = join ( top , name ) <EOL> if follow_symlinks and islink ( path ) : <EOL> top_abs = abspath ( top ) <EOL> link_abs = abspath ( join ( top , os . readlink ( path ) ) ) <EOL> if not link_abs . startswith ( top_abs + os . sep ) : <EOL> continue <EOL> for x in _walk ( path , topdown , onerror , follow_symlinks = follow_symlinks ) : <EOL> yield x <EOL> if not topdown : <EOL> yield top , dirs , nondirs <EOL> _NOT_SPECIFIED = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def _paths_from_path_patterns ( path_patterns , files = True , dirs = "<STR_LIT>" , <EOL> recursive = True , includes = [ ] , excludes = [ ] , <EOL> skip_dupe_dirs = False , <EOL> follow_symlinks = False , <EOL> on_error = _NOT_SPECIFIED ) : <EOL> """<STR_LIT>""" <EOL> from os . path import basename , exists , isdir , join , normpath , abspath , lexists , islink , realpath <EOL> from glob import glob <EOL> assert not isinstance ( path_patterns , basestring ) , "<STR_LIT>" % path_patterns <EOL> GLOB_CHARS = '<STR_LIT>' <EOL> if skip_dupe_dirs : <EOL> searched_dirs = set ( ) <EOL> for path_pattern in path_patterns : <EOL> for glob_char in GLOB_CHARS : <EOL> if glob_char in path_pattern : <EOL> paths = glob ( path_pattern ) <EOL> break <EOL> else : <EOL> if follow_symlinks : <EOL> paths = exists ( path_pattern ) and [ path_pattern ] or [ ] <EOL> else : <EOL> paths = lexists ( path_pattern ) and [ path_pattern ] or [ ] <EOL> if not paths : <EOL> if on_error is None : <EOL> pass <EOL> elif on_error is _NOT_SPECIFIED : <EOL> try : <EOL> log . error ( "<STR_LIT>" , path_pattern ) <EOL> except ( NameError , AttributeError ) : <EOL> pass <EOL> else : <EOL> on_error ( path_pattern ) <EOL> for path in paths : <EOL> if ( follow_symlinks or not islink ( path ) ) and isdir ( path ) : <EOL> if skip_dupe_dirs : <EOL> canon_path = normpath ( abspath ( path ) ) <EOL> if follow_symlinks : <EOL> canon_path = realpath ( canon_path ) <EOL> if canon_path in searched_dirs : <EOL> continue <EOL> else : <EOL> searched_dirs . add ( canon_path ) <EOL> if ( dirs == "<STR_LIT>" <EOL> or ( dirs == "<STR_LIT>" and not recursive ) <EOL> ) and _should_include_path ( path , includes , excludes ) : <EOL> yield path <EOL> if recursive and _should_include_path ( path , [ ] , excludes ) : <EOL> for dirpath , dirnames , filenames in _walk ( path , <EOL> follow_symlinks = follow_symlinks ) : <EOL> dir_indeces_to_remove = [ ] <EOL> for i , dirname in enumerate ( dirnames ) : <EOL> d = join ( dirpath , dirname ) <EOL> if skip_dupe_dirs : <EOL> canon_d = normpath ( abspath ( d ) ) <EOL> if follow_symlinks : <EOL> canon_d = realpath ( canon_d ) <EOL> if canon_d in searched_dirs : <EOL> dir_indeces_to_remove . append ( i ) <EOL> continue <EOL> else : <EOL> searched_dirs . add ( canon_d ) <EOL> if dirs == "<STR_LIT>" and _should_include_path ( d , includes , excludes ) : <EOL> yield d <EOL> if not _should_include_path ( d , [ ] , excludes ) : <EOL> dir_indeces_to_remove . append ( i ) <EOL> for i in reversed ( dir_indeces_to_remove ) : <EOL> del dirnames [ i ] <EOL> if files : <EOL> for filename in sorted ( filenames ) : <EOL> f = join ( dirpath , filename ) <EOL> if _should_include_path ( f , includes , excludes ) : <EOL> yield f <EOL> elif files and _should_include_path ( path , includes , excludes ) : <EOL> yield path <EOL> _g_version = None <EOL> def _get_version ( ) : <EOL> global _g_version <EOL> if _g_version is None : <EOL> sys . path . insert ( <NUM_LIT:0> , join ( dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> try : <EOL> import cmdln <EOL> _g_version = cmdln . __version__ <EOL> finally : <EOL> del sys . path [ <NUM_LIT:0> ] <EOL> return _g_version <EOL> def _setup_command_prefix ( ) : <EOL> prefix = "<STR_LIT>" <EOL> if sys . platform == "<STR_LIT>" : <EOL> prefix = "<STR_LIT>" <EOL> return prefix <EOL> def _capture_stdout ( argv ) : <EOL> import subprocess <EOL> p = subprocess . Popen ( argv , stdout = subprocess . PIPE ) <EOL> return p . communicate ( ) [ <NUM_LIT:0> ] </s>
