Skip to content

Commit

Permalink
check file before uploading to server (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenYuhan authored Dec 14, 2020
1 parent e6bda9c commit 53a31e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions visualdl/reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,28 @@
from visualdl.utils.string_util import decode_tag, encode_tag


def is_VDLRecord_file(path):
def is_VDLRecord_file(path, check=False):
"""Determine whether it is a VDL log file according to the file name.
File name of a VDL log file must contain `vdlrecords`.
Args:
path: File name to determine.
check: Check file is valid or not.
Returns:
True if the file is a VDL log file, otherwise false.
"""
return "vdlrecords" in path
if not "vdlrecords" in path:
return False
if check:
_reader = RecordReader(filepath=path)
meta_data = _reader.get_next()
record = record_pb2.Record()
record.ParseFromString(meta_data)
if 'meta_data_tag' != record.values[0].tag:
return False
return True


class LogReader(object):
Expand Down
3 changes: 2 additions & 1 deletion visualdl/server/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def get_vdl_log_file(logdirs):

walks_temp = {}
for run, tags in walks.items():
tags_temp = [tag for tag in tags if is_VDLRecord_file(tag)]
tags_temp = [tag for tag in tags if
is_VDLRecord_file(path=bfile.join(run, tag), check=True)]
tags_temp.sort(reverse=True)
if len(tags_temp) > 0:
walks_temp.update({run: tags_temp[0]})
Expand Down

0 comments on commit 53a31e3

Please sign in to comment.