Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
1997de19
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看板
未验证
提交
1997de19
编写于
9月 25, 2019
作者:
B
Bin Long
提交者:
GitHub
9月 25, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #174 from ShenYuhan/release/v1.2
delete stat
上级
2ece967d
372786d9
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
50 addition
and
58 deletion
+50
-58
paddlehub/commands/download.py
paddlehub/commands/download.py
+13
-3
paddlehub/commands/hub.py
paddlehub/commands/hub.py
+0
-1
paddlehub/commands/install.py
paddlehub/commands/install.py
+2
-1
paddlehub/commands/run.py
paddlehub/commands/run.py
+2
-1
paddlehub/commands/search.py
paddlehub/commands/search.py
+2
-1
paddlehub/common/hub_server.py
paddlehub/common/hub_server.py
+20
-8
paddlehub/common/server_config.py
paddlehub/common/server_config.py
+0
-7
paddlehub/common/srv_utils.py
paddlehub/common/srv_utils.py
+3
-29
paddlehub/module/manager.py
paddlehub/module/manager.py
+6
-6
paddlehub/module/module.py
paddlehub/module/module.py
+2
-1
未找到文件。
paddlehub/commands/download.py
浏览文件 @
1997de19
...
...
@@ -55,16 +55,26 @@ class DownloadCommand(BaseCommand):
self
.
args
=
self
.
parser
.
parse_args
(
argv
[
1
:])
self
.
args
.
type
=
self
.
check_type
(
self
.
args
.
type
)
extra
=
{
"command"
:
"download"
}
if
self
.
args
.
type
in
[
"Module"
,
"Model"
]:
search_result
=
default_hub_server
.
get_resource_url
(
mod_name
,
resource_type
=
self
.
args
.
type
,
version
=
mod_version
)
mod_name
,
resource_type
=
self
.
args
.
type
,
version
=
mod_version
,
extra
=
extra
)
else
:
search_result
=
default_hub_server
.
get_resource_url
(
mod_name
,
resource_type
=
"Module"
,
version
=
mod_version
)
mod_name
,
resource_type
=
"Module"
,
version
=
mod_version
,
extra
=
extra
)
self
.
args
.
type
=
"Module"
if
search_result
==
{}:
search_result
=
default_hub_server
.
get_resource_url
(
mod_name
,
resource_type
=
"Model"
,
version
=
mod_version
)
mod_name
,
resource_type
=
"Model"
,
version
=
mod_version
,
extra
=
extra
)
self
.
args
.
type
=
"Model"
url
=
search_result
.
get
(
'url'
,
None
)
except_md5_value
=
search_result
.
get
(
'md5'
,
None
)
...
...
paddlehub/commands/hub.py
浏览文件 @
1997de19
...
...
@@ -51,7 +51,6 @@ class HubCommand(BaseCommand):
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
:])
...
...
paddlehub/commands/install.py
浏览文件 @
1997de19
...
...
@@ -47,8 +47,9 @@ class InstallCommand(BaseCommand):
"=="
)[
1
]
module_name
=
module_name
if
"=="
not
in
module_name
else
module_name
.
split
(
"=="
)[
0
]
extra
=
{
"command"
:
"install"
}
result
,
tips
,
module_dir
=
default_module_manager
.
install_module
(
module_name
=
module_name
,
module_version
=
module_version
)
module_name
=
module_name
,
module_version
=
module_version
,
extra
=
extra
)
print
(
tips
)
return
True
...
...
paddlehub/commands/run.py
浏览文件 @
1997de19
...
...
@@ -62,8 +62,9 @@ class RunCommand(BaseCommand):
module_dir
=
(
module_name
,
None
)
else
:
print
(
"Install Module %s"
%
module_name
)
extra
=
{
"command"
:
"install"
}
result
,
tips
,
module_dir
=
default_module_manager
.
install_module
(
module_name
)
module_name
,
extra
=
extra
)
print
(
tips
)
if
not
result
:
return
None
...
...
paddlehub/commands/search.py
浏览文件 @
1997de19
...
...
@@ -43,8 +43,9 @@ class SearchCommand(BaseCommand):
argv
=
[
'.*'
]
resource_name
=
argv
[
0
]
extra
=
{
"command"
:
"search"
}
resource_list
=
default_hub_server
.
search_resource
(
resource_name
,
resource_type
=
"Module"
)
resource_name
,
resource_type
=
"Module"
,
extra
=
extra
)
if
utils
.
is_windows
():
placeholders
=
[
20
,
8
,
8
,
20
]
else
:
...
...
paddlehub/common/hub_server.py
浏览文件 @
1997de19
...
...
@@ -96,13 +96,17 @@ class HubServer(object):
return
False
return
True
def
search_resource
(
self
,
resource_key
,
resource_type
=
None
,
update
=
False
):
def
search_resource
(
self
,
resource_key
,
resource_type
=
None
,
update
=
False
,
extra
=
None
):
try
:
payload
=
{
'word'
:
resource_key
}
if
resource_type
:
payload
[
'type'
]
=
resource_type
api_url
=
srv_utils
.
uri_path
(
self
.
get_server_url
(),
'search'
)
r
=
srv_utils
.
hub_request
(
api_url
,
payload
)
r
=
srv_utils
.
hub_request
(
api_url
,
payload
,
extra
=
extra
)
if
r
[
'status'
]
==
0
and
len
(
r
[
'data'
])
>
0
:
return
[(
item
[
'name'
],
item
[
'type'
],
item
[
'version'
],
item
[
'summary'
])
for
item
in
r
[
'data'
]]
...
...
@@ -147,7 +151,8 @@ class HubServer(object):
resource_name
,
resource_type
=
None
,
version
=
None
,
update
=
False
):
update
=
False
,
extra
=
None
):
try
:
payload
=
{
'word'
:
resource_name
}
if
resource_type
:
...
...
@@ -155,7 +160,7 @@ class HubServer(object):
if
version
:
payload
[
'version'
]
=
version
api_url
=
srv_utils
.
uri_path
(
self
.
get_server_url
(),
'search'
)
r
=
srv_utils
.
hub_request
(
api_url
,
payload
)
r
=
srv_utils
.
hub_request
(
api_url
,
payload
,
extra
)
if
r
[
'status'
]
==
0
and
len
(
r
[
'data'
])
>
0
:
for
item
in
r
[
'data'
]:
if
resource_name
.
lower
()
==
item
[
'name'
].
lower
():
...
...
@@ -200,19 +205,26 @@ class HubServer(object):
return
{}
def
get_module_url
(
self
,
module_name
,
version
=
None
,
update
=
False
):
def
get_module_url
(
self
,
module_name
,
version
=
None
,
update
=
False
,
extra
=
None
):
return
self
.
get_resource_url
(
resource_name
=
module_name
,
resource_type
=
"Module"
,
version
=
version
,
update
=
update
)
update
=
update
,
extra
=
extra
)
def
get_model_url
(
self
,
module_name
,
version
=
None
,
update
=
False
):
def
get_model_url
(
self
,
module_name
,
version
=
None
,
update
=
False
,
extra
=
None
):
return
self
.
get_resource_url
(
resource_name
=
module_name
,
resource_type
=
"Model"
,
version
=
version
,
update
=
update
)
update
=
update
,
extra
=
extra
)
def
request
(
self
):
if
not
os
.
path
.
exists
(
hub
.
CACHE_HOME
):
...
...
paddlehub/common/server_config.py
浏览文件 @
1997de19
...
...
@@ -14,16 +14,9 @@
HUB_SERVERS
=
[
"http://paddlepaddle.org.cn/paddlehub"
]
STAT_SERVERS
=
[
"http://paddlepaddle.org.cn/paddlehub/stat"
,
"http://paddlepaddle.org.cn/paddlehub/stat"
]
default_server_config
=
{
"server_url"
:
HUB_SERVERS
,
"resource_storage_server_url"
:
"https://bj.bcebos.com/paddlehub-data/"
,
"debug"
:
False
,
"log_level"
:
"DEBUG"
}
default_stat_config
=
{
"server_list"
:
STAT_SERVERS
}
paddlehub/common/srv_utils.py
浏览文件 @
1997de19
...
...
@@ -17,38 +17,11 @@ import requests
import
time
import
paddle
import
socket
import
json
from
random
import
randint
,
seed
from
paddlehub
import
version
from
paddlehub.common.server_config
import
default_stat_config
def
get_stat_server
():
seed
(
int
(
time
.
time
()))
stat_env
=
os
.
environ
.
get
(
'HUB_SERVER_STAT_SRV'
)
if
stat_env
:
server_list
=
stat_env
.
split
(
';'
)
else
:
server_list
=
default_stat_config
[
'server_list'
]
return
server_list
[
randint
(
0
,
len
(
server_list
)
-
1
)]
def
hub_stat
(
argv
):
try
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
s
.
connect
((
'bj.bcebos.com'
,
80
))
ip_addr
=
s
.
getsockname
()[
0
]
params
=
{
'command'
:
' '
.
join
(
argv
),
'hub_version'
:
version
.
hub_version
,
'paddle_version'
:
paddle
.
__version__
,
'ip_addr'
:
ip_addr
}
stat_api
=
get_stat_server
()
r
=
requests
.
get
(
stat_api
,
params
=
params
,
timeout
=
0.5
)
except
:
pass
def
uri_path
(
server_url
,
api
):
...
...
@@ -63,8 +36,9 @@ def uri_path(server_url, api):
return
srv
def
hub_request
(
api
,
params
):
def
hub_request
(
api
,
params
,
extra
=
None
):
params
[
'hub_version'
]
=
version
.
hub_version
params
[
'paddle_version'
]
=
paddle
.
__version__
params
[
"extra"
]
=
json
.
dumps
(
extra
)
r
=
requests
.
get
(
api
,
params
)
return
r
.
json
()
paddlehub/module/manager.py
浏览文件 @
1997de19
...
...
@@ -75,7 +75,11 @@ class LocalModuleManager(object):
self
.
all_modules
(
update
=
update
)
return
self
.
modules_dict
.
get
(
module_name
,
None
)
def
install_module
(
self
,
module_name
,
module_version
=
None
,
upgrade
=
False
):
def
install_module
(
self
,
module_name
,
module_version
=
None
,
upgrade
=
False
,
extra
=
None
):
self
.
all_modules
(
update
=
True
)
module_info
=
self
.
modules_dict
.
get
(
module_name
,
None
)
if
module_info
:
...
...
@@ -84,13 +88,12 @@ class LocalModuleManager(object):
module_dir
=
self
.
modules_dict
[
module_name
][
0
]
module_tag
=
module_name
if
not
module_version
else
'%s-%s'
%
(
module_name
,
module_version
)
srv_utils
.
hub_stat
([
'installed'
,
module_tag
])
tips
=
"Module %s already installed in %s"
%
(
module_tag
,
module_dir
)
return
True
,
tips
,
self
.
modules_dict
[
module_name
]
search_result
=
hub
.
default_hub_server
.
get_module_url
(
module_name
,
version
=
module_version
)
module_name
,
version
=
module_version
,
extra
=
extra
)
name
=
search_result
.
get
(
'name'
,
None
)
url
=
search_result
.
get
(
'url'
,
None
)
md5_value
=
search_result
.
get
(
'md5'
,
None
)
...
...
@@ -102,7 +105,6 @@ class LocalModuleManager(object):
tips
+=
" with version %s"
%
module_version
module_tag
=
module_name
if
not
module_version
else
'%s-%s'
%
(
module_name
,
module_version
)
srv_utils
.
hub_stat
([
'install fail'
,
module_tag
])
return
False
,
tips
,
None
result
,
tips
,
module_zip_file
=
default_downloader
.
download_file
(
...
...
@@ -127,7 +129,6 @@ class LocalModuleManager(object):
shutil
.
move
(
module_dir
,
save_path
)
module_dir
=
save_path
tips
=
"Successfully installed %s"
%
module_name
srv_utils
.
hub_stat
([
'install'
,
module_name
,
url
])
if
installed_module_version
:
tips
+=
"-%s"
%
installed_module_version
return
True
,
tips
,
(
module_dir
,
installed_module_version
)
...
...
@@ -143,7 +144,6 @@ class LocalModuleManager(object):
1
]:
tips
=
"%s-%s is not installed"
%
(
module_name
,
module_version
)
return
True
,
tips
srv_utils
.
hub_stat
([
'uninstall'
,
module_name
])
tips
=
"Successfully uninstalled %s"
%
module_name
if
module_version
:
tips
+=
'-%s'
%
module_version
...
...
paddlehub/module/module.py
浏览文件 @
1997de19
...
...
@@ -150,8 +150,9 @@ class Module(object):
if
version
:
log_msg
+=
"-%s"
%
version
logger
.
info
(
log_msg
)
extra
=
{
"command"
:
"install"
}
result
,
tips
,
module_dir
=
default_module_manager
.
install_module
(
module_name
=
name
,
module_version
=
version
)
module_name
=
name
,
module_version
=
version
,
extra
=
extra
)
if
not
result
:
logger
.
error
(
tips
)
exit
(
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录