added option to overwrite existing logo and force flag

This commit is contained in:
Kenneth SOARES 2025-04-09 20:19:19 +02:00
parent 61844e4cc5
commit 0fb5baf467

View File

@ -10,16 +10,23 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("numero", type=int)
parser.add_argument("path", type=pathlib.Path)
parser.add_argument("-f", "--force", action="store_true")
def handle(self, *args, **options):
if options["path"].exists():
path = pathlib.Path(
dest_path = pathlib.Path(
f"{BASE_DIR}/core/static/core/img/promo_{options['numero']}.png"
)
if dest_path.exists() and not options["force"]:
over = input("File already exists, do you want to overwrite it? (Y/n):")
if over.lower() != "y":
exit(0)
try:
with Image.open(options["path"]) as im:
im.resize((120, 120)).save(path, format="PNG")
im.resize((120, 120)).save(dest_path, format="PNG")
self.stdout.write("Promo logo moved and resized successfully")
except IOError as ioe:
self.stderr.write(ioe)
else:
self.stdout.write("file does not exist.")
self.stdout.write("input file does not exist.")