Exemplo n.º 1
0
 def save(self, *args, **kwargs):
     obj = super(ConfigurationForm, self).save(*args, **kwargs)
     if self._orig.get('repourl') != obj.repourl:
         p = pbi.PBI()
         p.set_appdir("/var/pbi")
         for repoid, name in p.listrepo():
             p.deleterepo(repoid=repoid)
         p.addrepo(repofile='/var/tmp/plugins.rpo')
     return obj
Exemplo n.º 2
0
    def get_remote(self, repo_id=None, cache=False):
        if not repo_id:
            repo_id = self._def_repo_id()
        if cache and repo_id in self.__cache:
            log.debug("Using cached results for %s", repo_id)
            return self.__cache.get(repo_id)

        log.debug("Retrieving available plugins from repo %s", repo_id)

        p = pbi.PBI()
        p.pbid(flags=pbi.PBID_FLAGS_REFRESH, sync=True)

        results = p.browser(repo_id=repo_id,
                            flags=pbi.PBI_BROWSER_FLAGS_VIEWALL)
        if not results:
            log.debug("No results returned for repo %s", repo_id)
            return results

        plugins = []
        results.sort(key=lambda x: x['Application'].lower())

        for p in results:
            try:
                index_entry = self.get_index_entry(
                    repo_id,
                    application=p['Application'],
                    arch=p['Arch'],
                    version=p['Version'])
                if not index_entry:
                    log.debug("not index entry found for %s", p['Application'])
                    continue

                urls = self.get_mirror_urls(repo_id)

                item = self._get_remote_item(repo_id, p, index_entry, urls)
                if item is False:
                    log.debug("unable to create plugin for %s",
                              p['Application'])
                    continue

                plugins.append(item)
            except Exception as e:
                log.debug("Failed to get remote item: %s", e)

        self.__cache[repo_id] = plugins
        return plugins
Exemplo n.º 3
0
    def get_repo(self, repo_id=None, create=False):
        p = pbi.PBI()

        if repo_id:
            repos = p.listrepo(repoid=repo_id)
        else:
            repos = p.listrepo()

        if not repos and create is False:
            return None

        elif not repos and create is True:
            if not self.create_repo():
                return None
            repos = p.listrepo()

        elif repos and repo_id is not None:
            for repo in repos:
                return repo

        for repo in repos:
            if re.match('Official FreeNAS Repository', repo[1], re.I):
                return repo

        for repo in repos:
            return repo

        if create is True:
            if not self.create_repo():
                return None

            repos = p.listrepo()
            if not repos:
                return None

        for repo in repos:
            #repoid = repo[0]
            description = repo[1]
            if re.match('Official FreeNAS Repository', description, re.I):
                return repo

        return None
Exemplo n.º 4
0
    def create_repo(self):
        from freenasUI.middleware.notifier import notifier
        url = PLUGINS_REPO
        rpath = "/var/tmp/pbi-repo.rpo"

        r = requests.get(url, timeout=8)
        if r.status_code != requests.codes.ok:
            return False

        with open(rpath, "w") as f:
            for byte in r:
                f.write(byte)
            f.close()

        p = pbi.PBI()

        out = p.addrepo(repofile=rpath)
        if not out:
            return False

        notifier().restart("pbid")
        return True