Beispiel #1
0
    def _Handle_Download(self, tarball=None):
        errors = []
        url = None
        pkg_path = None

        # In case of running from the GUI, the file is downloaded by
        # now, so the only thing left to do is to update the params.
        if self.app_fetch and self.app_fetch.startswith("http:"):
            if CTK.DownloadEntry_Exists(self.app_fetch):
                down_entry = CTK.DownloadEntry_Factory(self.app_fetch)
                self.targz_path = down_entry.target_path
                return []

        # Auto
        if not self.app_fetch or self.app_fetch == 'auto':
            url = tarball

        # Static file
        elif self.app_fetch[0] == '/':
            if not os.path.exists(self.app_fetch):
                errors += [
                    _("File or Directory not found: %(app_path)s") %
                    ({
                        'app_path': self.app_fetch
                    })
                ]
                return errors

            if os.path.isdir(self.app_fetch):
                self.targz_path = self.app_dir
            else:
                self.targz_path = self.app_fetch

        # Download the software
        else:
            url = self.app_fetch

        if url:
            Install_Log.log("Downloading: %s" % (url))

            self.downloader = CTK.DownloadEntry_Factory(url)
            self.downloader.start()

            while self.downloader.isAlive():
                self.downloader.join(1)
                if self.downloader.size <= 0:
                    Install_Log.log("Downloaded %d bytes..." %
                                    (self.downloader.downloaded))
                else:
                    Install_Log.log(
                        "Downloaded %d / %d (%d%%)..." %
                        (self.downloader.downloaded, self.downloader.size,
                         (self.downloader.downloaded * 100 /
                          self.downloader.size)))

            self.targz_path = self.downloader.target_path
            Install_Log.log("Download completed: %s" % (self.targz_path))

        return []
Beispiel #2
0
def _Setup_unpack():
    url_download = CTK.cfg.get_val('tmp!market!install!download')

    # has it been downloaded?
    pkg_filename = url_download.split('/')[-1]

    package_path = CTK.cfg.get_val('tmp!market!install!local_package')
    if not package_path or not os.path.exists(package_path):
        down_entry = CTK.DownloadEntry_Factory(url_download)
        package_path = down_entry.target_path

    # Create the local directory
    target_path = os.path.join(CHEROKEE_OWS_ROOT, str(int(time.time() * 100)))
    os.mkdir(target_path, 0700)
    CTK.cfg['tmp!market!install!root'] = target_path

    # Create the log file
    Install_Log.set_file(os.path.join(target_path, "install.log"))

    # Uncompress
    try:
        if sys.version_info < (
                2, 5
        ):  # tarfile module prior to 2.5 is useless to us: http://bugs.python.org/issue1509889
            raise tarfile.CompressionError

        Install_Log.log("Unpacking %s with Python" % (package_path))
        tar = tarfile.open(package_path, 'r:gz')
        for tarinfo in tar:
            Install_Log.log("  %s" % (tarinfo.name))
            tar.extract(tarinfo, target_path)
        ret = {'retcode': 0}
    except tarfile.CompressionError:
        command = "gzip -dc '%s' | tar xfv -" % (package_path)
        Install_Log.log(
            "Unpacking %(package_path)s with the GZip binary (cd: %(target_path)s): %(command)s"
            % (locals()))
        ret = popen.popen_sync(command, cd=target_path)
        Install_Log.log(ret['stdout'])
        Install_Log.log(ret['stderr'])

    # Set default permission
    Install_Log.log("Setting default permission 755 for directory %s" %
                    (target_path))
    os.chmod(
        target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP
        | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)

    # Remove the package
    if package_path.startswith(CHEROKEE_OWS_DIR):
        Install_Log.log("Skipping removal of: %s" % (package_path))
    else:
        Install_Log.log("Removing %s" % (package_path))
        os.unlink(package_path)

    return ret