Skip to content

Commit

Permalink
pattern/db: Updated .save logic in PatternDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Somerandomguy10111 committed Feb 24, 2025
1 parent 49d982d commit 7aedbb4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions xrdpattern/pattern/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,21 @@ def _add_data(self, info : XrdData, fpath : str, strict : bool):
if strict:
raise e

def save(self, dirpath : str, force_overwrite : bool = False):
if os.path.isfile(dirpath):
raise ValueError(f'Path \"{dirpath}\" is occupied by file')
def save(self, dirpath : str, skip_if_occupied : bool = True):
is_occupied = os.path.isfile(dirpath) or os.path.isdir(dirpath)
if is_occupied and skip_if_occupied:
patterdb_logger.warning(f'Path \"{dirpath}\" already exists. Skipping save operation')
return

os.makedirs(dirpath, exist_ok=True)

for j, patterns in enumerate(self.fpath_dict.values()):
for k, p in enumerate(patterns):
if len(patterns) > 1:
fname = f'pattern_group_{j}_{k}.{Formats.aimat_suffix()}'
else:
fname = f'pattern_{j}.{Formats.aimat_suffix()}'
fpath = os.path.join(dirpath, fname)
p.save(fpath=fpath, force_overwrite=force_overwrite)
p.save(fpath=fpath, force_overwrite=True)

# -------------------------------------------
# operations
Expand Down

0 comments on commit 7aedbb4

Please sign in to comment.