Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindinsight
提交
edb6dc56
M
mindinsight
项目概览
MindSpore
/
mindinsight
通知
8
Star
4
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindinsight
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
edb6dc56
编写于
4月 02, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
4月 02, 2020
浏览文件
操作
浏览文件
下载
差异文件
!11 Reduce cyclomatic complexity of list_summary_directories
Merge pull request !11 from luopengting/summary_watcher
上级
ffe69c96
57dd4595
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
65 addition
and
21 deletion
+65
-21
mindinsight/datavisual/common/exceptions.py
mindinsight/datavisual/common/exceptions.py
+9
-0
mindinsight/datavisual/data_transform/summary_watcher.py
mindinsight/datavisual/data_transform/summary_watcher.py
+42
-21
mindinsight/datavisual/utils/tools.py
mindinsight/datavisual/utils/tools.py
+14
-0
未找到文件。
mindinsight/datavisual/common/exceptions.py
浏览文件 @
edb6dc56
...
@@ -81,3 +81,12 @@ class NodeNotInGraphError(MindInsightException):
...
@@ -81,3 +81,12 @@ class NodeNotInGraphError(MindInsightException):
super
(
NodeNotInGraphError
,
self
).
__init__
(
DataVisualErrors
.
NODE_NOT_IN_GRAPH_ERROR
,
super
(
NodeNotInGraphError
,
self
).
__init__
(
DataVisualErrors
.
NODE_NOT_IN_GRAPH_ERROR
,
error_msg
,
error_msg
,
http_code
=
400
)
http_code
=
400
)
class
MaxCountExceededException
(
MindInsightException
):
"""Count is out of limit."""
def
__init__
(
self
):
error_msg
=
"Count is out of limit."
super
(
MaxCountExceededException
,
self
).
__init__
(
DataVisualErrors
.
NODE_NOT_IN_GRAPH_ERROR
,
error_msg
,
http_code
=
400
)
mindinsight/datavisual/data_transform/summary_watcher.py
浏览文件 @
edb6dc56
...
@@ -21,6 +21,8 @@ from pathlib import Path
...
@@ -21,6 +21,8 @@ from pathlib import Path
from
mindinsight.datavisual.common.log
import
logger
from
mindinsight.datavisual.common.log
import
logger
from
mindinsight.datavisual.common.validation
import
Validation
from
mindinsight.datavisual.common.validation
import
Validation
from
mindinsight.datavisual.utils.tools
import
Counter
from
mindinsight.utils.exceptions
import
ParamValueError
from
mindinsight.utils.exceptions
import
FileSystemPermissionError
from
mindinsight.utils.exceptions
import
FileSystemPermissionError
...
@@ -42,6 +44,7 @@ class SummaryWatcher:
...
@@ -42,6 +44,7 @@ class SummaryWatcher:
Args:
Args:
summary_base_dir (str): Path of summary base directory.
summary_base_dir (str): Path of summary base directory.
overall (bool): Limit the total num of scanning if overall is False.
Returns:
Returns:
list, list of summary directory info, each of which including the following attributes.
list, list of summary directory info, each of which including the following attributes.
...
@@ -67,7 +70,11 @@ class SummaryWatcher:
...
@@ -67,7 +70,11 @@ class SummaryWatcher:
return
[]
return
[]
summary_dict
=
{}
summary_dict
=
{}
scan_count
=
0
if
not
overall
:
counter
=
Counter
(
max_count
=
self
.
MAX_SCAN_COUNT
)
else
:
counter
=
Counter
()
try
:
try
:
entries
=
os
.
scandir
(
summary_base_dir
)
entries
=
os
.
scandir
(
summary_base_dir
)
...
@@ -78,6 +85,12 @@ class SummaryWatcher:
...
@@ -78,6 +85,12 @@ class SummaryWatcher:
for
entry
in
entries
:
for
entry
in
entries
:
if
len
(
summary_dict
)
==
self
.
MAX_SUMMARY_DIR_COUNT
:
if
len
(
summary_dict
)
==
self
.
MAX_SUMMARY_DIR_COUNT
:
break
break
try
:
counter
.
add
()
except
ParamValueError
:
logger
.
info
(
'Stop further scanning due to overall is False and '
'number of scanned files exceeds upper limit.'
)
break
relative_path
=
os
.
path
.
join
(
'.'
,
''
)
relative_path
=
os
.
path
.
join
(
'.'
,
''
)
if
entry
.
is_symlink
():
if
entry
.
is_symlink
():
pass
pass
...
@@ -85,30 +98,12 @@ class SummaryWatcher:
...
@@ -85,30 +98,12 @@ class SummaryWatcher:
self
.
_update_summary_dict
(
summary_dict
,
relative_path
,
entry
)
self
.
_update_summary_dict
(
summary_dict
,
relative_path
,
entry
)
elif
entry
.
is_dir
():
elif
entry
.
is_dir
():
full_path
=
os
.
path
.
realpath
(
os
.
path
.
join
(
summary_base_dir
,
entry
.
name
))
full_path
=
os
.
path
.
realpath
(
os
.
path
.
join
(
summary_base_dir
,
entry
.
name
))
try
:
try
:
subdir_entries
=
os
.
scandir
(
full_path
)
subdir_entries
=
os
.
scandir
(
full_path
)
except
PermissionError
:
except
PermissionError
:
logger
.
warning
(
'Path of %s under summary base directory is not accessible.'
,
entry
.
name
)
logger
.
warning
(
'Path of %s under summary base directory is not accessible.'
,
entry
.
name
)
else
:
continue
for
subdir_entry
in
subdir_entries
:
self
.
_scan_subdir_entries
(
summary_dict
,
subdir_entries
,
entry
.
name
,
counter
)
if
len
(
summary_dict
)
==
self
.
MAX_SUMMARY_DIR_COUNT
:
break
subdir_relative_path
=
os
.
path
.
join
(
'.'
,
entry
.
name
)
if
subdir_entry
.
is_symlink
():
pass
elif
subdir_entry
.
is_file
():
self
.
_update_summary_dict
(
summary_dict
,
subdir_relative_path
,
subdir_entry
)
scan_count
+=
1
if
not
overall
and
scan_count
>=
self
.
MAX_SCAN_COUNT
:
break
scan_count
+=
1
if
not
overall
and
scan_count
>=
self
.
MAX_SCAN_COUNT
:
logger
.
info
(
'Stop further scanning due to overall is False and '
'number of scanned files exceeds upper limit.'
)
break
directories
=
[{
directories
=
[{
'relative_path'
:
key
,
'relative_path'
:
key
,
...
@@ -121,6 +116,32 @@ class SummaryWatcher:
...
@@ -121,6 +116,32 @@ class SummaryWatcher:
return
directories
return
directories
def
_scan_subdir_entries
(
self
,
summary_dict
,
subdir_entries
,
entry_name
,
counter
):
"""
Scan subdir entries.
Args:
summary_dict (dict): Temporary data structure to hold summary directory info.
subdir_entries(DirEntry): Directory entry instance.
entry_name (str): Name of entry.
counter (Counter): An instance of CountLimiter.
"""
for
subdir_entry
in
subdir_entries
:
if
len
(
summary_dict
)
==
self
.
MAX_SUMMARY_DIR_COUNT
:
break
try
:
counter
.
add
()
except
ParamValueError
:
logger
.
info
(
'Stop further scanning due to overall is False and '
'number of scanned files exceeds upper limit.'
)
break
subdir_relative_path
=
os
.
path
.
join
(
'.'
,
entry_name
)
if
subdir_entry
.
is_symlink
():
pass
elif
subdir_entry
.
is_file
():
self
.
_update_summary_dict
(
summary_dict
,
subdir_relative_path
,
subdir_entry
)
def
_contains_null_byte
(
self
,
**
kwargs
):
def
_contains_null_byte
(
self
,
**
kwargs
):
"""
"""
Check if arg contains null byte.
Check if arg contains null byte.
...
...
mindinsight/datavisual/utils/tools.py
浏览文件 @
edb6dc56
...
@@ -20,6 +20,7 @@ import os
...
@@ -20,6 +20,7 @@ import os
from
numbers
import
Number
from
numbers
import
Number
from
urllib.parse
import
unquote
from
urllib.parse
import
unquote
from
mindinsight.datavisual.common.exceptions
import
MaxCountExceededException
from
mindinsight.utils
import
exceptions
from
mindinsight.utils
import
exceptions
_IMG_EXT_TO_MIMETYPE
=
{
_IMG_EXT_TO_MIMETYPE
=
{
...
@@ -153,3 +154,16 @@ def if_nan_inf_to_none(name, value):
...
@@ -153,3 +154,16 @@ def if_nan_inf_to_none(name, value):
if
math
.
isnan
(
value
)
or
math
.
isinf
(
value
):
if
math
.
isnan
(
value
)
or
math
.
isinf
(
value
):
value
=
None
value
=
None
return
value
return
value
class
Counter
:
"""Count accumulator with limit checking."""
def
__init__
(
self
,
max_count
=
None
,
init_count
=
0
):
self
.
_count
=
init_count
self
.
_max_count
=
max_count
def
add
(
self
,
value
=
1
):
"""Add value."""
if
self
.
_max_count
is
not
None
and
self
.
_count
+
value
>
self
.
_max_count
:
raise
MaxCountExceededException
()
self
.
_count
+=
value
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录