Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
bcedab22
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看板
提交
bcedab22
编写于
3月 21, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
do not print tips in downloader
上级
d15bd206
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
20 deletion
+32
-20
paddle_hub/commands/download.py
paddle_hub/commands/download.py
+4
-2
paddle_hub/hub_server.py
paddle_hub/hub_server.py
+3
-1
paddle_hub/tools/downloader.py
paddle_hub/tools/downloader.py
+25
-17
未找到文件。
paddle_hub/commands/download.py
浏览文件 @
bcedab22
...
...
@@ -59,11 +59,13 @@ class DownloadCommand(BaseCommand):
self
.
print_args
()
if
self
.
args
.
uncompress
:
default_downloader
.
download_file_and_uncompress
(
result
,
tips
,
file
=
default_downloader
.
download_file_and_uncompress
(
url
=
url
,
save_path
=
self
.
args
.
output_path
)
else
:
default_downloader
.
download_file
(
result
,
tips
,
file
=
default_downloader
.
download_file
(
url
=
url
,
save_path
=
self
.
args
.
output_path
)
print
(
tips
)
return
result
command
=
DownloadCommand
.
instance
()
paddle_hub/hub_server.py
浏览文件 @
bcedab22
...
...
@@ -74,8 +74,10 @@ class HubServer:
def
request
(
self
):
file_url
=
self
.
server_url
+
MODULE_LIST_FILE
self
.
module_list_file
=
default_downloader
.
download_file
(
result
,
tips
,
self
.
module_list_file
=
default_downloader
.
download_file
(
file_url
,
save_path
=
hub
.
CACHE_HOME
)
if
not
result
:
return
False
self
.
module_list_file
=
csv_reader
.
read
(
self
.
module_list_file
)
return
True
...
...
paddle_hub/tools/downloader.py
浏览文件 @
bcedab22
...
...
@@ -41,7 +41,12 @@ def md5file(fname):
class
Downloader
:
def
download_file
(
self
,
url
,
save_path
,
save_name
=
None
,
retry_limit
=
3
):
def
download_file
(
self
,
url
,
save_path
,
save_name
=
None
,
retry_limit
=
3
,
print_progress
=
False
):
if
not
os
.
path
.
exists
(
save_path
):
utils
.
mkdir
(
save_path
)
save_name
=
url
.
split
(
'/'
)[
-
1
]
if
save_name
is
None
else
save_name
...
...
@@ -53,11 +58,9 @@ class Downloader:
if
retry_times
<
retry_limit
:
retry_times
+=
1
else
:
raise
RuntimeError
(
"Cannot download {0} within retry limit {1}"
.
format
(
url
,
retry_limit
))
logger
.
info
(
"Cache file %s not found, downloading %s"
%
(
file_name
,
url
))
tips
=
"Cannot download {0} within retry limit {1}"
.
format
(
url
,
retry_limit
)
return
False
,
tips
,
None
r
=
requests
.
get
(
url
,
stream
=
True
)
total_length
=
r
.
headers
.
get
(
'content-length'
)
...
...
@@ -72,13 +75,14 @@ class Downloader:
for
data
in
r
.
iter_content
(
chunk_size
=
4096
):
dl
+=
len
(
data
)
f
.
write
(
data
)
done
=
int
(
50
*
dl
/
total_length
)
sys
.
stdout
.
write
(
"
\r
[%s%s]"
%
(
'='
*
done
,
' '
*
(
50
-
done
)))
sys
.
stdout
.
flush
()
if
print_progress
:
done
=
int
(
50
*
dl
/
total_length
)
sys
.
stdout
.
write
(
"
\r
[%s%s]"
%
(
'='
*
done
,
' '
*
(
50
-
done
)))
sys
.
stdout
.
flush
()
logger
.
info
(
"file %s download completed!"
%
(
file_name
)
)
return
file_name
tips
=
"file %s download completed!"
%
(
file_name
)
return
True
,
tips
,
file_name
def
uncompress
(
self
,
file
,
dirname
=
None
,
delete_file
=
False
):
dirname
=
os
.
path
.
dirname
(
file
)
if
dirname
is
None
else
dirname
...
...
@@ -91,7 +95,7 @@ class Downloader:
if
delete_file
:
os
.
remove
(
file
)
return
module_dir
return
True
,
"file %s uncompress completed!"
%
file
,
module_dir
def
download_file_and_uncompress
(
self
,
url
,
...
...
@@ -99,17 +103,21 @@ class Downloader:
save_name
=
None
,
retry_limit
=
3
,
delete_file
=
True
):
file
=
self
.
download_file
(
result
,
tips_1
,
file
=
self
.
download_file
(
url
=
url
,
save_path
=
save_path
,
save_name
=
save_name
,
retry_limit
=
retry_limit
)
file
=
self
.
uncompress
(
file
,
delete_file
=
delete_file
)
if
not
result
:
return
result
,
tips_1
,
file
result
,
tips_2
,
file
=
self
.
uncompress
(
file
,
delete_file
=
delete_file
)
if
not
result
:
return
result
,
tips_2
,
file
if
save_name
:
save_name
=
os
.
path
.
join
(
save_path
,
save_name
)
shutil
.
move
(
file
,
save_name
)
return
save_name
return
file
return
result
,
"%s
\n
%s"
%
(
tips_1
,
tips_2
),
save_name
return
result
,
"%s
\n
%s"
%
(
tips_1
,
tips_2
),
file
default_downloader
=
Downloader
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录