parameters: (self,
                tar,
                rootuid=None,
                rootgid=None,
                numeric=False,
                name_filter=None,
                root=None)
docstring: Merge a tar content into the current tar, stripping timestamp.
  
      Args:
        tar: the name of tar to extract and put content into the current tar.
        rootuid: user id that we will pretend is root (replaced by uid 0).
        rootgid: group id that we will pretend is root (replaced by gid 0).
        numeric: set to true to strip out name of owners (and just use the
            numeric values).
        name_filter: filter out file by names. If not none, this method will be
            called for each file to add, given the name and should return true if
            the file is to be added to the final tar and false otherwise.
        root: place all non-absolute content under given root direcory, if not
            None.
  
      Raises:
        TarFileWriter.Error: if an error happens when uncompressing the tar file.
docstring_summary: Merge a tar content into the current tar, stripping timestamp.
docstring_tokens: Merge a tar content into the current tar stripping timestamp .
function: def add_tar(self,
                tar,
                rootuid=None,
                rootgid=None,
                numeric=False,
                name_filter=None,
                root=None):
      """Merge a tar content into the current tar, stripping timestamp.
  
      Args:
        tar: the name of tar to extract and put content into the current tar.
        rootuid: user id that we will pretend is root (replaced by uid 0).
        rootgid: group id that we will pretend is root (replaced by gid 0).
        numeric: set to true to strip out name of owners (and just use the
            numeric values).
        name_filter: filter out file by names. If not none, this method will be
            called for each file to add, given the name and should return true if
            the file is to be added to the final tar and false otherwise.
        root: place all non-absolute content under given root direcory, if not
            None.
  
      Raises:
        TarFileWriter.Error: if an error happens when uncompressing the tar file.
      """
      if root and root[0] not in ['/', '.']:
        # Root prefix should start with a '/', adds it if missing
        root = '/' + root
      compression = os.path.splitext(tar)[-1][1:]
      if compression == 'tgz':
        compression = 'gz'
      elif compression == 'bzip2':
        compression = 'bz2'
      elif compression == 'lzma':
        compression = 'xz'
      elif compression not in ['gz', 'bz2', 'xz']:
        compression = ''
      if compression == 'xz':
        # Python 2 does not support lzma, our py3 support is terrible so let's
        # just hack around.
        # Note that we buffer the file in memory and it can have an important
        # memory footprint but it's probably fine as we don't use them for really
        # large files.
        # TODO(dmarting): once our py3 support gets better, compile this tools
        # with py3 for proper lzma support.
        if subprocess.call('which xzcat', shell=True, stdout=subprocess.PIPE):
          raise self.Error('Cannot handle .xz and .lzma compression: '
                           'xzcat not found.')
        p = subprocess.Popen('cat %s | xzcat' % tar,
                             shell=True,
                             stdout=subprocess.PIPE)
        f = StringIO(p.stdout.read())
        p.wait()
        intar = tarfile.open(fileobj=f, mode='r:')
      else:
        intar = tarfile.open(name=tar, mode='r:' + compression)
      for tarinfo in intar:
        if name_filter is None or name_filter(tarinfo.name):
          tarinfo.mtime = 0
          if rootuid is not None and tarinfo.uid == rootuid:
            tarinfo.uid = 0
            tarinfo.uname = 'root'
          if rootgid is not None and tarinfo.gid == rootgid:
            tarinfo.gid = 0
            tarinfo.gname = 'root'
          if numeric:
            tarinfo.uname = ''
            tarinfo.gname = ''
  
          name = tarinfo.name
          if not name.startswith('/') and not name.startswith('.'):
            name = './' + name
          if root is not None:
            if name.startswith('.'):
              name = '.' + root + name.lstrip('.')
              # Add root dir with same permissions if missing. Note that
              # add_file deduplicates directories and is safe to call here.
              self.add_file('.' + root,
                            tarfile.DIRTYPE,
                            uid=tarinfo.uid,
                            gid=tarinfo.gid,
                            uname=tarinfo.uname,
                            gname=tarinfo.gname,
                            mtime=tarinfo.mtime,
                            mode=0o755)
            # Relocate internal hardlinks as well to avoid breaking them.
            link = tarinfo.linkname
            if link.startswith('.') and tarinfo.type == tarfile.LNKTYPE:
              tarinfo.linkname = '.' + root + link.lstrip('.')
          tarinfo.name = name
  
          if tarinfo.isfile():
            self._addfile(tarinfo, intar.extractfile(tarinfo.name))
          else:
            self._addfile(tarinfo)
      intar.close()
function_tokens: def add_tar ( self , tar , rootuid = None , rootgid = None , numeric = False , name_filter = None , root = None ) : if root and root [ 0 ] not in [ '/' , '.' ] : # Root prefix should start with a '/', adds it if missing root = '/' + root compression = os . path . splitext ( tar ) [ - 1 ] [ 1 : ] if compression == 'tgz' : compression = 'gz' elif compression == 'bzip2' : compression = 'bz2' elif compression == 'lzma' : compression = 'xz' elif compression not in [ 'gz' , 'bz2' , 'xz' ] : compression = '' if compression == 'xz' : # Python 2 does not support lzma, our py3 support is terrible so let's # just hack around. # Note that we buffer the file in memory and it can have an important # memory footprint but it's probably fine as we don't use them for really # large files. # TODO(dmarting): once our py3 support gets better, compile this tools # with py3 for proper lzma support. if subprocess . call ( 'which xzcat' , shell = True , stdout = subprocess . PIPE ) : raise self . Error ( 'Cannot handle .xz and .lzma compression: ' 'xzcat not found.' ) p = subprocess . Popen ( 'cat %s | xzcat' % tar , shell = True , stdout = subprocess . PIPE ) f = StringIO ( p . stdout . read ( ) ) p . wait ( ) intar = tarfile . open ( fileobj = f , mode = 'r:' ) else : intar = tarfile . open ( name = tar , mode = 'r:' + compression ) for tarinfo in intar : if name_filter is None or name_filter ( tarinfo . name ) : tarinfo . mtime = 0 if rootuid is not None and tarinfo . uid == rootuid : tarinfo . uid = 0 tarinfo . uname = 'root' if rootgid is not None and tarinfo . gid == rootgid : tarinfo . gid = 0 tarinfo . gname = 'root' if numeric : tarinfo . uname = '' tarinfo . gname = '' name = tarinfo . name if not name . startswith ( '/' ) and not name . startswith ( '.' ) : name = './' + name if root is not None : if name . startswith ( '.' ) : name = '.' + root + name . lstrip ( '.' ) # Add root dir with same permissions if missing. Note that # add_file deduplicates directories and is safe to call here. self . add_file ( '.' + root , tarfile . DIRTYPE , uid = tarinfo . uid , gid = tarinfo . gid , uname = tarinfo . uname , gname = tarinfo . gname , mtime = tarinfo . mtime , mode = 0o755 ) # Relocate internal hardlinks as well to avoid breaking them. link = tarinfo . linkname if link . startswith ( '.' ) and tarinfo . type == tarfile . LNKTYPE : tarinfo . linkname = '.' + root + link . lstrip ( '.' ) tarinfo . name = name if tarinfo . isfile ( ) : self . _addfile ( tarinfo , intar . extractfile ( tarinfo . name ) ) else : self . _addfile ( tarinfo ) intar . close ( )