#NEWLINE# def checkout( args , filename ) : #NEWLINE# #INDENT# 'Check out snapshot from a json file, as specified by arguments in args.\n\n    Return 0 on success, 1 on failure.' #NEWLINE# LOGGER . debug ( 'In subcommand checkout.' ) #NEWLINE# os . chdir ( args . project ) #NEWLINE# projectpath = os . getcwd ( ) #NEWLINE# non_git_repos = [ ] #NEWLINE# try : #NEWLINE# #INDENT# with open ( filename , 'r' ) as metafile : #NEWLINE# #INDENT# json_object = json . load ( metafile ) #NEWLINE# LOGGER . info ( ( 'Loaded json data from ' + filename ) ) #NEWLINE# LOGGER . debug ( json_object ) #NEWLINE# #UNINDENT# #UNINDENT# except IOError as exc : #NEWLINE# #INDENT# LOGGER . error ( ( 'Could not open file: ' + str ( exc ) ) ) #NEWLINE# return 1 #NEWLINE# #UNINDENT# entry = check_for_snapshot_entry ( args . name , json_object ) #NEWLINE# if ( not entry ) : #NEWLINE# #INDENT# LOGGER . error ( ( ( 'Snapshot entry ' + args . name ) + ' does not exist.' ) ) #NEWLINE# return 1 #NEWLINE# #UNINDENT# LOGGER . info ( 'Making sure repos are clean: OF' ) #NEWLINE# os . chdir ( entry [ 'core' ] [ 'path' ] ) #NEWLINE# if ( validate_git_repo ( ) != 0 ) : #NEWLINE# #INDENT# LOGGER . error ( 'OF git repo could not be validated successfully.' ) #NEWLINE# return 1 #NEWLINE# #UNINDENT# LOGGER . info ( 'Making sure repos are clean: addons' ) #NEWLINE# addons_path = os . path . join ( os . getcwd ( ) , 'addons' ) #NEWLINE# os . chdir ( addons_path ) #NEWLINE# for addon in entry [ 'addons' ] : #NEWLINE# #INDENT# LOGGER . info ( ( 'Processing addon ' + addon [ 'name' ] ) ) #NEWLINE# if ( addon [ 'sha' ] == 'non-git' ) : #NEWLINE# #INDENT# LOGGER . info ( ( 'Skipping non-git addon ' + addon [ 'name' ] ) ) #NEWLINE# non_git_repos . append ( addon [ 'name' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# os . chdir ( addon [ 'name' ] ) #NEWLINE# if ( validate_git_repo ( ) != 0 ) : #NEWLINE# #INDENT# LOGGER . error ( ( addon [ 'name' ] + ' git repo could not be validated successfully.' ) ) #NEWLINE# return 1 #NEWLINE# #UNINDENT# os . chdir ( addons_path ) #NEWLINE# #UNINDENT# #UNINDENT# LOGGER . info ( 'Checking out openFrameworks' ) #NEWLINE# LOGGER . info ( ( ( ( 'Checking out ' + entry [ 'core' ] [ 'sha' ] ) + ' of ' ) + entry [ 'core' ] [ 'path' ] ) ) #NEWLINE# os . chdir ( projectpath ) #NEWLINE# os . chdir ( entry [ 'core' ] [ 'path' ] ) #NEWLINE# refname = get_branchname ( entry [ 'core' ] [ 'sha' ] ) #NEWLINE# if ( subprocess . call ( [ 'git' , 'checkout' , refname ] ) != 0 ) : #NEWLINE# #INDENT# LOGGER . error ( ( 'An error occured checking out ' + entry [ 'core' ] [ 'path' ] ) ) #NEWLINE# return 1 #NEWLINE# #UNINDENT# LOGGER . info ( 'Checking out addons' ) #NEWLINE# os . chdir ( addons_path ) #NEWLINE# for addon in entry [ 'addons' ] : #NEWLINE# #INDENT# if ( addon [ 'sha' ] == 'non-git' ) : #NEWLINE# #INDENT# LOGGER . info ( ( 'Skipping non-git addon ' + addon [ 'name' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# LOGGER . info ( ( ( ( 'Checking out ' + addon [ 'sha' ] ) + ' of ' ) + addon [ 'name' ] ) ) #NEWLINE# os . chdir ( addon [ 'name' ] ) #NEWLINE# refname = get_branchname ( addon [ 'sha' ] ) #NEWLINE# if ( subprocess . call ( [ 'git' , 'checkout' , refname ] ) != 0 ) : #NEWLINE# #INDENT# LOGGER . error ( ( 'An error occured checking out ' + addon [ 'name' ] ) ) #NEWLINE# return 1 #NEWLINE# #UNINDENT# os . chdir ( addons_path ) #NEWLINE# #UNINDENT# #UNINDENT# LOGGER . info ( ( 'Finished checking out snapshot ' + non_git_repos [ 'name' ] ) ) #NEWLINE# if non_git_repos : #NEWLINE# #INDENT# LOGGER . warning ( ( 'The following addons not under git control were ' + 'found. Correct code state cannot be guaranteed!' ) ) #NEWLINE# for item in non_git_repos : #NEWLINE# #INDENT# LOGGER . warning ( str ( item ) ) #NEWLINE# #UNINDENT# #UNINDENT# return 0