mirror of
https://github.com/ae-utbm/sith.git
synced 2025-04-16 02:50:22 +00:00
added option to overwrite existing logo and force flag
This commit is contained in:
parent
61844e4cc5
commit
0fb5baf467
@ -10,16 +10,23 @@ class Command(BaseCommand):
|
|||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument("numero", type=int)
|
parser.add_argument("numero", type=int)
|
||||||
parser.add_argument("path", type=pathlib.Path)
|
parser.add_argument("path", type=pathlib.Path)
|
||||||
|
parser.add_argument("-f", "--force", action="store_true")
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
if options["path"].exists():
|
if options["path"].exists():
|
||||||
path = pathlib.Path(
|
dest_path = pathlib.Path(
|
||||||
f"{BASE_DIR}/core/static/core/img/promo_{options['numero']}.png"
|
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:
|
try:
|
||||||
with Image.open(options["path"]) as im:
|
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:
|
except IOError as ioe:
|
||||||
self.stderr.write(ioe)
|
self.stderr.write(ioe)
|
||||||
else:
|
else:
|
||||||
self.stdout.write("file does not exist.")
|
self.stdout.write("input file does not exist.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user