(self, name, arcname=None, recursive=True, *, filter=None)
Add the file `name' to the archive. `name' may be any type of file
           (directory, fifo, symbolic link, etc.). If given, `arcname'
           specifies an alternative name for the file in the archive.
           Directories are added recursively by default. This can be avoided by
           setting `recursive' to False. `filter' is a function
           that expects a TarInfo object argument and returns the changed
           TarInfo object, if it returns None the TarInfo object will be
           excluded from the archive.
Add the file `name' to the archive. `name' may be any type of file
           (directory, fifo, symbolic link, etc.). If given, `arcname'
           specifies an alternative name for the file in the archive.
           Directories are added recursively by default. This can be avoided by
           setting `recursive' to False. `filter' is a function
           that expects a TarInfo object argument and returns the changed
           TarInfo object, if it returns None the TarInfo object will be
           excluded from the archive.
Add the file name to the archive . name may be any type of file ( directory fifo symbolic link etc . ) . If given arcname specifies an alternative name for the file in the archive . Directories are added recursively by default . This can be avoided by setting recursive to False . filter is a function that expects a TarInfo object argument and returns the changed TarInfo object if it returns None the TarInfo object will be excluded from the archive .
def add(self, name, arcname=None, recursive=True, *, filter=None):
        """Add the file `name' to the archive. `name' may be any type of file
           (directory, fifo, symbolic link, etc.). If given, `arcname'
           specifies an alternative name for the file in the archive.
           Directories are added recursively by default. This can be avoided by
           setting `recursive' to False. `filter' is a function
           that expects a TarInfo object argument and returns the changed
           TarInfo object, if it returns None the TarInfo object will be
           excluded from the archive.
        """
        self._check("awx")

        if arcname is None:
            arcname = name

        # Skip if somebody tries to archive the archive...
        if self.name is not None and os.path.abspath(name) == self.name:
            self._dbg(2, "tarfile: Skipped %r" % name)
            return

        self._dbg(1, name)

        # Create a TarInfo object from the file.
        tarinfo = self.gettarinfo(name, arcname)

        if tarinfo is None:
            self._dbg(1, "tarfile: Unsupported type %r" % name)
            return

        # Change or exclude the TarInfo object.
        if filter is not None:
            tarinfo = filter(tarinfo)
            if tarinfo is None:
                self._dbg(2, "tarfile: Excluded %r" % name)
                return

        # Append the tar header and data to the archive.
        if tarinfo.isreg():
            with bltn_open(name, "rb") as f:
                self.addfile(tarinfo, f)

        elif tarinfo.isdir():
            self.addfile(tarinfo)
            if recursive:
                for f in sorted(os.listdir(name)):
                    self.add(os.path.join(name, f), os.path.join(arcname, f),
                            recursive, filter=filter)

        else:
            self.addfile(tarinfo)
def add ( self , name , arcname = None , recursive = True , * , filter = None ) : self . _check ( "awx" ) if arcname is None : arcname = name # Skip if somebody tries to archive the archive... if self . name is not None and os . path . abspath ( name ) == self . name : self . _dbg ( 2 , "tarfile: Skipped %r" % name ) return self . _dbg ( 1 , name ) # Create a TarInfo object from the file. tarinfo = self . gettarinfo ( name , arcname ) if tarinfo is None : self . _dbg ( 1 , "tarfile: Unsupported type %r" % name ) return # Change or exclude the TarInfo object. if filter is not None : tarinfo = filter ( tarinfo ) if tarinfo is None : self . _dbg ( 2 , "tarfile: Excluded %r" % name ) return # Append the tar header and data to the archive. if tarinfo . isreg ( ) : with bltn_open ( name , "rb" ) as f : self . addfile ( tarinfo , f ) elif tarinfo . isdir ( ) : self . addfile ( tarinfo ) if recursive : for f in sorted ( os . listdir ( name ) ) : self . add ( os . path . join ( name , f ) , os . path . join ( arcname , f ) , recursive , filter = filter ) else : self . addfile ( tarinfo )