Remove dry-run option from clean playback token files command and enhance output logging
This commit is contained in:
parent
8f4e851fb9
commit
d919ed95b8
1 changed files with 24 additions and 32 deletions
|
|
@ -31,7 +31,6 @@ class Command(BaseCommand):
|
||||||
default=None,
|
default=None,
|
||||||
help="Directory to move files to instead of deleting them (defaults to '<dir>/deleted')",
|
help="Directory to move files to instead of deleting them (defaults to '<dir>/deleted')",
|
||||||
)
|
)
|
||||||
parser.add_argument("--dry-run", action="store_true", help="Only print files that would be moved without actually moving them")
|
|
||||||
|
|
||||||
def is_playback_token_only(self, data: dict[str, Any]) -> bool:
|
def is_playback_token_only(self, data: dict[str, Any]) -> bool:
|
||||||
"""Determine if a JSON data structure only contains PlaybackAccessToken data.
|
"""Determine if a JSON data structure only contains PlaybackAccessToken data.
|
||||||
|
|
@ -56,6 +55,7 @@ class Command(BaseCommand):
|
||||||
)
|
)
|
||||||
|
|
||||||
if has_playback_token:
|
if has_playback_token:
|
||||||
|
self.stdout.write(f"Found PlaybackAccessToken only in {data['data']['streamPlaybackAccessToken']['__typename']}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Also check if the operation name in extensions is PlaybackAccessToken and no other data
|
# Also check if the operation name in extensions is PlaybackAccessToken and no other data
|
||||||
|
|
@ -66,15 +66,13 @@ class Command(BaseCommand):
|
||||||
and ("data" not in data or ("data" in data and len(data["data"]) <= 1))
|
and ("data" not in data or ("data" in data and len(data["data"]) <= 1))
|
||||||
)
|
)
|
||||||
|
|
||||||
def process_file(self, file_path: Path, *, dry_run: bool = False, deleted_dir: Path) -> bool:
|
def process_file(self, file_path: Path, *, deleted_dir: Path) -> bool:
|
||||||
"""Process a single JSON file to check if it only contains PlaybackAccessToken data.
|
"""Process a single JSON file to check if it only contains PlaybackAccessToken data.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
----------
|
----------
|
||||||
file_path : Path
|
file_path : Path
|
||||||
The path to the JSON file
|
The path to the JSON file
|
||||||
dry_run : bool, keyword-only
|
|
||||||
If True, only log the action without actually moving the file
|
|
||||||
deleted_dir : Path, keyword-only
|
deleted_dir : Path, keyword-only
|
||||||
Directory to move files to instead of deleting them
|
Directory to move files to instead of deleting them
|
||||||
|
|
||||||
|
|
@ -87,9 +85,6 @@ class Command(BaseCommand):
|
||||||
data = json.loads(file_path.read_text(encoding="utf-8"))
|
data = json.loads(file_path.read_text(encoding="utf-8"))
|
||||||
|
|
||||||
if self.is_playback_token_only(data):
|
if self.is_playback_token_only(data):
|
||||||
if dry_run:
|
|
||||||
self.stdout.write(f"Would move: {file_path} to {deleted_dir}")
|
|
||||||
else:
|
|
||||||
# Create the deleted directory if it doesn't exist
|
# Create the deleted directory if it doesn't exist
|
||||||
if not deleted_dir.exists():
|
if not deleted_dir.exists():
|
||||||
deleted_dir.mkdir(parents=True, exist_ok=True)
|
deleted_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
@ -161,13 +156,10 @@ class Command(BaseCommand):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
file_count += 1
|
file_count += 1
|
||||||
if self.process_file(file_path, dry_run=dry_run, deleted_dir=deleted_dir):
|
if self.process_file(file_path, deleted_dir=deleted_dir):
|
||||||
moved_count += 1
|
moved_count += 1
|
||||||
|
|
||||||
# Report the results
|
# Report the results
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
self.style.SUCCESS(
|
self.style.SUCCESS(f"Cleanup completed: Processed {file_count} files, moved {moved_count} files to {deleted_dir}")
|
||||||
f"{'Dry run completed' if dry_run else 'Cleanup completed'}: "
|
|
||||||
f"Processed {file_count} files, {'would move' if dry_run else 'moved'} {moved_count} files to {deleted_dir}"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue