Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
52cddc67
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
52cddc67
编写于
1月 23, 2019
作者:
C
Caio Carrara
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'clebergnu/asset_fetcher_name_and_hash'
Signed-off-by:
N
Caio Carrara
<
ccarrara@redhat.com
>
上级
2cebf57b
831d54fb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
20 deletion
+21
-20
avocado/utils/asset.py
avocado/utils/asset.py
+12
-11
selftests/unit/test_utils_asset.py
selftests/unit/test_utils_asset.py
+9
-9
未找到文件。
avocado/utils/asset.py
浏览文件 @
52cddc67
...
...
@@ -65,7 +65,7 @@ class Asset(object):
:param name: the asset filename. url is also supported
:param asset_hash: asset hash
:param algorithm: hash algorithm
:param locations: list of locations
fetch asset
from
:param locations: list of locations
where the asset can be fetched
from
:param cache_dirs: list of cache directories
:param expire: time in seconds for the asset to expire
"""
...
...
@@ -106,16 +106,17 @@ class Asset(object):
def
_get_relative_dir
(
self
,
parsed_url
):
"""
When an asset has a name and a hash, there's a clear intention
for it to be unique *by name*, overwriting it if the file is
corrupted or expired. These will be stored in the cache directory
indexed by name.
When an asset does not have a hash, they will be saved according
to their locations, so that multiple assets with the same file name,
but completely unrelated to each other, will still coexist.
When an asset name is not an URL, and it also has a hash,
there's a clear intention for it to be unique *by name*,
overwriting it if the file is corrupted or expired. These
will be stored in the cache directory indexed by name.
When an asset name is an URL, wether it has a hash or not, it
will be saved according to their locations, so that multiple
assets with the same file name, but completely unrelated to
each other, will still coexist.
"""
if
self
.
asset_hash
:
if
self
.
asset_hash
and
not
parsed_url
.
scheme
:
return
'by_name'
base_url
=
"%s://%s/%s"
%
(
parsed_url
.
scheme
,
parsed_url
.
netloc
,
...
...
@@ -171,6 +172,7 @@ class Asset(object):
for
item
in
self
.
locations
:
urls
.
append
(
item
)
cache_relative_dir
=
self
.
_get_relative_dir
(
parsed_url
)
for
url
in
urls
:
urlobj
=
urlparse
.
urlparse
(
url
)
if
urlobj
.
scheme
in
[
'http'
,
'https'
,
'ftp'
]:
...
...
@@ -180,7 +182,6 @@ class Asset(object):
else
:
raise
UnsupportedProtocolError
(
"Unsupported protocol"
": %s"
%
urlobj
.
scheme
)
cache_relative_dir
=
self
.
_get_relative_dir
(
urlobj
)
asset_file
=
os
.
path
.
join
(
cache_dir
,
cache_relative_dir
,
basename
)
dirname
=
os
.
path
.
dirname
(
asset_file
)
if
not
os
.
path
.
isdir
(
dirname
):
...
...
selftests/unit/test_utils_asset.py
浏览文件 @
52cddc67
...
...
@@ -25,27 +25,27 @@ class TestAsset(unittest.TestCase):
self
.
url
=
'file://%s'
%
self
.
localpath
self
.
cache_dir
=
tempfile
.
mkdtemp
(
dir
=
self
.
basedir
)
def
test_fetch_url
name
(
self
):
def
test_fetch_url
_cache_by_location
(
self
):
foo_tarball
=
asset
.
Asset
(
self
.
url
,
asset_hash
=
self
.
assethash
,
algorithm
=
'sha1'
,
locations
=
None
,
cache_dirs
=
[
self
.
cache_dir
],
expire
=
None
).
fetch
()
expected_
tarball
=
os
.
path
.
join
(
self
.
cache_dir
,
'by_name'
,
self
.
assetname
)
self
.
assert
Equal
(
foo_tarball
,
expected_tarball
)
expected_
location
=
os
.
path
.
join
(
self
.
cache_dir
,
'by_location'
)
self
.
assertTrue
(
foo_tarball
.
startswith
(
expected_location
)
)
self
.
assert
True
(
foo_tarball
.
endswith
(
self
.
assetname
)
)
def
test_fetch_
location
(
self
):
def
test_fetch_
name_cache_by_name
(
self
):
foo_tarball
=
asset
.
Asset
(
self
.
assetname
,
asset_hash
=
self
.
assethash
,
algorithm
=
'sha1'
,
locations
=
[
self
.
url
],
cache_dirs
=
[
self
.
cache_dir
],
expire
=
None
).
fetch
()
expected_
tarball
=
os
.
path
.
join
(
self
.
cache_dir
,
'by_name'
,
self
.
assetname
)
self
.
assertEqual
(
foo_tarball
,
expected_
tarball
)
expected_
location
=
os
.
path
.
join
(
self
.
cache_dir
,
'by_name'
,
self
.
assetname
)
self
.
assertEqual
(
foo_tarball
,
expected_
location
)
def
test_fetch_expire
(
self
):
foo_tarball
=
asset
.
Asset
(
self
.
assetname
,
...
...
@@ -98,7 +98,7 @@ class TestAsset(unittest.TestCase):
dirname
=
os
.
path
.
join
(
self
.
cache_dir
,
'by_name'
)
os
.
makedirs
(
dirname
)
with
FileLock
(
os
.
path
.
join
(
dirname
,
self
.
assetname
)):
a
=
asset
.
Asset
(
self
.
url
,
a
=
asset
.
Asset
(
self
.
assetname
,
asset_hash
=
self
.
assethash
,
algorithm
=
'sha1'
,
locations
=
None
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录