Example #1
0
 def store_depcheck_db(self, data_dir):
     """ Zip CVE DB file and store to S3 """
     with tempdir() as archive_dir:
         archive_path = os.path.join(archive_dir, self._DB_ARCHIVE)
         db_file_path = os.path.join(data_dir, self._DB_FILENAME)
         Archive.zip_file(db_file_path, archive_path, junk_paths=True)
         self.store_file(archive_path, self._DB_ARCHIVE)
 def store_index(self, target_dir):
     """ Zip files in target_dir/central-index dir and store to S3 """
     with tempdir() as temp_dir:
         central_index_dir = os.path.join(target_dir, self._INDEX_DIRNAME)
         archive_path = os.path.join(temp_dir, self._INDEX_ARCHIVE)
         Archive.zip_file(central_index_dir, archive_path, junk_paths=True)
         self.store_file(archive_path, self._INDEX_ARCHIVE)
Example #3
0
    def retrieve_depcheck_db_if_exists(self, data_dir):
        """ Retrieve zipped CVE DB file as stored on S3 and extract"""
        if self.object_exists(self._DB_ARCHIVE):
            with tempdir() as archive_dir:
                archive_path = os.path.join(archive_dir, self._DB_ARCHIVE)
                self.retrieve_file(self._DB_ARCHIVE, archive_path)
                Archive.extract_zip(archive_path, data_dir)
                return True

        return False
    def retrieve_index_if_exists(self, target_dir):
        """ Retrieve central-index.zip from S3 and extract into target_dir/central-index"""
        if self.object_exists(self._INDEX_ARCHIVE):
            with tempdir() as temp_dir:
                archive_path = os.path.join(temp_dir, self._INDEX_ARCHIVE)
                central_index_dir = os.path.join(target_dir,
                                                 self._INDEX_DIRNAME)
                self.retrieve_file(self._INDEX_ARCHIVE, archive_path)
                Archive.extract_zip(archive_path,
                                    central_index_dir,
                                    mkdest=True)
                return True

        return False
Example #5
0
    def get_extracted_source_jar(self):
        """Get extracted package source jar file

        :return: path to extracted source jar file
        """
        if not os.path.isdir(self._extracted_source_jar_dir):
            source_jar_path = self.get_source_jar()
            try:
                Archive.extract(source_jar_path,
                                self._extracted_source_jar_dir)
            except:
                # remove in case of failure so if one catches the exception, the extraction code is correctly
                # called again
                shutil.rmtree(self._extracted_source_jar_dir,
                              ignore_errors=True)
                raise

        return self._extracted_source_jar_dir
Example #6
0
    def get_extracted_source_tarball(self):
        """
        :return: path to the extracted package tarball
        """
        self._construct_source_tarball_names()
        if not os.path.isdir(self._extracted_tarball_dir):
            source_tarball_path = self.get_source_tarball()
            os.makedirs(self._extracted_tarball_dir)
            try:
                Archive.extract(source_tarball_path,
                                self._extracted_tarball_dir)
            except:
                # remove in case of failure so if one catches the exception, the extraction code is correctly
                # called again
                shutil.rmtree(self._extracted_tarball_dir, ignore_errors=True)
                raise

        return self._extracted_tarball_dir