<s> __all__ = ( "<STR_LIT>" ) <EOL> import os <EOL> import sys <EOL> import traceback <EOL> from subprocess import Popen , PIPE <EOL> def call_git_describe ( abbrev = <NUM_LIT:4> ) : <EOL> dot_git = os . path . join ( <EOL> os . path . dirname ( os . path . abspath ( __file__ ) ) , <EOL> '<STR_LIT>' ) <EOL> if not os . path . exists ( dot_git ) : <EOL> return None , None <EOL> line = None <EOL> p = None <EOL> try : <EOL> p = Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % abbrev ] , <EOL> stdout = PIPE , stderr = PIPE , <EOL> cwd = os . path . dirname ( os . path . abspath ( __file__ ) ) ) <EOL> p . stderr . close ( ) <EOL> describe_line = p . stdout . readlines ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> p = Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> stdout = PIPE , stderr = PIPE ) <EOL> p . stderr . close ( ) <EOL> source_hash = p . stdout . readlines ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> source_hash = source_hash [ : abbrev ] <EOL> parts = describe_line . split ( '<STR_LIT:->' ) <EOL> if len ( parts ) == <NUM_LIT:1> : <EOL> version = parts [ <NUM_LIT:0> ] <EOL> else : <EOL> ver , rel , source_hash = parts <EOL> version_parts = ver . split ( '<STR_LIT:.>' ) <EOL> lasti = len ( version_parts ) - <NUM_LIT:1> <EOL> version_parts [ lasti ] = str ( int ( version_parts [ lasti ] ) + <NUM_LIT:1> ) <EOL> version = '<STR_LIT>' . format ( '<STR_LIT:.>' . join ( version_parts ) , rel ) <EOL> return version , source_hash <EOL> except Exception , exc : <EOL> sys . stderr . write ( '<STR_LIT>' % line ) <EOL> sys . stderr . write ( traceback . format_exc ( exc ) ) <EOL> try : <EOL> sys . stderr . write ( '<STR_LIT>' % p . stderr . read ( ) ) <EOL> except Exception , exc : <EOL> sys . stderr . write ( traceback . format_exc ( exc ) ) <EOL> try : <EOL> sys . stderr . write ( '<STR_LIT>' % os . getcwd ( ) ) <EOL> except Exception , exc : <EOL> sys . stderr . write ( traceback . format_exc ( exc ) ) <EOL> return None , None <EOL> def read_release_version ( ) : <EOL> try : <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:r>" ) <EOL> try : <EOL> version = f . readlines ( ) [ <NUM_LIT:0> ] <EOL> return version . strip ( ) . split ( '<STR_LIT:U+002C>' ) <EOL> finally : <EOL> f . close ( ) <EOL> except : <EOL> return None , None <EOL> def write_release_version ( version , source_hash ) : <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> f . write ( "<STR_LIT>" % ( version , source_hash ) ) <EOL> f . close ( ) <EOL> def get_git_version ( abbrev = <NUM_LIT:4> ) : <EOL> release_version , release_source_hash = read_release_version ( ) <EOL> version , source_hash = call_git_describe ( abbrev ) <EOL> if version is None : <EOL> version = release_version <EOL> source_hash = release_source_hash <EOL> if version is None : <EOL> version = '<STR_LIT>' <EOL> source_hash = '<STR_LIT>' <EOL> if version != release_version or source_hash != release_source_hash : <EOL> write_release_version ( version , source_hash ) <EOL> return version , source_hash <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> print get_git_version ( ) </s>
