<s> from __future__ import unicode_literals <EOL> import datetime <EOL> import os <EOL> import subprocess <EOL> from sellmo . utils . lru_cache import lru_cache <EOL> def get_version ( version = None ) : <EOL> "<STR_LIT>" <EOL> version = get_complete_version ( version ) <EOL> main = get_main_version ( version ) <EOL> sub = '<STR_LIT>' <EOL> if version [ <NUM_LIT:3> ] == '<STR_LIT>' and version [ <NUM_LIT:4> ] == <NUM_LIT:0> : <EOL> git_changeset = get_git_changeset ( ) <EOL> if git_changeset : <EOL> sub = '<STR_LIT>' % git_changeset <EOL> elif version [ <NUM_LIT:3> ] != '<STR_LIT>' : <EOL> mapping = { '<STR_LIT>' : '<STR_LIT:a>' , '<STR_LIT>' : '<STR_LIT:b>' , '<STR_LIT>' : '<STR_LIT:c>' } <EOL> sub = mapping [ version [ <NUM_LIT:3> ] ] + str ( version [ <NUM_LIT:4> ] ) <EOL> return str ( main + sub ) <EOL> def get_main_version ( version = None ) : <EOL> "<STR_LIT>" <EOL> version = get_complete_version ( version ) <EOL> parts = <NUM_LIT:2> if version [ <NUM_LIT:2> ] == <NUM_LIT:0> else <NUM_LIT:3> <EOL> return '<STR_LIT:.>' . join ( str ( x ) for x in version [ : parts ] ) <EOL> def get_complete_version ( version = None ) : <EOL> """<STR_LIT>""" <EOL> if version is None : <EOL> from sellmo import VERSION as version <EOL> else : <EOL> assert len ( version ) == <NUM_LIT:5> <EOL> assert version [ <NUM_LIT:3> ] in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> return version <EOL> def get_docs_version ( version = None ) : <EOL> version = get_complete_version ( version ) <EOL> if version [ <NUM_LIT:3> ] != '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' % version [ : <NUM_LIT:2> ] <EOL> @ lru_cache ( ) <EOL> def get_git_changeset ( ) : <EOL> """<STR_LIT>""" <EOL> repo_dir = os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) <EOL> git_log = subprocess . Popen ( <EOL> '<STR_LIT>' , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = True , <EOL> cwd = repo_dir , <EOL> universal_newlines = True <EOL> ) <EOL> timestamp = git_log . communicate ( ) [ <NUM_LIT:0> ] <EOL> try : <EOL> timestamp = datetime . datetime . utcfromtimestamp ( int ( timestamp ) ) <EOL> except ValueError : <EOL> return None <EOL> return timestamp . strftime ( '<STR_LIT>' ) </s>
