original_docstring: Record a snapshot in a json file, as specified by arguments in args.
  
      Return 0 on success, 1 on failure.
docstring: Record a snapshot in a json file, as specified by arguments in args.
  Return 0 on success, 1 on failure.
docstring_tokens: Record a snapshot in a json file as specified by arguments in args . Return 0 on success 1 on failure .
code: def record(args, filename):
      """Record a snapshot in a json file, as specified by arguments in args.
  
      Return 0 on success, 1 on failure."""
  
      LOGGER.debug('In subcommand record.')
      os.chdir(args.project)
      projectpath = os.getcwd()
  
      # parse addons.make into a list of addons
      addons_list = []
      try:
          with open('addons.make', 'r') as addons_make:
              for line in addons_make.readlines():
                  addons_list.append(line.rstrip())
      except IOError as exc:
          if exc.errno == errno.ENOENT:
              LOGGER.debug('No addons.make file found.')
          else:  # pragma: no cover
              raise
      if len(addons_list) is 0:
          LOGGER.info('No addons found.')
  
      # search config.make for OF location
      with open('config.make', 'r') as config_make:
          of_path = ''
          for line in config_make.readlines():
              if 'OF_ROOT =' in line:
                  of_path = line.split('=', 1)[-1].strip()
                  break
          if len(of_path) == 0:
              LOGGER.error('Did not find OF location in config.make in ' +
                           os.getcwd())
              return 1
  
      LOGGER.info('Processing OF at ' + of_path)
      os.chdir(of_path)
      core_dict = {'path': of_path}
      if validate_git_repo() != 0:
          LOGGER.error('OF git repo could not be validated successfully.')
          return 1
  
      LOGGER.debug('Recording commit SHA')
      out = subprocess.check_output(['git', 'rev-parse', 'HEAD'],
                                    universal_newlines=True)
      core_dict['sha'] = out.strip()
      LOGGER.debug('OF commit SHA: ' + core_dict['sha'])
  
      LOGGER.info('Processing addons')
      addons_path = os.path.join(os.getcwd(), 'addons')
      os.chdir(addons_path)
      # get list of official addons
      official_addons = []
      with open('.gitignore', 'r') as gitignore_file:
          for line in gitignore_file:
              if line.startswith('!ofx'):
                  official_addons.append(line[1:].strip())
      # prune official addons (which are in the OF repo already)
      # not very efficient (better with sets),
      # but irrelevant for the small lists we expect
      addons_list = [{'name': x}
                     for x
                     in addons_list
                     if x
                     not in official_addons]
  
      for addon in addons_list:
          LOGGER.info('Processing addon ' + addon['name'])
          try:
              os.chdir(os.path.join(addons_path, addon['name']))
          except Exception as exc:
              if exc.errno == errno.ENOENT:
                  LOGGER.error(addon['name'] + ' does not exist at ' +
                               addons_path + '.')
                  sys.exit('Aborting')
              else:  # pragma: no cover
                  raise
  
          ret = validate_git_repo(strict=False)
          if ret == 0:
              out_string = subprocess.check_output(['git', 'rev-parse', 'HEAD'],
                                                   universal_newlines=True)
              addon['sha'] = out_string.strip()
          elif ret == 2:
              addon['sha'] = 'non-git'
          else:
              LOGGER.error(addon['name'] +
                           ' git repo could not be validated successfully.')
              return 1
  
      LOGGER.info('Storing metadata')
      os.chdir(projectpath)
  
      # Open/initialise metadata file
      try:
          with open(filename, 'r') as metafile:
              json_object = json.load(metafile)
              LOGGER.info('loaded data from ' + filename)
              LOGGER.debug(json_object)
      except IOError as exc:
          if exc.errno == errno.ENOENT:
              LOGGER.info(filename + ' does not exist yet. Creating..')
              open(filename, 'w').close()
              # create new skeleton json_object
              json_object = json.loads('{ "snapshots": [] }')
          else:  # pragma: no cover
              raise
  
      # Store/update metadata
      # check if snapshot entry already exists
      for entry in json_object['snapshots']:
          if entry['name'] == args.name:
              if (args.update is False) and (args.name is not 'latest'):
                  LOGGER.error(args.name +
                               ': entry with the same name already exists. ' +
                               'Use -u option to overwrite.')
                  return 1
              json_object['snapshots'].remove(entry)
  
      # write updated entry
      temp = {'name': args.name,
              'date': datetime.now().isoformat(),
              'description': args.description,
              'core': core_dict,
              'addons': addons_list}
      json_object['snapshots'].append(temp)
  
      LOGGER.info('Writing updated data to ' + filename)
      with open(filename, 'w') as metafile:
          json.dump(json_object, metafile, indent=1, sort_keys=True)
  
      return 0
