コード例 #1
0
    def launch_zip(self, zipdir: str) -> None:
        """Downloads and unzip a zip version from a git repo"""

        bakdir = None
        if os.path.exists(zipdir):
            bakdir = zipdir + ".bak"
            if os.path.exists(bakdir):
                shutil.rmtree(bakdir)
            os.rename(zipdir, bakdir)
        os.makedirs(zipdir)
        zipurl = utils.get_zip_url(self.repo)
        if not zipurl:
            self.failure.emit(
                self.repo,
                translate("AddonsInstaller", "Error: Unable to locate ZIP from")
                + " "
                + self.repo.name,
            )
            return

        self.zipdir = zipdir
        self.bakdir = bakdir

        NetworkManager.AM_NETWORK_MANAGER.progress_made.connect(self.update_zip_status)
        NetworkManager.AM_NETWORK_MANAGER.progress_complete.connect(self.finish_zip)
        self.zip_download_index = (
            NetworkManager.AM_NETWORK_MANAGER.submit_monitored_get(zipurl)
        )
コード例 #2
0
    def download(self, baseurl, clonedir):
        "downloads and unzip a zip version from a git repo"

        bakdir = None
        if os.path.exists(clonedir):
            bakdir = clonedir+".bak"
            if os.path.exists(bakdir):
                shutil.rmtree(bakdir)
            os.rename(clonedir, bakdir)
        os.makedirs(clonedir)
        zipurl = utils.get_zip_url(baseurl)
        if not zipurl:
            return translate("AddonsInstaller", "Error: Unable to locate zip from") + " " + baseurl
        try:
            print("Downloading "+zipurl)
            u = utils.urlopen(zipurl)
        except Exception:
            return translate("AddonsInstaller", "Error: Unable to download") + " " + zipurl
        if not u:
            return translate("AddonsInstaller", "Error: Unable to download") + " " + zipurl
        zfile = _stringio()
        zfile.write(u.read())
        zfile = zipfile.ZipFile(zfile)
        master = zfile.namelist()[0]  # github will put everything in a subfolder
        zfile.extractall(clonedir)
        u.close()
        zfile.close()
        for filename in os.listdir(clonedir+os.sep+master):
            shutil.move(clonedir+os.sep+master+os.sep+filename, clonedir+os.sep+filename)
        os.rmdir(clonedir+os.sep+master)
        if bakdir:
            shutil.rmtree(bakdir)
        return translate("AddonsInstaller", "Successfully installed") + " " + zipurl