-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from mxmehl/force-cleanup
Add --force option
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# SPDX-FileCopyrightText: 2024 Max Mehl <https://mehl.mx> | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-only | ||
|
||
"""Helper functions for file operations""" | ||
|
||
import logging | ||
from pathlib import Path | ||
from shutil import rmtree | ||
|
||
from ._card import Card | ||
from ._helpers import get_directories_in_directory, proper_dirname | ||
|
||
|
||
def clean_unconfigured_dirs(destination: str, cards: dict[int, Card]): | ||
"""Delete directories that are not configured as cards""" | ||
dest = Path(destination) | ||
# Calculate which directories are handled by the configuration | ||
handled_dirs = [proper_dirname(card) for card in cards] | ||
# For each existing directory on the SD card, check whether it is concerned | ||
# by the configuration | ||
for dirpath in get_directories_in_directory(dest): | ||
if dirpath.name in ("mp3", "advert"): | ||
continue | ||
if dirpath.name not in handled_dirs: | ||
logging.info( | ||
"The directory %s exists on the SD card although it is not configured here. " | ||
"Deleting it because you requested it with --force", | ||
dirpath.name, | ||
) | ||
rmtree(dirpath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters