Пример #1
0
    def __str__(self):
        msg = '{}'.format(self.name)
        if self.version:
            msg += '-{}'.format(self.version)

        if self.source:
            msg += ' from {}'.format(self.source)

        tips = 'No HubModule named {} was found'.format(log.FormattedText(text=msg, color='red'))

        if self.info:
            sort_infos = sorted(self.info.items(), key=lambda x: utils.Version(x[0]))

            table = log.Table()
            table.append(
                *['Name', 'Version', 'PaddlePaddle Version Required', 'PaddleHub Version Required'],
                widths=[15, 10, 35, 35],
                aligns=['^', '^', '^', '^'],
                colors=['cyan', 'cyan', 'cyan', 'cyan'])

            for _ver, info in sort_infos:
                paddle_version = 'Any' if not info['paddle_version'] else ', '.join(info['paddle_version'])
                hub_version = 'Any' if not info['hub_version'] else ', '.join(info['hub_version'])
                table.append(self.name, _ver, paddle_version, hub_version, aligns=['^', '^', '^', '^'])

            tips += ':\n{}'.format(table)
        return tips
Пример #2
0
    def execute(self, argv: List) -> bool:
        if not argv:
            print("ERROR: You must give one module to show.")
            return False
        argv = argv[0]

        if os.path.exists(argv) and os.path.isdir(argv):
            try:
                module = Module.load(argv)
            except InvalidHubModule:
                print('{} is not a valid HubModule'.format(argv))
                return False
            except:
                print('Some exception occurred while loading the {}'.format(
                    argv))
                return False
        else:
            module = LocalModuleManager().search(argv)
            if not module:
                print('{} is not existed!'.format(argv))
                return False

        widths = [15, 40] if platform.is_windows else [15, 50]
        aligns = ['^', '<']
        colors = ['cyan', '']
        table = log.Table(widths=widths, colors=colors, aligns=aligns)

        table.append('ModuleName', module.name)
        table.append('Version', str(module.version))
        table.append('Summary', module.summary)
        table.append('Author', module.author)
        table.append('Author-Email', module.author_email)
        table.append('Location', module.directory)
        print(table)
        return True
Пример #3
0
    def execute(self, argv: List) -> bool:
        manager = LocalModuleManager()

        widths = [20, 40] if platform.is_windows() else [25, 50]
        aligns = ['^', '<']
        table = log.Table(widths=widths, aligns=aligns)

        table.append('ModuleName', 'Path', colors=['green', 'green'])

        for module in manager.list():
            table.append(module.name, module.directory)

        print(table)
        return True
Пример #4
0
    def execute(self, argv: List) -> bool:
        argv = '.*' if not argv else argv[0]

        widths = [20, 8, 30] if platform.is_windows() else [30, 8, 40]
        table = log.Table(widths=widths)
        table.append(*['ModuleName', 'Version', 'Summary'],
                     aligns=['^', '^', '^'],
                     colors=["blue", "blue", "blue"])
        CacheUpdater("hub_search", argv).start()
        results = module_server.search_module(name=argv)

        for result in results:
            table.append(result['name'], result['version'], result['summary'])

        print(table)
        return True
Пример #5
0
    def __str__(self):
        msg = '{}'.format(self.name)
        if self.version:
            msg += '-{}'.format(self.version)

        tips = '{} cannot be installed because some conditions are not met'.format(
            log.FormattedText(text=msg, color='red'))

        if self.info:
            sort_infos = sorted(self.info.items(), key=lambda x: utils.Version(x[0]))

            table = log.Table()
            table.append(
                *['Name', 'Version', 'PaddlePaddle Version Required', 'PaddleHub Version Required'],
                widths=[15, 10, 35, 35],
                aligns=['^', '^', '^', '^'],
                colors=['cyan', 'cyan', 'cyan', 'cyan'])

            import paddle
            import paddlehub

            for _ver, info in sort_infos:
                paddle_version = 'Any' if not info['paddle_version'] else ', '.join(info['paddle_version'])
                for version in info['paddle_version']:
                    if not utils.Version(paddle.__version__).match(version):
                        paddle_version = '{}(Mismatch)'.format(paddle_version)
                        break

                hub_version = 'Any' if not info['hub_version'] else ', '.join(info['hub_version'])
                for version in info['hub_version']:
                    if not utils.Version(paddlehub.__version__).match(version):
                        hub_version = '{}(Mismatch)'.format(hub_version)
                        break

                table.append(self.name, _ver, paddle_version, hub_version, aligns=['^', '^', '^', '^'])

            tips += ':\n{}'.format(table)
        return tips