install.py 2.0 KB
Newer Older
S
Steffy-zxf 已提交
1
#coding:utf-8
W
wuzewu 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2019  PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     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.
15

W
wuzewu 已提交
16 17 18
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
W
wuzewu 已提交
19 20 21

import argparse

W
wuzewu 已提交
22 23 24
from paddlehub.common import utils
from paddlehub.module.manager import default_module_manager
from paddlehub.commands.base_command import BaseCommand, ENTRY
W
wuzewu 已提交
25 26 27 28 29 30 31 32


class InstallCommand(BaseCommand):
    name = "install"

    def __init__(self, name):
        super(InstallCommand, self).__init__(name)
        self.show_in_help = True
Z
Zeyu Chen 已提交
33
        self.description = "Install PaddleHub module."
W
wuzewu 已提交
34 35 36 37 38
        self.parser = self.parser = argparse.ArgumentParser(
            description=self.__class__.__doc__,
            prog='%s %s <module_name>' % (ENTRY, name),
            usage='%(prog)s',
            add_help=False)
W
wuzewu 已提交
39

W
wuzewu 已提交
40
    def execute(self, argv):
W
wuzewu 已提交
41
        if not argv:
Z
Zeyu Chen 已提交
42
            print("ERROR: Please specify a module name.\n")
W
wuzewu 已提交
43 44
            self.help()
            return False
W
wuzewu 已提交
45
        module_name = argv[0]
W
wuzewu 已提交
46 47 48 49
        module_version = None if "==" not in module_name else module_name.split(
            "==")[1]
        module_name = module_name if "==" not in module_name else module_name.split(
            "==")[0]
S
shenyuhan 已提交
50
        extra = {"command": "install"}
W
wuzewu 已提交
51
        result, tips, module_dir = default_module_manager.install_module(
S
shenyuhan 已提交
52
            module_name=module_name, module_version=module_version, extra=extra)
W
wuzewu 已提交
53
        print(tips)
W
wuzewu 已提交
54
        return True
W
wuzewu 已提交
55 56 57


command = InstallCommand.instance()