code_tokens: def record ( args , filename ) : LOGGER . debug ( 'In subcommand record.' ) os . chdir ( args . project ) projectpath = os . getcwd ( ) addons_list = [ ] try : with open ( 'addons.make' , 'r' ) as addons_make : for line in addons_make . readlines ( ) : addons_list . append ( line . rstrip ( ) ) except IOError as exc : if exc . errno == errno . ENOENT : LOGGER . debug ( 'No addons.make file found.' ) else : raise if len ( addons_list ) is 0 : LOGGER . info ( 'No addons found.' ) with open ( 'config.make' , 'r' ) as config_make : of_path = '' for line in config_make . readlines ( ) : if 'OF_ROOT =' in line : of_path = line . split ( '=' , 1 ) [ - 1 ] . strip ( ) break if len ( of_path ) == 0 : LOGGER . error ( 'Did not find OF location in config.make in ' + os . getcwd ( ) ) return 1 LOGGER . info ( 'Processing OF at ' + of_path ) os . chdir ( of_path ) core_dict = { 'path' : of_path } if validate_git_repo ( ) != 0 : LOGGER . error ( 'OF git repo could not be validated successfully.' ) return 1 LOGGER . debug ( 'Recording commit SHA' ) out = subprocess . check_output ( [ 'git' , 'rev-parse' , 'HEAD' ] , universal_newlines = True ) core_dict [ 'sha' ] = out . strip ( ) LOGGER . debug ( 'OF commit SHA: ' + core_dict [ 'sha' ] ) LOGGER . info ( 'Processing addons' ) addons_path = os . path . join ( os . getcwd ( ) , 'addons' ) os . chdir ( addons_path ) official_addons = [ ] with open ( '.gitignore' , 'r' ) as gitignore_file : for line in gitignore_file : if line . startswith ( '!ofx' ) : official_addons . append ( line [ 1 : ] . strip ( ) ) addons_list = [ { 'name' : x } for x in addons_list if x not in official_addons ] for addon in addons_list : LOGGER . info ( 'Processing addon ' + addon [ 'name' ] ) try : os . chdir ( os . path . join ( addons_path , addon [ 'name' ] ) ) except Exception as exc : if exc . errno == errno . ENOENT : LOGGER . error ( addon [ 'name' ] + ' does not exist at ' + addons_path + '.' ) sys . exit ( 'Aborting' ) else : raise ret = validate_git_repo ( strict = False ) if ret == 0 : out_string = subprocess . check_output ( [ 'git' , 'rev-parse' , 'HEAD' ] , universal_newlines = True ) addon [ 'sha' ] = out_string . strip ( ) elif ret == 2 : addon [ 'sha' ] = 'non-git' else : LOGGER . error ( addon [ 'name' ] + ' git repo could not be validated successfully.' ) return 1 LOGGER . info ( 'Storing metadata' ) os . chdir ( projectpath ) try : with open ( filename , 'r' ) as metafile : json_object = json . load ( metafile ) LOGGER . info ( 'loaded data from ' + filename ) LOGGER . debug ( json_object ) except IOError as exc : if exc . errno == errno . ENOENT : LOGGER . info ( filename + ' does not exist yet. Creating..' ) open ( filename , 'w' ) . close ( ) json_object = json . loads ( '{ "snapshots": [] }' ) else : raise for entry in json_object [ 'snapshots' ] : if entry [ 'name' ] == args . name : if ( args . update is False ) and ( args . name is not 'latest' ) : LOGGER . error ( args . name + ': entry with the same name already exists. ' + 'Use -u option to overwrite.' ) return 1 json_object [ 'snapshots' ] . remove ( entry ) temp = { 'name' : args . name , 'date' : datetime . now ( ) . isoformat ( ) , 'description' : args . description , 'core' : core_dict , 'addons' : addons_list } json_object [ 'snapshots' ] . append ( temp ) LOGGER . info ( 'Writing updated data to ' + filename ) with open ( filename , 'w' ) as metafile : json . dump ( json_object , metafile , indent = 1 , sort_keys = True ) return 0
short_docstring: Record a snapshot in a json file, as specified by arguments in args.
short_docstring_tokens: Record a snapshot in a json file as specified by arguments in args .
comment: """Record a snapshot in a json file, as specified by arguments in args.
  
      Return 0 on success, 1 on failure."""$SEP$# parse addons.make into a list of addons$SEP$# pragma: no cover$SEP$# search config.make for OF location$SEP$# get list of official addons$SEP$# prune official addons (which are in the OF repo already)$SEP$# not very efficient (better with sets),$SEP$# but irrelevant for the small lists we expect$SEP$# pragma: no cover$SEP$# Open/initialise metadata file$SEP$# create new skeleton json_object$SEP$# pragma: no cover$SEP$# Store/update metadata$SEP$# check if snapshot entry already exists$SEP$# write updated entry