Commit 73ace0a6 authored by Mario Hock's avatar Mario Hock

cnl_ls: Ignore non-cnl-files (e.g., README.txt)

parent d88a4c23
......@@ -92,14 +92,18 @@ def read_header(f):
return header
class CNLParser:
class WrongFileFormat_Exception(Exception):
pass
def __init__(self, filename):
self.filename = filename
with open( self.filename ) as in_file:
## Check file format version.
assert( in_file.readline() == "%% CPUnetLOGv1\n" )
if ( not in_file.readline() == "%% CPUnetLOGv1\n" ):
raise self.WrongFileFormat_Exception()
## Read JSON header.
self.header = read_header(in_file)
......
......@@ -125,7 +125,12 @@ if __name__ == "__main__":
## Parse files and store them in a dict (of lists) according to their hostname.
for filename in filenames:
cnl_file = CNLParser(filename)
try:
cnl_file = CNLParser(filename)
except CNLParser.WrongFileFormat_Exception:
print( "Skipping: {}".format(filename) )
continue
hostname = cnl_file.get_hostname()
cnl_files[hostname].append( cnl_file )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment