Пример #1
0
    def getProductFile(self, product_name, fname='readme.txt'):
        """Return the content of a file of the product
        case-insensitive, if it does not exist -> None
        """
        packages = get_packages()
        prodpath = packages.get(product_name)
        if prodpath is None:
            prodpath = packages.get('Products.' + product_name)

        if prodpath is None:
            return None

        # now list the directory to get the readme.txt case-insensitive
        try:
            files = os.listdir(prodpath)
        except OSError:
            return None

        for fil in files:
            if fil.lower() != fname:
                continue
            text = open(os.path.join(prodpath, fil)).read()
            try:
                return six.text_type(text)
            except UnicodeDecodeError:
                try:
                    return six.text_type(text, 'utf-8')
                except UnicodeDecodeError:
                    return six.text_type(text, 'utf-8', 'replace')
        return None
Пример #2
0
    def getProductFile(self, product_name, fname='readme.txt'):
        """Return the content of a file of the product
        case-insensitive, if it does not exist -> None
        """
        packages = get_packages()
        prodpath = packages.get(product_name)
        if prodpath is None:
            prodpath = packages.get('Products.' + product_name)

        if prodpath is None:
            return None

        # now list the directory to get the readme.txt case-insensitive
        try:
            files = os.listdir(prodpath)
        except OSError:
            return None

        for fil in files:
            if fil.lower() != fname:
                continue
            text = open(os.path.join(prodpath, fil)).read()
            try:
                return unicode(text)
            except UnicodeDecodeError:
                try:
                    return unicode(text, 'utf-8')
                except UnicodeDecodeError:
                    return unicode(text, 'utf-8', 'replace')
        return None
    def listInstallableProducts(self, skipInstalled=True):
        """List candidate CMF products for installation -> list of dicts
           with keys:(id,title,hasError,status)
        """
        self._init_errors(reset=True)

        # Returns full names with Products. prefix for all packages / products
        packages = get_packages()

        pids = []
        for pkg in packages:
            if not self.isProductInstallable(pkg):
                continue
            if pkg.startswith('Products.'):
                pkg = pkg[9:]
            pids.append(pkg)

        # Get product list from the extension profiles
        profile_pids = self.listInstallableProfiles()

        for pp in profile_pids:
            if pp in pids or pp in packages:
                continue
            if not self.isProductInstallable(pp):
                continue
            pids.append(pp)

        if skipInstalled:
            installed = [
                p['id'] for p in self.listInstalledProducts(showHidden=True)
            ]
            pids = [r for r in pids if r not in installed]

        res = []
        for pid in pids:
            installed_product = self._getOb(pid, None)
            name = pid
            profile = self.getInstallProfile(pid)
            if profile:
                name = profile['title']
            record = {'id': pid, 'title': name}
            if installed_product:
                record['status'] = installed_product.getStatus()
                record['hasError'] = installed_product.hasError()
            else:
                record['status'] = 'new'
                record['hasError'] = False
            res.append(record)
        res.sort(
            lambda x, y: cmp(
                x.get('title', x.get('id', None)),
                y.get('title', y.get('id', None))
            )
        )
        return res
Пример #4
0
    def listInstallableProducts(self, skipInstalled=True):
        """List candidate CMF products for installation -> list of dicts
           with keys:(id,title,hasError,status)
        """
        # reset the list of broken products
        if getattr(self, '_v_errors', True):
            self._v_errors = {}

        # Returns full names with Products. prefix for all packages / products
        packages = get_packages()

        pids = []
        for p in packages:
            if not self.isProductInstallable(p):
                continue
            if p.startswith('Products.'):
                p = p[9:]
            pids.append(p)

        # Get product list from the extension profiles
        profile_pids = self.listInstallableProfiles()

        for p in profile_pids:
            if p in pids or p in packages:
                continue
            if not self.isProductInstallable(p):
                continue
            pids.append(p)

        if skipInstalled:
            installed = [p['id'] for p in self.listInstalledProducts(showHidden=True)]
            pids = [r for r in pids if r not in installed]

        res = []
        for r in pids:
            p = self._getOb(r, None)
            name = r
            profile = self.getInstallProfile(r)
            if profile:
                name = profile['title']
            if p:
                res.append({'id': r, 'title': name, 'status': p.getStatus(),
                            'hasError': p.hasError()})
            else:
                res.append({'id': r, 'title': name, 'status': 'new', 'hasError': False})
        res.sort(lambda x, y: cmp(x.get('title', x.get('id', None)),
                                 y.get('title', y.get('id', None))))
        return res