You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
937 B

  1. import json
  2. import pathlib as pl
  3. def load(batch_file):
  4. batch_file = pl.Path(batch_file).resolve()
  5. with open(batch_file, "r") as bfile:
  6. batch_obj = json.loads(bfile.read())
  7. batch_obj["base_path"] = batch_file.parent
  8. return __load_batch_obj(batch_obj)
  9. def __load_batch_obj(batch_obj):
  10. paths = []
  11. instance_dir = None
  12. if "dir" in batch_obj:
  13. instance_dir = pl.Path(batch_obj["dir"])
  14. if not instance_dir.is_absolute():
  15. instance_dir = pl.Path(batch_obj["base_path"], instance_dir)
  16. else:
  17. instance_dir = batch_obj["base_path"]
  18. if "instances" in batch_obj:
  19. for instance in batch_obj["instances"]:
  20. paths.append(pl.Path(instance_dir, instance))
  21. if "batches" in batch_obj:
  22. for batch in batch_obj["batches"]:
  23. batch["base_path"] = instance_dir
  24. paths.extend(__load_batch_obj(batch))
  25. return paths