#NEWLINE# def fetch_repository( repository , workdir = None , branch = None , cache_config_dir = None , cache_config_file_name = 'cached_repositories.ini' , reference_repository = None ) : #NEWLINE# #INDENT# "\n    Fetch repository inside a workdir. Return filesystem path of newly created dir.\n    if cache_config_dir is False, no attempt to use caching is used. If None, curdir is used, if string, it's taken as path to directory.\n        If given directory is not writeable, warning is logged and fetch proceeds as if cache_config_dir would be False\n    " #NEWLINE# write_repository_cache = False #NEWLINE# if ( cache_config_dir is not False ) : #NEWLINE# #INDENT# if ( not cache_config_dir ) : #NEWLINE# #INDENT# cache_config_dir = os . curdir #NEWLINE# #UNINDENT# if ( ( not os . path . isdir ( cache_config_dir ) ) or ( not os . access ( cache_config_dir , os . W_OK ) ) ) : #NEWLINE# #INDENT# cache_config_dir = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cache_file_path = os . path . join ( cache_config_dir , cache_config_file_name ) #NEWLINE# parser = SafeConfigParser ( ) #NEWLINE# write_repository_cache = True #NEWLINE# if os . path . exists ( cache_file_path ) : #NEWLINE# #INDENT# parser . read ( [ cache_file_path ] ) #NEWLINE# if ( parser . has_section ( repository ) and parser . has_option ( repository , 'cache_dir' ) ) : #NEWLINE# #INDENT# cached_repo = parser . get ( repository , 'cache_dir' ) #NEWLINE# if os . path . exists ( cached_repo ) : #NEWLINE# #INDENT# return cached_repo #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# dir = os . path . abspath ( os . path . join ( mkdtemp ( dir = workdir ) , 'repository' ) ) #NEWLINE# clone = [ 'git' , 'clone' , repository , dir ] #NEWLINE# if ( reference_repository and os . path . exists ( reference_repository ) ) : #NEWLINE# #INDENT# clone . extend ( [ '--reference' , reference_repository ] ) #NEWLINE# #UNINDENT# check_call ( clone , stdout = PIPE , stdin = PIPE , stderr = PIPE ) #NEWLINE# if ( branch and ( branch != 'master' ) ) : #NEWLINE# #INDENT# check_call ( [ 'git' , 'checkout' , '-b' , branch , ( 'origin/%s' % branch ) ] , cwd = dir , stdout = PIPE , stdin = PIPE , stderr = PIPE ) #NEWLINE# #UNINDENT# if write_repository_cache : #NEWLINE# #INDENT# if ( not parser . has_section ( repository ) ) : #NEWLINE# #INDENT# parser . add_section ( repository ) #NEWLINE# #UNINDENT# parser . set ( repository , 'cache_dir' , dir ) #NEWLINE# f = open ( cache_file_path , 'w' ) #NEWLINE# parser . write ( f ) #NEWLINE# f . close ( ) #NEWLINE# #UNINDENT# return dir