Rewrite dict keywords checking
@@ -38,8 +38,7 @@ def get_file(ftuple):
def parse_datafiles(datasearch, datasetslist):
for dataset in datasetslist:
- if datasearch == dataset["name"] or datasearch == "":
- if dataset["files"]:
+ if (datasearch == dataset["name"] or datasearch == "") and dataset.get("files", ""):
for ds in dataset["files"]:
label = ds["path"]
data = {"url": ds["url"], "path": ds["path"]}
@@ -51,8 +50,7 @@ def parse_datafiles(datasearch, datasetslist):
def parse_imagefiles(notebookslist):
for item in notebookslist:
record = notebookslist[item]
- if "images" in record:
- if record["images"]:
+ if record.get("images", ""):
for im in record["images"]:
label = "im: " + im
path = "images/" + im + ".png"
@@ -155,8 +153,7 @@ class ComputePlan:
else:
for item in self.listfiles:
record = self.listfiles[item]
- if "datasets" in record:
- if record["datasets"] != "":
+ if record.get("datasets", ""):
for ds in record["datasets"]:
datafound.update(
dict(parse_datafiles(ds, datasets))
@@ -189,12 +186,10 @@ class ComputePlan:
self.listfiles[label]["path"] = path
self.listfiles[label]["datasets"] = []
self.listfiles[label]["images"] = []
- if "datasets" in nb:
- if nb["datasets"]:
+ if nb.get("datasets", ""):
for ds in nb["datasets"]:
self.listfiles[label]["datasets"].append(ds)
- if "images" in nb:
- if nb["images"]:
+ if nb.get("images", ""):
for im in nb["images"]:
self.listfiles[label]["images"].append(im)
@@ -219,8 +214,7 @@ class ComputePlan:
self.listfiles[label]["url"] = sc["url"]
self.listfiles[label]["path"] = path
self.listfiles[label]["datasets"] = []
- if "datasets" in sc:
- if sc["datasets"]:
+ if sc.get("datasets", ""):
for ds in sc["datasets"]:
self.listfiles[label]["datasets"].append(ds)
