bare batch load functionality
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
al2.egg-info/
|
||||
__pycache__
|
||||
dist/
|
||||
|
||||
*.swp
|
0
al2/__init__.py
Normal file
0
al2/__init__.py
Normal file
38
al2/batch.py
Normal file
38
al2/batch.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import json
|
||||
import pathlib as pl
|
||||
|
||||
def load(batch_file):
|
||||
batch_file = pl.Path(batch_file).resolve()
|
||||
|
||||
with open(batch_file, "r") as bfile:
|
||||
batch_obj = json.loads(bfile.read())
|
||||
|
||||
batch_obj["base_path"] = batch_file.parent
|
||||
|
||||
return __load_batch_obj(batch_obj)
|
||||
|
||||
|
||||
def __load_batch_obj(batch_obj):
|
||||
paths = []
|
||||
|
||||
instance_dir = None
|
||||
|
||||
if "dir" in batch_obj:
|
||||
instance_dir = pl.Path(batch_obj["dir"])
|
||||
|
||||
if not instance_dir.is_absolute():
|
||||
instance_dir = pl.Path(batch_obj["base_path"], instance_dir)
|
||||
else:
|
||||
instance_dir = batch_obj["base_path"]
|
||||
|
||||
if "instances" in batch_obj:
|
||||
for instance in batch_obj["instances"]:
|
||||
paths.append(pl.Path(instance_dir, instance))
|
||||
|
||||
if "batches" in batch_obj:
|
||||
for batch in batch_obj["batches"]:
|
||||
batch["base_path"] = instance_dir
|
||||
|
||||
paths.extend(__load_batch_obj(batch))
|
||||
|
||||
return paths
|
Reference in New Issue
Block a user