Exemple #1
0
    def download_from_github(self):
        # download
        Logger.i('Downloading repository: {0}...'.format(self.get_name()))

        download_url = self.get_download_url()
        download_filename = self.get_download_filename()
        download_dest_dir = Constants.TEMP_DIR
        download_dest_path = os.path.join(Constants.TEMP_DIR,
                                          download_filename)
        unpacked_dir = self.get_temp_dir()
        unpack_dir = Constants.TEMP_DIR
        force_download = False

        _, git_data_type, git_data_version = self.get_git_data()

        if git_data_type == Repository.GIT_TYPE_BRANCH:
            force_download = True

        # skip if exists
        if not force_download and os.path.isfile(download_dest_path):
            Logger.i('Repository already downloaded: {0}'.format(
                self.get_name()))
        else:
            FileUtil.remove_file(download_dest_path)

            DownloadUtil.download_file(download_url, download_dest_dir,
                                       download_filename)

            # check if file was downloaded
            if os.path.isfile(download_dest_path):
                Logger.i('Repository downloaded: {0}'.format(self.get_name()))
            else:
                Logger.f('Problems when download repository: {0}'.format(
                    self.get_name()))

        # unpack
        Logger.i('Unpacking repository: {0}...'.format(self.get_name()))

        if not force_download and os.path.isdir(unpacked_dir):
            Logger.i('Repository already unpacked: {0}...'.format(
                self.get_name()))
        else:
            FileUtil.remove_dir(unpacked_dir)

            # untar file
            FileUtil.create_dir(unpack_dir)

            tar = tarfile.open(download_dest_path)
            tar.extractall(path=unpack_dir)
            tar.close()

            if os.path.isdir(unpacked_dir):
                Logger.i('Repository unpacked: {0}'.format(self.get_name()))
            else:
                Logger.f('Problems when unpack repository: {0}'.format(
                    self.get_name()))
Exemple #2
0
    def test_remove_file(self, d):
        os.chdir(d.path)

        filename = 'new-file.txt'

        FileUtil.write_to_file('.', filename, 'content test')

        self.assertTrue(os.path.isfile(filename))

        FileUtil.remove_file(filename)

        self.assertFalse(os.path.isfile(filename))
Exemple #3
0
    def download_from_zip(self):
        # download
        Logger.i('Downloading repository: {0}...'.format(self.get_name()))

        download_url = self.get_download_url()
        download_filename = self.get_download_filename()
        download_dest_dir = Constants.TEMP_DIR
        download_dest_path = os.path.join(download_dest_dir, download_filename)
        unpacked_dir = self.get_temp_dir()
        unpack_dir = download_dest_dir

        # skip if exists
        if os.path.isfile(download_dest_path):
            Logger.i('Repository already downloaded: {0}'.format(
                self.get_name()))
        else:
            FileUtil.remove_file(download_dest_path)

            DownloadUtil.download_file(download_url, download_dest_dir,
                                       download_filename)

            # check if file was downloaded
            if os.path.isfile(download_dest_path):
                Logger.i('Repository downloaded: {0}'.format(self.get_name()))
            else:
                Logger.f('Problems when download repository: {0}'.format(
                    self.get_name()))

        # unpack
        Logger.i('Unpacking repository: {0}...'.format(self.get_name()))

        if os.path.isdir(unpacked_dir):
            Logger.i('Repository already unpacked: {0}...'.format(
                self.get_name()))
        else:
            FileUtil.remove_dir(unpacked_dir)

            # unpack file
            FileUtil.create_dir(unpack_dir)

            zipref = zipfile.ZipFile(download_dest_path, 'r')
            zipref.extractall(path=unpack_dir)
            zipref.close()

            if os.path.isdir(unpacked_dir):
                Logger.i('Repository unpacked: {0}'.format(self.get_name()))
            else:
                Logger.f('Problems when unpack repository: {0}'.format(
                    self.get_name()))