Skip to content

Commit

Permalink
don't re-create already existing collections
Browse files Browse the repository at this point in the history
  • Loading branch information
sellth committed Sep 26, 2023
1 parent e7df7b7 commit 96a93e7
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions cubi_tk/sodar/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,42 @@ def execute(self):
{p["ipath"].parent for p in source_paths if not p["ipath"].parent == Path(".")}
)

logger.info("Planning to create the following sub-collections:")
for d in dirs:
output_logger.info(f"{self.target_coll}/{str(d)}")
if not self.args.yes:
if not input("Is this OK? [y/N] ").lower().startswith("y"): # pragma: no cover
logger.info("Aborting at your request.")
sys.exit(0)

for d in dirs:
coll_name = f"{self.lz_irods_path}/{self.target_coll}/{str(d)}"
try:
irods_session.collections.create(coll_name)
except Exception as e: # pragma: no cover
logger.error("Error creating sub-collection.")
logger.error(e)
sys.exit(1)
finally:
irods_session.cleanup()
logger.info("Sub-collections created.")
# Filter out existing sub-collections
try:
dirs = [
d
for d in dirs
if not irods_session.collections.exists(
f"{self.lz_irods_path}/{self.target_coll}/{str(d)}"
)
]
except Exception as e: # pragma: no cover
logger.error("Error checking for sub-collections.")
logger.error(e)
sys.exit(1)
finally:
irods_session.cleanup()

if dirs:
logger.info("Planning to create the following sub-collections:")
for d in dirs:
output_logger.info(f"{self.target_coll}/{str(d)}")
if not self.args.yes:
if not input("Is this OK? [y/N] ").lower().startswith("y"): # pragma: no cover
logger.info("Aborting at your request.")
sys.exit(0)

for d in dirs:
coll_name = f"{self.lz_irods_path}/{self.target_coll}/{str(d)}"
try:
irods_session.collections.create(coll_name)
except Exception as e: # pragma: no cover
logger.error("Error creating sub-collection.")
logger.error(e)
sys.exit(1)
finally:
irods_session.cleanup()
logger.info("Sub-collections created.")

# Build transfer jobs
jobs = self.build_jobs(source_paths, irods_session)
Expand Down

0 comments on commit 96a93e7

Please sign in to comment.