Пример #1
0
    def run(self):

        "populates the list of addons"

        self.progressbar_show.emit(True)
        u = utils.urlopen("https://github.com/FreeCAD/FreeCAD-addons")
        if not u:
            self.progressbar_show.emit(False)
            self.done.emit()
            self.stop = True
            return
        p = u.read()
        if sys.version_info.major >= 3 and isinstance(p, bytes):
            p = p.decode("utf-8")
        u.close()
        p = p.replace("\n"," ")
        p = re.findall("octicon-file-submodule(.*?)message",p)
        basedir = FreeCAD.getUserAppDataDir()
        moddir = basedir + os.sep + "Mod"
        repos = []
        # querying official addons
        for l in p:
            #name = re.findall("data-skip-pjax=\"true\">(.*?)<",l)[0]
            name = re.findall("title=\"(.*?) @",l)[0]
            self.info_label.emit(name)
            #url = re.findall("title=\"(.*?) @",l)[0]
            url = utils.getRepoUrl(l)
            if url:
                addondir = moddir + os.sep + name
                #print ("found:",name," at ",url)
                if os.path.exists(addondir) and os.listdir(addondir):
                    # make sure the folder exists and it contains files!
                    state = 1
                else:
                    state = 0
                repos.append([name,url,state])
        # querying custom addons
        customaddons = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons").GetString("CustomRepositories","").split("\n")
        for url in customaddons:
            if url:
                name = url.split("/")[-1]
                if name.lower().endswith(".git"):
                    name = name[:-4]
                addondir = moddir + os.sep + name
                if not os.path.exists(addondir):
                    state = 0
                else:
                    state = 1
                repos.append([name,url,state])
        if not repos:
            self.info_label.emit(translate("AddonsInstaller", "Unable to download addon list."))
        else:
            repos = sorted(repos, key=lambda s: s[0].lower())
            for repo in repos:
                self.addon_repo.emit(repo)
            self.info_label.emit(translate("AddonsInstaller", "Workbenches list was updated."))
        self.progressbar_show.emit(False)
        self.done.emit()
        self.stop = True
Пример #2
0
    def run(self):

        "populates the list of addons"

        self.progressbar_show.emit(True)
        u = utils.urlopen("https://github.com/FreeCAD/FreeCAD-addons")
        if not u:
            self.progressbar_show.emit(False)
            self.done.emit()
            self.stop = True
            return
        p = u.read()
        if sys.version_info.major >= 3 and isinstance(p, bytes):
            p = p.decode("utf-8")
        u.close()
        p = p.replace("\n", " ")
        p = re.findall("octicon-file-submodule(.*?)message", p)
        basedir = FreeCAD.getUserAppDataDir()
        moddir = basedir + os.sep + "Mod"
        repos = []
        # querying official addons
        for l in p:
            #name = re.findall("data-skip-pjax=\"true\">(.*?)<",l)[0]
            res = re.findall("title=\"(.*?) @", l)
            if res:
                name = res[0]
            else:
                print("AddonMananger: Debug: couldn't find title in", l)
                continue
            self.info_label.emit(name)
            #url = re.findall("title=\"(.*?) @",l)[0]
            url = utils.getRepoUrl(l)
            if url:
                addondir = moddir + os.sep + name
                #print ("found:",name," at ",url)
                if os.path.exists(addondir) and os.listdir(addondir):
                    # make sure the folder exists and it contains files!
                    state = 1
                else:
                    state = 0
                repos.append([name, url, state])
        # querying custom addons
        customaddons = FreeCAD.ParamGet(
            "User parameter:BaseApp/Preferences/Addons").GetString(
                "CustomRepositories", "").split("\n")
        for url in customaddons:
            if url:
                name = url.split("/")[-1]
                if name.lower().endswith(".git"):
                    name = name[:-4]
                addondir = moddir + os.sep + name
                if not os.path.exists(addondir):
                    state = 0
                else:
                    state = 1
                repos.append([name, url, state])
        if not repos:
            self.info_label.emit(
                translate("AddonsInstaller", "Unable to download addon list."))
        else:
            repos = sorted(repos, key=lambda s: s[0].lower())
            for repo in repos:
                self.addon_repo.emit(repo)
            self.info_label.emit(
                translate("AddonsInstaller", "Workbenches list was updated."))
        git_exe = utils.checkGitBinary()
        import platform
        try:
            out = os.popen(git_exe + ' --version', 'r')
        except:
            if platform.system() == 'Windows':
                FreeCAD.Console.PrintLog(
                    translate(
                        "AddonsInstaller",
                        "The Git executable has not been found in the path.") +
                    "\n")
            else:
                FreeCAD.Console.PrintLog(
                    translate("AddonsInstaller",
                              "The Git binary has not been found.") + "\n")
        from distutils.version import StrictVersion
        if 'out' in locals():
            out_string = out.read()
            out.close()
            result = re.search('(\d+\.\d+\.\d+)', out_string)
            git_version = StrictVersion(result.group(1))
            if platform.system() == 'Windows':
                FreeCAD.Console.PrintLog(
                    translate("AddonsInstaller",
                              "Found Git executable version ") +
                    str(git_version) + "\n")
            else:
                FreeCAD.Console.PrintLog(
                    translate("AddonsInstaller", "Found Git binary version ") +
                    str(git_version) + "\n")
        else:
            git_version = StrictVersion("0.0.0")
        self.progressbar_show.emit(False)
        self.done.emit()
        self.stop = True