def put(self, destination):
        """ Copy the referenced directory to this path

        Note:
            This ignores anything not in the desired directory, given by ``self.dirname``.

        Args:
            destination (str): path to put this directory (which must NOT already exist)

        References:
            https://stackoverflow.com/a/8261083/1958900
        """
        target = get_target_path(destination, self.dirname)
        valid_paths = (self.dirname, './%s' % self.dirname)

        with tarfile.open(self.archive_path, 'r:*') as tf:
            members = []
            for tarinfo in tf:
                # Get only files under the directory `self.dirname`
                pathsplit = os.path.normpath(tarinfo.path).split(os.sep)
                if pathsplit[0] not in valid_paths:
                    print('WARNING: skipped file "%s" in archive; not in directory "%s"' %
                          (tarinfo.path, self.dirname))
                    continue
                if len(pathsplit) == 1:
                    continue
                tarinfo.name = os.path.join(*pathsplit[1:])
                members.append(tarinfo)

            if not members:
                raise ValueError("No files under path directory '%s' in this tarfile")

            tf.extractall(target, members)
def put ( self , destination ) : target = get_target_path ( destination , self . dirname ) valid_paths = ( self . dirname , './%s' % self . dirname ) with tarfile . open ( self . archive_path , 'r:*' ) as tf : members = [ ] for tarinfo in tf : pathsplit = os . path . normpath ( tarinfo . path ) . split ( os . sep ) if pathsplit [ 0 ] not in valid_paths : print ( 'WARNING: skipped file "%s" in archive; not in directory "%s"' % ( tarinfo . path , self . dirname ) ) continue if len ( pathsplit ) == 1 : continue tarinfo . name = os . path . join ( * pathsplit [ 1 : ] ) members . append ( tarinfo ) if not members : raise ValueError ( "No files under path directory '%s' in this tarfile" ) tf . extractall ( target , members )
Copy the referenced directory to this path

        Note:
            This ignores anything not in the desired directory, given by ``self.dirname``.

        Args:
            destination (str): path to put this directory (which must NOT already exist)

        References:
            https://stackoverflow.com/a/8261083/1958900