Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
8a91c860
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看板
提交
8a91c860
编写于
11月 07, 2019
作者:
S
shenyuhan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add check_server()
上级
fff66a11
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
18 deletion
+47
-18
paddlehub/commands/download.py
paddlehub/commands/download.py
+7
-4
paddlehub/commands/search.py
paddlehub/commands/search.py
+5
-0
paddlehub/common/hub_server.py
paddlehub/common/hub_server.py
+26
-9
paddlehub/module/manager.py
paddlehub/module/manager.py
+9
-5
未找到文件。
paddlehub/commands/download.py
浏览文件 @
8a91c860
...
...
@@ -79,10 +79,13 @@ class DownloadCommand(BaseCommand):
url
=
search_result
.
get
(
'url'
,
None
)
except_md5_value
=
search_result
.
get
(
'md5'
,
None
)
if
not
url
:
tips
=
"PaddleHub can't find model/module named %s"
%
mod_name
if
mod_version
:
tips
+=
" with version %s"
%
mod_version
tips
+=
". Please use the 'hub search' command to find the correct model/module name."
if
default_hub_server
.
_server_check
()
is
False
:
tips
=
"Request Hub-Server unsuccessfully, please check your network."
else
:
tips
=
"PaddleHub can't find model/module named %s"
%
mod_name
if
mod_version
:
tips
+=
" with version %s"
%
mod_version
tips
+=
". Please use the 'hub search' command to find the correct model/module name."
print
(
tips
)
return
True
...
...
paddlehub/commands/search.py
浏览文件 @
8a91c860
...
...
@@ -53,6 +53,11 @@ class SearchCommand(BaseCommand):
tp
=
TablePrinter
(
titles
=
[
"ResourceName"
,
"Type"
,
"Version"
,
"Summary"
],
placeholders
=
placeholders
)
if
len
(
resource_list
)
==
0
:
if
default_hub_server
.
server_check
()
is
False
:
print
(
"Request Hub-Server unsuccessfully, please check your network."
)
for
resource_name
,
resource_type
,
resource_version
,
resource_summary
in
resource_list
:
if
resource_type
==
"Module"
:
colors
=
[
"yellow"
,
None
,
None
,
None
]
...
...
paddlehub/common/hub_server.py
浏览文件 @
8a91c860
...
...
@@ -31,7 +31,7 @@ from paddlehub.common.downloader import default_downloader
from
paddlehub.common.server_config
import
default_server_config
from
paddlehub.io.parser
import
yaml_parser
from
paddlehub.common.lock
import
lock
import
paddlehub
as
hub
from
paddlehub.common.dir
import
CONF_HOME
,
CACHE_HOME
RESOURCE_LIST_FILE
=
"resource_list_file.yml"
CACHE_TIME
=
60
*
10
...
...
@@ -40,9 +40,9 @@ CACHE_TIME = 60 * 10
class
HubServer
(
object
):
def
__init__
(
self
,
config_file_path
=
None
):
if
not
config_file_path
:
config_file_path
=
os
.
path
.
join
(
hub
.
CONF_HOME
,
'config.json'
)
if
not
os
.
path
.
exists
(
hub
.
CONF_HOME
):
utils
.
mkdir
(
hub
.
CONF_HOME
)
config_file_path
=
os
.
path
.
join
(
CONF_HOME
,
'config.json'
)
if
not
os
.
path
.
exists
(
CONF_HOME
):
utils
.
mkdir
(
CONF_HOME
)
if
not
os
.
path
.
exists
(
config_file_path
):
with
open
(
config_file_path
,
'w+'
)
as
fp
:
lock
.
flock
(
fp
,
lock
.
LOCK_EX
)
...
...
@@ -69,7 +69,7 @@ class HubServer(object):
return
self
.
server_url
[
random
.
randint
(
0
,
len
(
self
.
server_url
)
-
1
)]
def
resource_list_file_path
(
self
):
return
os
.
path
.
join
(
hub
.
CACHE_HOME
,
RESOURCE_LIST_FILE
)
return
os
.
path
.
join
(
CACHE_HOME
,
RESOURCE_LIST_FILE
)
def
_load_resource_list_file_if_valid
(
self
):
self
.
resource_list_file
=
{}
...
...
@@ -106,6 +106,7 @@ class HubServer(object):
if
resource_type
:
payload
[
'type'
]
=
resource_type
api_url
=
srv_utils
.
uri_path
(
self
.
get_server_url
(),
'search'
)
print
(
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'
],
...
...
@@ -227,12 +228,12 @@ class HubServer(object):
extra
=
extra
)
def
request
(
self
):
if
not
os
.
path
.
exists
(
hub
.
CACHE_HOME
):
utils
.
mkdir
(
hub
.
CACHE_HOME
)
if
not
os
.
path
.
exists
(
CACHE_HOME
):
utils
.
mkdir
(
CACHE_HOME
)
try
:
r
=
requests
.
get
(
self
.
get_server_url
()
+
'/'
+
'search'
)
data
=
json
.
loads
(
r
.
text
)
cache_path
=
os
.
path
.
join
(
hub
.
CACHE_HOME
,
RESOURCE_LIST_FILE
)
cache_path
=
os
.
path
.
join
(
CACHE_HOME
,
RESOURCE_LIST_FILE
)
with
open
(
cache_path
,
'w+'
)
as
fp
:
yaml
.
safe_dump
({
'resource_list'
:
data
[
'data'
]},
fp
)
return
True
...
...
@@ -245,12 +246,28 @@ class HubServer(object):
file_url
=
self
.
config
[
'resource_storage_server_url'
]
+
RESOURCE_LIST_FILE
result
,
tips
,
self
.
resource_list_file
=
default_downloader
.
download_file
(
file_url
,
save_path
=
hub
.
CACHE_HOME
,
replace
=
True
)
file_url
,
save_path
=
CACHE_HOME
,
replace
=
True
)
if
not
result
:
return
False
except
:
return
False
return
True
def
_server_check
(
self
):
try
:
r
=
requests
.
get
(
self
.
get_server_url
()
+
'/search'
)
if
r
.
status_code
==
200
:
return
True
else
:
return
False
except
:
return
False
def
server_check
(
self
):
if
self
.
_server_check
()
is
True
:
print
(
"Request Hub-Server successfully."
)
else
:
print
(
"Request Hub-Server unsuccessfully."
)
default_hub_server
=
HubServer
()
paddlehub/module/manager.py
浏览文件 @
8a91c860
...
...
@@ -23,6 +23,7 @@ import shutil
from
paddlehub.common
import
utils
from
paddlehub.common
import
srv_utils
from
paddlehub.common.downloader
import
default_downloader
from
paddlehub.common.hub_server
import
default_hub_server
from
paddlehub.common.dir
import
MODULE_HOME
from
paddlehub.module
import
module_desc_pb2
import
paddlehub
as
hub
...
...
@@ -100,11 +101,14 @@ class LocalModuleManager(object):
installed_module_version
=
search_result
.
get
(
'version'
,
None
)
if
not
url
or
(
module_version
is
not
None
and
installed_module_version
!=
module_version
)
or
(
name
!=
module_name
):
tips
=
"Can't find module %s"
%
module_name
if
module_version
:
tips
+=
" with version %s"
%
module_version
module_tag
=
module_name
if
not
module_version
else
'%s-%s'
%
(
module_name
,
module_version
)
if
default_hub_server
.
_server_check
()
is
False
:
tips
=
"Request Hub-Server unsuccessfully, please check your network."
else
:
tips
=
"Can't find module %s"
%
module_name
if
module_version
:
tips
+=
" with version %s"
%
module_version
module_tag
=
module_name
if
not
module_version
else
'%s-%s'
%
(
module_name
,
module_version
)
return
False
,
tips
,
None
result
,
tips
,
module_zip_file
=
default_downloader
.
download_file
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录