Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
7d6054ba
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7d6054ba
编写于
3月 21, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update commands
上级
c492de97
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
118 addition
and
51 deletion
+118
-51
paddle_hub/commands/__init__.py
paddle_hub/commands/__init__.py
+1
-1
paddle_hub/commands/base_command.py
paddle_hub/commands/base_command.py
+5
-2
paddle_hub/commands/download.py
paddle_hub/commands/download.py
+14
-7
paddle_hub/commands/help.py
paddle_hub/commands/help.py
+1
-0
paddle_hub/commands/hub.py
paddle_hub/commands/hub.py
+12
-10
paddle_hub/commands/install.py
paddle_hub/commands/install.py
+12
-5
paddle_hub/commands/list.py
paddle_hub/commands/list.py
+1
-0
paddle_hub/commands/run.py
paddle_hub/commands/run.py
+32
-21
paddle_hub/commands/search.py
paddle_hub/commands/search.py
+13
-1
paddle_hub/commands/show.py
paddle_hub/commands/show.py
+14
-2
paddle_hub/commands/uninstall.py
paddle_hub/commands/uninstall.py
+12
-2
paddle_hub/commands/version.py
paddle_hub/commands/version.py
+1
-0
未找到文件。
paddle_hub/commands/__init__.py
浏览文件 @
7d6054ba
...
...
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
.
import
hub
from
.
import
download
from
.
import
run
from
.
import
show
...
...
@@ -22,3 +21,4 @@ from . import install
from
.
import
uninstall
from
.
import
search
from
.
import
help
from
.
import
hub
paddle_hub/commands/base_command.py
浏览文件 @
7d6054ba
...
...
@@ -16,9 +16,10 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
paddle_hub.tools.arg_helper
import
add_argument
,
print_arguments
from
paddle_hub.tools.logger
import
logger
import
argparse
ENTRY
=
"hub"
class
BaseCommand
:
command_dict
=
{}
...
...
@@ -39,12 +40,14 @@ class BaseCommand:
assert
not
hasattr
(
self
.
__class__
,
'_instance'
),
'Please use `instance()` to get Command object!'
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
self
.
args
=
None
self
.
name
=
name
self
.
show_in_help
=
True
self
.
description
=
""
def
help
(
self
):
self
.
parser
.
print_help
()
def
add_arg
(
self
,
argument
,
type
=
"str"
,
default
=
None
,
help
=
None
):
add_argument
(
argument
=
argument
,
...
...
paddle_hub/commands/download.py
浏览文件 @
7d6054ba
...
...
@@ -16,10 +16,11 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
paddle_hub.tools.logger
import
logger
from
paddle_hub.commands.base_command
import
BaseCommand
from
paddle_hub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddle_hub.tools
import
utils
from
paddle_hub.tools.downloader
import
default_downloader
from
paddle_hub.hub_server
import
default_hub_server
import
argparse
class
DownloadCommand
(
BaseCommand
):
...
...
@@ -29,15 +30,21 @@ class DownloadCommand(BaseCommand):
super
(
DownloadCommand
,
self
).
__init__
(
name
)
self
.
show_in_help
=
True
self
.
description
=
"Download a paddle hub module."
self
.
parser
=
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
self
.
__class__
.
__doc__
,
prog
=
'%s %s <module_name>'
%
(
ENTRY
,
name
),
usage
=
'%(prog)s [options]'
,
add_help
=
False
)
# yapf: disable
self
.
add_arg
(
'--output_path'
,
str
,
"."
,
"path to save the module
, default in current directory
"
)
self
.
add_arg
(
'--output_path'
,
str
,
"."
,
"path to save the module"
)
self
.
add_arg
(
'--uncompress'
,
bool
,
False
,
"uncompress the download package or not"
)
# yapf: enable
def
help
(
self
):
self
.
parser
.
print_help
()
def
exec
(
self
,
argv
):
if
not
argv
:
print
(
"ERROR: Please specify a module
\n
"
)
self
.
help
()
return
False
module_name
=
argv
[
0
]
module_version
=
None
if
"=="
not
in
module_name
else
module_name
.
split
(
"=="
)[
1
]
...
...
@@ -55,7 +62,7 @@ class DownloadCommand(BaseCommand):
if
module_version
:
tips
+=
" with version %s"
%
module_version
print
(
tips
)
return
return
True
self
.
print_args
()
if
self
.
args
.
uncompress
:
...
...
@@ -65,7 +72,7 @@ class DownloadCommand(BaseCommand):
result
,
tips
,
file
=
default_downloader
.
download_file
(
url
=
url
,
save_path
=
self
.
args
.
output_path
)
print
(
tips
)
return
result
return
True
command
=
DownloadCommand
.
instance
()
paddle_hub/commands/help.py
浏览文件 @
7d6054ba
...
...
@@ -42,6 +42,7 @@ class HelpCommand(BaseCommand):
help_text
+=
" %-15s
\t\t
%s
\n
"
%
(
command
.
name
,
command
.
description
)
print
(
help_text
)
return
True
command
=
HelpCommand
.
instance
()
paddle_hub/commands/hub.py
浏览文件 @
7d6054ba
...
...
@@ -31,22 +31,24 @@ class HubCommand(BaseCommand):
def
__init__
(
self
,
name
):
super
(
HubCommand
,
self
).
__init__
(
name
)
self
.
show_in_help
=
False
# yapf: disable
self
.
add_arg
(
'command'
,
str
,
None
,
"command to run"
)
# yapf: enable
def
exec
(
self
,
argv
):
args
=
self
.
parser
.
parse_args
(
argv
[
1
:
2
])
if
not
args
.
command
in
BaseCommand
.
command_dict
:
logger
.
critical
(
"command %s not supported!"
%
args
.
command
)
if
not
argv
:
help
.
command
.
exec
(
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
.
exec
(
argv
)
exit
(
1
)
return
False
command
=
BaseCommand
.
command_dict
[
args
.
command
]
command
.
exec
(
argv
[
2
:])
command
=
BaseCommand
.
command_dict
[
sub_
command
]
return
command
.
exec
(
argv
[
1
:])
command
=
HubCommand
.
instance
()
if
__name__
==
"__main__"
:
command
.
exec
(
sys
.
argv
)
command
.
exec
(
sys
.
argv
[
1
:]
)
paddle_hub/commands/install.py
浏览文件 @
7d6054ba
...
...
@@ -16,9 +16,10 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
paddle_hub.tools.logger
import
logger
from
paddle_hub.commands.base_command
import
BaseCommand
from
paddle_hub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddle_hub.tools
import
utils
from
paddle_hub.module.manager
import
default_module_manager
import
argparse
class
InstallCommand
(
BaseCommand
):
...
...
@@ -28,12 +29,18 @@ class InstallCommand(BaseCommand):
super
(
InstallCommand
,
self
).
__init__
(
name
)
self
.
show_in_help
=
True
self
.
description
=
"Install the specify module to current environment."
self
.
parser
=
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
self
.
__class__
.
__doc__
,
prog
=
'%s %s <module_name>'
%
(
ENTRY
,
name
),
usage
=
'%(prog)s'
,
add_help
=
False
)
#TODO(wuzewu): add --upgrade option
def
help
(
self
):
self
.
parser
.
print_help
()
def
exec
(
self
,
argv
):
if
not
argv
:
print
(
"ERROR: Please specify a module
\n
"
)
self
.
help
()
return
False
module_name
=
argv
[
0
]
module_version
=
None
if
"=="
not
in
module_name
else
module_name
.
split
(
"=="
)[
1
]
...
...
@@ -42,7 +49,7 @@ class InstallCommand(BaseCommand):
result
,
tips
,
module_dir
=
default_module_manager
.
install_module
(
module_name
=
module_name
,
module_version
=
module_version
)
print
(
tips
)
return
result
return
True
command
=
InstallCommand
.
instance
()
paddle_hub/commands/list.py
浏览文件 @
7d6054ba
...
...
@@ -38,6 +38,7 @@ class ListCommand(BaseCommand):
for
module_name
,
module_dir
in
all_modules
.
items
():
list_text
+=
" %-20s
\t\t
%s
\n
"
%
(
module_name
,
module_dir
)
print
(
list_text
)
return
True
command
=
ListCommand
.
instance
()
paddle_hub/commands/run.py
浏览文件 @
7d6054ba
...
...
@@ -16,11 +16,14 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
paddle_hub.tools.logger
import
logger
from
paddle_hub.commands.base_command
import
BaseCommand
import
paddle_hub
as
hub
from
paddle_hub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddle_hub.data.reader
import
csv_reader
,
yaml_reader
from
paddle_hub.module.manager
import
default_module_manager
from
paddle_hub.tools
import
utils
from
paddle_hub.tools.arg_helper
import
add_argument
,
print_arguments
import
paddle_hub
as
hub
import
argparse
import
os
class
RunCommand
(
BaseCommand
):
...
...
@@ -30,51 +33,59 @@ class RunCommand(BaseCommand):
super
(
RunCommand
,
self
).
__init__
(
name
)
self
.
show_in_help
=
True
self
.
description
=
"Run the specify module"
self
.
parser
=
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
self
.
__class__
.
__doc__
,
prog
=
'%s %s <module>'
%
(
ENTRY
,
name
),
usage
=
'%(prog)s [options]'
)
# yapf: disable
self
.
add_arg
(
'--config'
,
str
,
None
,
"config file in yaml format"
)
self
.
add_arg
(
'--dataset'
,
str
,
None
,
"dataset be used"
)
self
.
add_arg
(
'--module'
,
str
,
None
,
"module to run"
)
self
.
add_arg
(
'--signature'
,
str
,
None
,
"signature to run"
)
# yapf: enable
def
_check_module
(
self
):
if
not
self
.
args
.
module
:
logger
.
critical
(
"lack of module"
)
self
.
help
()
exit
(
1
)
def
_check_dataset
(
self
):
if
not
self
.
args
.
dataset
:
logger
.
critical
(
"l
ack of dataset file"
)
print
(
"Error! L
ack of dataset file"
)
self
.
help
()
exit
(
1
)
if
not
utils
.
is_csv_file
(
self
.
args
.
dataset
):
logger
.
critical
(
"d
ataset file should in csv format"
)
print
(
"Error! D
ataset file should in csv format"
)
self
.
help
()
exit
(
1
)
def
_check_config
(
self
):
if
not
self
.
args
.
config
:
logger
.
critical
(
"l
ack of config file"
)
print
(
"Error! L
ack of config file"
)
self
.
help
()
exit
(
1
)
if
not
utils
.
is_yaml_file
(
self
.
args
.
config
):
logger
.
critical
(
"c
onfig file should in yaml format"
)
print
(
"Error! C
onfig file should in yaml format"
)
self
.
help
()
exit
(
1
)
def
help
(
self
):
self
.
parser
.
print_help
()
def
exec
(
self
,
argv
):
self
.
args
=
self
.
parser
.
parse_args
(
argv
)
self
.
print_args
()
self
.
_check_module
()
if
not
argv
:
print
(
"ERROR: Please specify a key
\n
"
)
self
.
help
()
return
False
module_name
=
argv
[
0
]
self
.
args
=
self
.
parser
.
parse_args
(
argv
[
1
:])
self
.
_check_dataset
()
self
.
_check_config
()
module
=
hub
.
Module
(
module_dir
=
self
.
args
.
module
)
module_dir
=
default_module_manager
.
search_module
(
module_name
)
if
not
module_dir
:
if
os
.
path
.
exists
(
module_name
):
module_dir
=
module_name
else
:
print
(
"Install Module %s"
%
module_name
)
result
,
tips
,
module_dir
=
default_module_manager
.
install_module
(
module_name
)
print
(
tips
)
if
not
result
:
return
False
module
=
hub
.
Module
(
module_dir
=
module_dir
)
yaml_config
=
yaml_reader
.
read
(
self
.
args
.
config
)
if
not
self
.
args
.
signature
:
...
...
paddle_hub/commands/search.py
浏览文件 @
7d6054ba
...
...
@@ -16,9 +16,10 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
paddle_hub.tools.logger
import
logger
from
paddle_hub.commands.base_command
import
BaseCommand
from
paddle_hub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddle_hub.tools
import
utils
from
paddle_hub.hub_server
import
default_hub_server
import
argparse
class
SearchCommand
(
BaseCommand
):
...
...
@@ -28,8 +29,18 @@ class SearchCommand(BaseCommand):
super
(
SearchCommand
,
self
).
__init__
(
name
)
self
.
show_in_help
=
True
self
.
description
=
"Search a paddle hub module with keyword."
self
.
parser
=
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
self
.
__class__
.
__doc__
,
prog
=
'%s %s <key>'
%
(
ENTRY
,
name
),
usage
=
'%(prog)s'
,
add_help
=
False
)
def
exec
(
self
,
argv
):
if
not
argv
:
print
(
"ERROR: Please specify a key
\n
"
)
self
.
help
()
return
False
module_name
=
argv
[
0
]
module_list
=
default_hub_server
.
search_module
(
module_name
)
text
=
"
\n
"
...
...
@@ -38,6 +49,7 @@ class SearchCommand(BaseCommand):
for
module_name
,
module_version
in
module_list
:
text
+=
" %-20s
\t\t
%s
\n
"
%
(
module_name
,
module_version
)
print
(
text
)
return
True
command
=
SearchCommand
.
instance
()
paddle_hub/commands/show.py
浏览文件 @
7d6054ba
...
...
@@ -16,10 +16,11 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
paddle_hub.tools.logger
import
logger
from
paddle_hub.commands.base_command
import
BaseCommand
from
paddle_hub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddle_hub.module.manager
import
default_module_manager
from
paddle_hub.module.module
import
Module
import
os
import
argparse
class
ShowCommand
(
BaseCommand
):
...
...
@@ -29,8 +30,18 @@ class ShowCommand(BaseCommand):
super
(
ShowCommand
,
self
).
__init__
(
name
)
self
.
show_in_help
=
True
self
.
description
=
"Show the specify module's info"
self
.
parser
=
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
self
.
__class__
.
__doc__
,
prog
=
'%s %s <module_name/module_dir>'
%
(
ENTRY
,
name
),
usage
=
'%(prog)s'
,
add_help
=
False
)
def
exec
(
self
,
argv
):
if
not
argv
:
print
(
"ERROR: Please specify a module
\n
"
)
self
.
help
()
return
False
module_name
=
argv
[
0
]
cwd
=
os
.
getcwd
()
...
...
@@ -38,7 +49,7 @@ class ShowCommand(BaseCommand):
module_dir
=
os
.
path
.
join
(
cwd
,
module_name
)
if
not
module_dir
else
module_dir
if
not
module_dir
or
not
os
.
path
.
exists
(
module_dir
):
return
return
True
module
=
Module
(
module_dir
=
module_dir
)
show_text
=
"Name:%s
\n
"
%
module
.
name
...
...
@@ -50,6 +61,7 @@ class ShowCommand(BaseCommand):
show_text
+=
"Location:%s
\n
"
%
module_dir
#TODO(wuzewu): add more signature info
print
(
show_text
)
return
True
command
=
ShowCommand
.
instance
()
paddle_hub/commands/uninstall.py
浏览文件 @
7d6054ba
...
...
@@ -16,9 +16,10 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
paddle_hub.tools.logger
import
logger
from
paddle_hub.commands.base_command
import
BaseCommand
from
paddle_hub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddle_hub.tools
import
utils
from
paddle_hub.module.manager
import
default_module_manager
import
argparse
class
UninstallCommand
(
BaseCommand
):
...
...
@@ -28,13 +29,22 @@ class UninstallCommand(BaseCommand):
super
(
UninstallCommand
,
self
).
__init__
(
name
)
self
.
show_in_help
=
True
self
.
description
=
"Uninstall the specify module from current environment."
self
.
parser
=
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
self
.
__class__
.
__doc__
,
prog
=
'%s %s <module_name>'
%
(
ENTRY
,
name
),
usage
=
'%(prog)s'
,
add_help
=
False
)
def
exec
(
self
,
argv
):
if
not
argv
:
print
(
"ERROR: Please specify a module
\n
"
)
self
.
help
()
return
False
module_name
=
argv
[
0
]
result
,
tips
=
default_module_manager
.
uninstall_module
(
module_name
=
module_name
)
print
(
tips
)
return
result
return
True
command
=
UninstallCommand
.
instance
()
paddle_hub/commands/version.py
浏览文件 @
7d6054ba
...
...
@@ -30,6 +30,7 @@ class VersionCommand(BaseCommand):
def
exec
(
self
,
argv
):
print
(
"hub %s"
%
version
.
hub_version
)
return
True
command
=
VersionCommand
.
instance
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录