Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
14755b3b
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看板
未验证
提交
14755b3b
编写于
12月 23, 2019
作者:
B
Bin Long
提交者:
GitHub
12月 23, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #272 from ShenYuhan/add_search_tip
add version match tips
上级
81dfda51
fa6f8d16
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
124 addition
and
3 deletion
+124
-3
paddlehub/commands/list.py
paddlehub/commands/list.py
+1
-1
paddlehub/commands/search.py
paddlehub/commands/search.py
+1
-1
paddlehub/commands/show.py
paddlehub/commands/show.py
+1
-1
paddlehub/common/cml_utils.py
paddlehub/common/cml_utils.py
+0
-0
paddlehub/common/hub_server.py
paddlehub/common/hub_server.py
+15
-0
paddlehub/common/utils.py
paddlehub/common/utils.py
+35
-0
paddlehub/module/manager.py
paddlehub/module/manager.py
+71
-0
未找到文件。
paddlehub/commands/list.py
浏览文件 @
14755b3b
...
@@ -21,7 +21,7 @@ from paddlehub.common import utils
...
@@ -21,7 +21,7 @@ from paddlehub.common import utils
from
paddlehub.common.downloader
import
default_downloader
from
paddlehub.common.downloader
import
default_downloader
from
paddlehub.module.manager
import
default_module_manager
from
paddlehub.module.manager
import
default_module_manager
from
paddlehub.commands.base_command
import
BaseCommand
from
paddlehub.commands.base_command
import
BaseCommand
from
paddlehub.comm
ands
.cml_utils
import
TablePrinter
from
paddlehub.comm
on
.cml_utils
import
TablePrinter
class
ListCommand
(
BaseCommand
):
class
ListCommand
(
BaseCommand
):
...
...
paddlehub/commands/search.py
浏览文件 @
14755b3b
...
@@ -22,7 +22,7 @@ import argparse
...
@@ -22,7 +22,7 @@ import argparse
from
paddlehub.common
import
utils
from
paddlehub.common
import
utils
from
paddlehub.common.hub_server
import
default_hub_server
from
paddlehub.common.hub_server
import
default_hub_server
from
paddlehub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddlehub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddlehub.comm
ands
.cml_utils
import
TablePrinter
from
paddlehub.comm
on
.cml_utils
import
TablePrinter
class
SearchCommand
(
BaseCommand
):
class
SearchCommand
(
BaseCommand
):
...
...
paddlehub/commands/show.py
浏览文件 @
14755b3b
...
@@ -22,7 +22,7 @@ import argparse
...
@@ -22,7 +22,7 @@ import argparse
from
paddlehub.common
import
utils
from
paddlehub.common
import
utils
from
paddlehub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddlehub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddlehub.comm
ands
.cml_utils
import
TablePrinter
from
paddlehub.comm
on
.cml_utils
import
TablePrinter
from
paddlehub.module.manager
import
default_module_manager
from
paddlehub.module.manager
import
default_module_manager
from
paddlehub.module.module
import
Module
from
paddlehub.module.module
import
Module
from
paddlehub.io.parser
import
yaml_parser
from
paddlehub.io.parser
import
yaml_parser
...
...
paddlehub/comm
ands
/cml_utils.py
→
paddlehub/comm
on
/cml_utils.py
浏览文件 @
14755b3b
文件已移动
paddlehub/common/hub_server.py
浏览文件 @
14755b3b
...
@@ -148,6 +148,21 @@ class HubServer(object):
...
@@ -148,6 +148,21 @@ class HubServer(object):
self
.
search_resource
(
self
.
search_resource
(
resource_key
=
module_key
,
resource_type
=
"Model"
,
update
=
update
)
resource_key
=
module_key
,
resource_type
=
"Model"
,
update
=
update
)
def
search_module_info
(
self
,
module_key
):
try
:
payload
=
{
'name'
:
module_key
}
api_url
=
srv_utils
.
uri_path
(
self
.
get_server_url
(),
'info'
)
r
=
srv_utils
.
hub_request
(
api_url
,
payload
)
if
r
[
'status'
]
==
0
and
len
(
r
[
'data'
])
>
0
:
return
[(
item
[
'raw_name'
],
item
[
'version'
],
item
[
'paddle_version'
],
item
[
"hub_version"
])
for
item
in
r
[
'data'
][
"info"
]]
except
:
if
self
.
config
.
get
(
'debug'
,
False
):
raise
else
:
pass
def
get_resource_url
(
self
,
def
get_resource_url
(
self
,
resource_name
,
resource_name
,
resource_type
=
None
,
resource_type
=
None
,
...
...
paddlehub/common/utils.py
浏览文件 @
14755b3b
...
@@ -257,3 +257,38 @@ def sys_stdout_encoding():
...
@@ -257,3 +257,38 @@ def sys_stdout_encoding():
if
encoding
is
None
:
if
encoding
is
None
:
encoding
=
get_platform_default_encoding
()
encoding
=
get_platform_default_encoding
()
return
encoding
return
encoding
def
version_sum
(
version
):
"""
get sum(version), eg: version_sum(1.4.5) = 1*100*100*100 + 4*100*100 + 5*100
:param version: string("1.3.6")
:return:
"""
sum
=
0
version_list
=
version
.
split
(
"."
)
for
i
in
version_list
:
sum
=
(
sum
+
int
(
i
))
*
100
return
sum
def
sort_version_key
(
version_a
,
version_b
):
if
version_sum
(
version_a
[
1
])
>
version_sum
(
version_b
[
1
]):
return
-
1
elif
version_sum
(
version_a
[
1
])
==
version_sum
(
version_b
[
1
]):
return
0
else
:
return
1
def
strflist_version
(
version_list
):
version_list
=
version_list
[
1
:
-
1
].
split
(
","
)
result
=
""
if
version_list
[
0
]
!=
"-1.0.0"
:
result
=
">"
+
version_list
[
0
]
if
version_list
[
1
]
!=
"99.0.0"
:
if
result
!=
""
:
result
=
result
+
", "
+
"<"
+
version_list
[
1
]
else
:
result
=
"<"
+
version_list
[
1
]
return
result
if
result
!=
""
else
"-"
paddlehub/module/manager.py
浏览文件 @
14755b3b
...
@@ -19,6 +19,8 @@ from __future__ import print_function
...
@@ -19,6 +19,8 @@ from __future__ import print_function
import
os
import
os
import
shutil
import
shutil
from
functools
import
cmp_to_key
import
tarfile
import
tarfile
from
paddlehub.common
import
utils
from
paddlehub.common
import
utils
...
@@ -26,6 +28,7 @@ from paddlehub.common import srv_utils
...
@@ -26,6 +28,7 @@ from paddlehub.common import srv_utils
from
paddlehub.common.downloader
import
default_downloader
from
paddlehub.common.downloader
import
default_downloader
from
paddlehub.common.hub_server
import
default_hub_server
from
paddlehub.common.hub_server
import
default_hub_server
from
paddlehub.common.dir
import
MODULE_HOME
from
paddlehub.common.dir
import
MODULE_HOME
from
paddlehub.common.cml_utils
import
TablePrinter
from
paddlehub.module
import
module_desc_pb2
from
paddlehub.module
import
module_desc_pb2
import
paddlehub
as
hub
import
paddlehub
as
hub
from
paddlehub.common.logger
import
logger
from
paddlehub.common.logger
import
logger
...
@@ -155,11 +158,79 @@ class LocalModuleManager(object):
...
@@ -155,11 +158,79 @@ class LocalModuleManager(object):
module_dir
)
module_dir
)
return
True
,
tips
,
self
.
modules_dict
[
module_name
]
return
True
,
tips
,
self
.
modules_dict
[
module_name
]
search_result
=
hub
.
default_hub_server
.
get_module_url
(
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
)
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
):
if
default_hub_server
.
_server_check
()
is
False
:
tips
=
"Request Hub-Server unsuccessfully, please check your network."
return
False
,
tips
,
None
module_versions_info
=
default_hub_server
.
search_module_info
(
module_name
)
if
module_versions_info
is
not
None
and
len
(
module_versions_info
)
>
0
:
if
utils
.
is_windows
():
placeholders
=
[
20
,
8
,
14
,
14
]
else
:
placeholders
=
[
30
,
8
,
16
,
16
]
tp
=
TablePrinter
(
titles
=
[
"ResourceName"
,
"Version"
,
"PaddlePaddle"
,
"PaddleHub"
],
placeholders
=
placeholders
)
module_versions_info
.
sort
(
key
=
cmp_to_key
(
utils
.
sort_version_key
))
for
resource_name
,
resource_version
,
paddle_version
,
\
hub_version
in
module_versions_info
:
colors
=
[
"yellow"
,
None
,
None
,
None
]
tp
.
add_line
(
contents
=
[
resource_name
,
resource_version
,
utils
.
strflist_version
(
paddle_version
),
utils
.
strflist_version
(
hub_version
)
],
colors
=
colors
)
tips
=
"The version of PaddlePaddle or PaddleHub "
\
"can not match module, please upgrade your "
\
"PaddlePaddle or PaddleHub according to the form "
\
"below."
+
tp
.
get_text
()
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
(
url
=
url
,
save_path
=
hub
.
CACHE_HOME
,
save_name
=
module_name
,
replace
=
True
,
print_progress
=
True
)
result
,
tips
,
module_dir
=
default_downloader
.
uncompress
(
file
=
module_zip_file
,
dirname
=
MODULE_HOME
,
delete_file
=
True
,
print_progress
=
True
)
if
module_dir
:
with
open
(
os
.
path
.
join
(
MODULE_HOME
,
module_dir
,
"md5.txt"
),
"w"
)
as
fp
:
fp
.
write
(
md5_value
)
if
md5_value
:
if
md5_value
:
with
open
(
with
open
(
os
.
path
.
join
(
MODULE_HOME
,
module_dir
,
"md5.txt"
),
os
.
path
.
join
(
MODULE_HOME
,
module_dir
,
"md5.txt"
),
"w"
)
as
fp
:
"w"
)
as
fp
:
fp
.
write
(
md5_value
)
fp
.
write
(
md5_value
)
save_path
=
os
.
path
.
join
(
MODULE_HOME
,
module_name
)
save_path
=
os
.
path
.
join
(
MODULE_HOME
,
module_name
)
if
os
.
path
.
exists
(
save_path
):
if
os
.
path
.
exists
(
save_path
):
shutil
.
move
(
save_path
)
shutil
.
move
(
save_path
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录