Exemplo n.º 1
0
    def test_tarSupport(self):
        files_created = 0
        while not (files_created == self.number_of_files):
            path = create_temp_file(file_dir=self.working_dir)
            md5sum = extract_md5(path)
            self.files.append({"path": path, "md5sum" : md5sum})
            files_created += 1

        archive_file = self.create_archive()
        self.extract_archive(archive_file)
        files = os.listdir(self.extract_dir)
        msg = "The number of files in the extract directory does not equal the number of files add to the archive."
        self.assertTrue(len(files) == len(self.files), msg)

        extract_files = []
        for f in files:
            md5sum = extract_md5("%s/%s" % (self.extract_dir, f))
            extract_files.append({"path": "%s/%s" % (self.extract_dir, f), "md5sum" : md5sum})

        for file_dict in self.files:
            for extract_dict in extract_files:
                if (os.path.basename(file_dict["path"]) == os.path.basename(extract_dict["path"])) and \
                   (file_dict["md5sum"] == extract_dict["md5sum"]):
                    extract_files.remove(extract_dict)
                    break
        self.assertTrue(len(extract_files) == 0, "At least one original file's md5sum did not match the extracted file's md5sum")
Exemplo n.º 2
0
 def setUp(self):
     self.extract_dir = tempfile.mkdtemp()
     self.working_dir = tempfile.mkdtemp()
     self.number_of_files = 5
     self.files = []
     self.strings = {"string1": "Why did the chicken cross the road?", "string2": "To get to the other side."}
     files_created = 0
     while not (files_created == self.number_of_files):
         path = create_temp_file(file_dir=self.working_dir)
         md5sum = extract_md5(path)
         self.files.append({"path": path, "md5sum": md5sum})
         files_created += 1
Exemplo n.º 3
0
    def extract_archive_blob(self, blob):
        # handle the tarball
        temp_path = create_temp_file(file_dir=self.working_dir, write_path_to_file=False)
        temp_file = open(temp_path, 'w')
        temp_file.write(blob)
        temp_file.seek(0)
        temp_file.close()
        shutil.move(temp_path, "%s.tar.gz" % temp_path)

        tarball = GlideinTar()
        self.assertTrue(tarball.is_tarfile("%s.tar.gz" % temp_path), "Blob tarball fails tarball.is_tarfile test")

        self.extract_archive_file("%s.tar.gz" % temp_path)
Exemplo n.º 4
0
 def create_files(self, number_of_files, suffix=""):
     """
     Create temporary files using the tempfile module.  The absolute path toThe file extension to place on the temporary file
     the file is written to the file for content.
     
     @type number_of_files: int
     @param number_of_files: The number of temporary files to create
     @type file_suffix: string
     @param file_suffix: The file extension to place on the temporary file
     """
     files_created = 0
     while not (files_created == number_of_files):
         path = create_temp_file(file_suffix=suffix, file_dir=self.cleanup_dir)
         files_created += 1