original_docstring: Archive a snapshot from a json file, as specified by arguments in args.
  
      Return 0 on success, 1 on failure.
docstring: Archive a snapshot from a json file, as specified by arguments in args.
  Return 0 on success, 1 on failure.
docstring_tokens: Archive a snapshot from a json file as specified by arguments in args . Return 0 on success 1 on failure .
code: def archive(args, filename):
      """Archive a snapshot from a json file, as specified by arguments in args.
  
      Return 0 on success, 1 on failure."""
      LOGGER.debug('In subcommand archive.')
      basedir = os.getcwd()
      os.chdir(args.project)
      projectpath = os.getcwd()
  
      LOGGER.debug('Opening metadata file')
      try:
          with open(filename, 'r') as metafile:
              json_object = json.load(metafile)
              LOGGER.info('loaded data from ' + filename)
              LOGGER.debug(json_object)
              # update with data
      except IOError as exc:
          if exc.errno == errno.ENOENT:
              LOGGER.info('Metadata file ' + filename +
                          ' does not exist yet. Creating...')
              return create_entry_then_archive(args, basedir, filename)
          else:  # pragma: no cover
              raise
  
      # check if snapshot entry already exists, if not create it
      entry = check_for_snapshot_entry(args.name, json_object)
      if not entry:
          LOGGER.info('Entry ' + args.name + ' does not exist yet. Creating...')
          return create_entry_then_archive(args, basedir, filename)
      #--------------------------------------------------------------------------
      else:
          # entry exists, start archiving
          # create subdirectory for archive
          basename = str(os.path.basename(projectpath))
          archivedirectory = basename + '_archive'
          try:
              os.mkdir(archivedirectory)
          except OSError as exc:
              if exc.errno == errno.EEXIST:
                  LOGGER.debug('Directory ' + archivedirectory +
                               ' already exists. Continuing.')
              else:  # pragma: no cover
                  LOGGER.error('Could not create directory: ' +
                               archivedirectory + ': ' + str(exc))
                  raise
          os.chdir(archivedirectory)
  
          # archive all elements
          # Description file
          if entry['description'] != '':
              LOGGER.info('Writing description file')
              with open(basename + '_' + entry['name'] +
                        '_description.txt', 'w') as descriptionfile:
                  descriptionfile.write(entry['description'])
  
          # OF itself
          archivename = (basename + '_' + entry['name'] +
                         '_OF_' + entry['core']['sha'][0:7] + '.tar.gz')
          repopath = os.path.abspath(os.path.join(projectpath,
                                                  entry['core']['path']))
          git_archive_repo(archivename, os.getcwd(),
                           repopath, entry['core']['sha'])
  
          # addons
          for addon in entry['addons']:
              LOGGER.info('Archiving addon ' + addon['name'])
              archivename = (basename + '_' + entry['name'] + '_' +
                             os.path.basename(addon['name']) + '_' +
                             addon['sha'][0:7] + '.tar.gz')
              repopath = os.path.abspath(os.path.join(projectpath,
                                                      entry['core']['path'],
                                                      'addons',
                                                      addon['name']))
              if addon['sha'] != 'non-git':
                  git_archive_repo(archivename, os.getcwd(),
                                   repopath, addon['sha'])
              else:
                  LOGGER.info(addon['name'] +
                              ' is not a git repo. Packing as tar.gz file.')
                  subprocess.call(['tar', '-zcf', archivename,
                                   '--directory=' + os.path.dirname(repopath),
                                   os.path.basename(repopath)])
  
          return 0
code_tokens: def archive ( args , filename ) : LOGGER . debug ( 'In subcommand archive.' ) basedir = os . getcwd ( ) os . chdir ( args . project ) projectpath = os . getcwd ( ) LOGGER . debug ( 'Opening 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 ( 'Metadata file ' + filename + ' does not exist yet. Creating...' ) return create_entry_then_archive ( args , basedir , filename ) else : raise entry = check_for_snapshot_entry ( args . name , json_object ) if not entry : LOGGER . info ( 'Entry ' + args . name + ' does not exist yet. Creating...' ) return create_entry_then_archive ( args , basedir , filename ) else : basename = str ( os . path . basename ( projectpath ) ) archivedirectory = basename + '_archive' try : os . mkdir ( archivedirectory ) except OSError as exc : if exc . errno == errno . EEXIST : LOGGER . debug ( 'Directory ' + archivedirectory + ' already exists. Continuing.' ) else : LOGGER . error ( 'Could not create directory: ' + archivedirectory + ': ' + str ( exc ) ) raise os . chdir ( archivedirectory ) if entry [ 'description' ] != '' : LOGGER . info ( 'Writing description file' ) with open ( basename + '_' + entry [ 'name' ] + '_description.txt' , 'w' ) as descriptionfile : descriptionfile . write ( entry [ 'description' ] ) archivename = ( basename + '_' + entry [ 'name' ] + '_OF_' + entry [ 'core' ] [ 'sha' ] [ 0 : 7 ] + '.tar.gz' ) repopath = os . path . abspath ( os . path . join ( projectpath , entry [ 'core' ] [ 'path' ] ) ) git_archive_repo ( archivename , os . getcwd ( ) , repopath , entry [ 'core' ] [ 'sha' ] ) for addon in entry [ 'addons' ] : LOGGER . info ( 'Archiving addon ' + addon [ 'name' ] ) archivename = ( basename + '_' + entry [ 'name' ] + '_' + os . path . basename ( addon [ 'name' ] ) + '_' + addon [ 'sha' ] [ 0 : 7 ] + '.tar.gz' ) repopath = os . path . abspath ( os . path . join ( projectpath , entry [ 'core' ] [ 'path' ] , 'addons' , addon [ 'name' ] ) ) if addon [ 'sha' ] != 'non-git' : git_archive_repo ( archivename , os . getcwd ( ) , repopath , addon [ 'sha' ] ) else : LOGGER . info ( addon [ 'name' ] + ' is not a git repo. Packing as tar.gz file.' ) subprocess . call ( [ 'tar' , '-zcf' , archivename , '--directory=' + os . path . dirname ( repopath ) , os . path . basename ( repopath ) ] ) return 0
short_docstring: Archive a snapshot from a json file, as specified by arguments in args.
short_docstring_tokens: Archive a snapshot from a json file as specified by arguments in args .
comment: """Archive a snapshot from a json file, as specified by arguments in args.
  
      Return 0 on success, 1 on failure."""$SEP$# update with data$SEP$# pragma: no cover$SEP$# check if snapshot entry already exists, if not create it$SEP$#--------------------------------------------------------------------------$SEP$# entry exists, start archiving$SEP$# create subdirectory for archive$SEP$# pragma: no cover$SEP$# archive all elements$SEP$# Description file$SEP$# OF itself$SEP$# addons