Skip to content

Commit

Permalink
refactor: #94 support dry run on resource deletion
Browse files Browse the repository at this point in the history
- updated deletion of remote files to support dry run mode
  • Loading branch information
miguelcsx committed Oct 23, 2024
1 parent 3b9271b commit dc296f7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cloudinary_cli/modules/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def push(self):
logger.info(f"{file}")
return True


logger.info(f"Uploading {len(files_to_push)} items to Cloudinary folder '{self.user_friendly_remote_dir}'")

options = {
Expand Down Expand Up @@ -364,6 +363,10 @@ def _handle_unique_remote_files(self):

# Each batch is further chunked by a deletion batch size that can be specified by the user.
for deletion_batch in chunker(batch, self.deletion_batch_size):
if self.dry_run:
logger.info(f"Dry run mode enabled. Would delete {len(deletion_batch)} resources:\n" +
"\n".join(deletion_batch))
continue
res = api.delete_resources(deletion_batch, invalidate=True, resource_type=attrs[0], type=attrs[1])
num_deleted = Counter(res['deleted'].values())["deleted"]
if self.verbose:
Expand Down Expand Up @@ -411,6 +414,9 @@ def _handle_unique_local_files(self):
logger.info(f"Deleting {len(self.unique_local_file_names)} local files...")
for file in self.unique_local_file_names:
full_path = path.abspath(self.local_files[file]['path'])
if self.dry_run:
logger.info(f"Dry run mode enabled. Would delete '{full_path}'")
continue
remove(full_path)
logger.info(f"Deleted '{full_path}'")

Expand Down

0 comments on commit dc296f7

Please sign in to comment.