How to use the paddlehub.commands.base_command.BaseCommand function in paddlehub

To help you get started, we’ve selected a few paddlehub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PaddlePaddle / PaddleHub / paddlehub / commands / hub.py View on Github external
def execute(self, argv):
        logger.setLevel("NOLOG")

        if not argv:
            help.command.execute(argv)
            exit(1)
            return False
        sub_command = argv[0]
        if not sub_command in BaseCommand.command_dict:
            print("ERROR: unknown command '%s'" % sub_command)
            help.command.execute(argv)
            exit(1)
            return False
        srv_utils.hub_stat(['hub'] + argv)
        command = BaseCommand.command_dict[sub_command]
        return command.execute(argv[1:])
github PaddlePaddle / PaddleHub / paddlehub / commands / hub.py View on Github external
import os

from paddlehub.common.logger import logger
from paddlehub.common.utils import sys_stdin_encoding
from paddlehub.common import srv_utils
from paddlehub.commands.base_command import BaseCommand
from paddlehub.commands import show
from paddlehub.commands import help
from paddlehub.commands import version
from paddlehub.commands import run
from paddlehub.commands import download
from paddlehub.common.lock import lock
from paddlehub.common.dir import CONF_HOME


class HubCommand(BaseCommand):
    name = "hub"

    def __init__(self, name):
        super(HubCommand, self).__init__(name)
        self.show_in_help = False

    def execute(self, argv):
        logger.setLevel("NOLOG")

        if not argv:
            help.command.execute(argv)
            exit(1)
            return False
        sub_command = argv[0]
        if not sub_command in BaseCommand.command_dict:
            print("ERROR: unknown command '%s'" % sub_command)
github PaddlePaddle / PaddleHub / paddlehub / commands / clear.py View on Github external
return cnt


def file_size_in_human_format(size):
    size = float(size)
    if size < 1024:
        return "%.1fB" % size
    elif size < 1024 * 1024:
        return "%.1fK" % (size / 1024)
    elif size < 1024 * 1024 * 1024:
        return "%.1fM" % (size / (1024 * 1024))
    else:
        return "%.1fG" % (size / (1024 * 1024 * 1024))


class ClearCommand(BaseCommand):
    name = "clear"

    def __init__(self, name):
        super(ClearCommand, self).__init__(name)
        self.show_in_help = True
        self.description = "Clear all cached data."

    def cache_dir(self):
        return CACHE_HOME

    def execute(self, argv):
        result = True
        total_file_size = 0
        total_file_count = 0
        for rootdir, dirs, files in os.walk(self.cache_dir(), topdown=False):
            for filename in files:
github PaddlePaddle / PaddleHub / paddlehub / commands / install.py View on Github external
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse

from paddlehub.common import utils
from paddlehub.module.manager import default_module_manager
from paddlehub.commands.base_command import BaseCommand, ENTRY


class InstallCommand(BaseCommand):
    name = "install"

    def __init__(self, name):
        super(InstallCommand, self).__init__(name)
        self.show_in_help = True
        self.description = "Install PaddleHub module."
        self.parser = self.parser = argparse.ArgumentParser(
            description=self.__class__.__doc__,
            prog='%s %s ' % (ENTRY, name),
            usage='%(prog)s',
            add_help=False)

    def execute(self, argv):
        if not argv:
            print("ERROR: Please specify a module name.\n")
            self.help()
github PaddlePaddle / PaddleHub / paddlehub / commands / version.py View on Github external
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from paddlehub import version
from paddlehub.commands.base_command import BaseCommand


class VersionCommand(BaseCommand):
    name = "version"

    def __init__(self, name):
        super(VersionCommand, self).__init__(name)
        self.show_in_help = True
        self.description = "Show PaddleHub's version."

    def execute(self, argv):
        print("hub %s" % version.hub_version)
        return True


command = VersionCommand.instance()
github PaddlePaddle / PaddleHub / paddlehub / commands / help.py View on Github external
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from paddlehub.commands.base_command import BaseCommand


class HelpCommand(BaseCommand):
    name = "help"

    def __init__(self, name):
        super(HelpCommand, self).__init__(name)
        self.show_in_help = True
        self.description = "Show help for commands."

    def get_all_commands(self):
        return BaseCommand.command_dict

    def execute(self, argv):
        hub_command = BaseCommand.command_dict["hub"]
        help_text = "\n"
        help_text += "Usage:\n"
        help_text += "%s  [options]\n" % hub_command.name
        help_text += "\n"
github PaddlePaddle / PaddleHub / paddlehub / commands / config.py View on Github external
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
import json
import os
import re

from paddlehub.commands.base_command import BaseCommand, ENTRY
from paddlehub.common.dir import CONF_HOME
from paddlehub.common.server_config import default_server_config


class ConfigCommand(BaseCommand):
    name = "config"

    def __init__(self, name):
        super(ConfigCommand, self).__init__(name)
        self.show_in_help = True
        self.description = "Configure PaddleHub."
        self.parser = argparse.ArgumentParser(
            description=self.__class__.__doc__,
            prog='%s %s [COMMAND]' % (ENTRY, name),
            usage='%(prog)s',
            add_help=True)
        self.parser.add_argument("command")
        self.parser.add_argument("option", nargs="?")
        self.parser.add_argument("value", nargs="?")

    @staticmethod
github PaddlePaddle / PaddleHub / paddlehub / commands / download.py View on Github external
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
import os

from paddlehub.common import utils
from paddlehub.common.downloader import default_downloader
from paddlehub.common.hub_server import default_hub_server
from paddlehub.commands.base_command import BaseCommand, ENTRY


class DownloadCommand(BaseCommand):
    name = "download"

    def __init__(self, name):
        super(DownloadCommand, self).__init__(name)
        self.show_in_help = True
        self.description = "Download PaddlePaddle pretrained model/module files."
        self.parser = self.parser = argparse.ArgumentParser(
            description=self.__class__.__doc__,
            prog='%s %s ' % (ENTRY, name),
            usage='%(prog)s [options]',
            add_help=False)
        # yapf: disable
        self.add_arg("--type",         str,  "All", "choice: Module/Model/All")
        self.add_arg('--output_path',  str,  ".",   "path to save the model/module" )
        self.add_arg('--uncompress',   bool, False,  "uncompress the download package or not" )
        # yapf: enable
github PaddlePaddle / PaddleHub / paddlehub / commands / base_command.py View on Github external
def instance(cls):
        if cls.name in BaseCommand.command_dict:
            command = BaseCommand.command_dict[cls.name]
            if command.__class__.__name__ != cls.__name__:
                raise KeyError(
                    "Command dict already has a command %s with type %s" %
                    (cls.name, command.__class__))
            return command
        if not hasattr(cls, '_instance'):
            cls._instance = cls(cls.name)
        BaseCommand.command_dict[cls.name] = cls._instance
        return cls._instance
github PaddlePaddle / PaddleHub / paddlehub / commands / search.py View on Github external
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse

from paddlehub.common import utils
from paddlehub.common.hub_server import default_hub_server
from paddlehub.commands.base_command import BaseCommand, ENTRY
from paddlehub.commands.cml_utils import TablePrinter


class SearchCommand(BaseCommand):
    name = "search"

    def __init__(self, name):
        super(SearchCommand, self).__init__(name)
        self.show_in_help = True
        self.description = "Search PaddleHub pretrained model through model keywords."
        self.parser = self.parser = argparse.ArgumentParser(
            description=self.__class__.__doc__,
            prog='%s %s ' % (ENTRY, name),
            usage='%(prog)s',
            add_help=False)

    def execute(self, argv):
        if not argv:
            argv = ['.*']