From a97070eb2e9a8e851b2be3400f0b825bb4d10ae5 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 26 Jan 2024 19:30:41 +0100 Subject: [PATCH] Add flask-babel installation hook --- scripts/hooks/utils.py | 28 ++++++++++++++++++++++++++++ scripts/hooks/v1.py | 13 +++++++++++-- scripts/migration.py | 3 ++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/scripts/hooks/utils.py b/scripts/hooks/utils.py index 9683c8e..c901181 100644 --- a/scripts/hooks/utils.py +++ b/scripts/hooks/utils.py @@ -1,7 +1,9 @@ import os +import sys import random import string import sqlite3 +from colorama import Fore, Style from . import config @@ -40,3 +42,29 @@ def new_uuid(): def format_uuid(uuid): """Format old uuid4 format""" return uuid.upper()[:6] + + +def install_package(package): + print(f"\nThe following python package needs to be installed: {Style.BRIGHT}{Fore.YELLOW}{package}{Style.RESET_ALL}") + print(f"1. Install with {Style.BRIGHT}pip{Style.RESET_ALL} (automatic)") + print(f"2. Install manually (other package manager)") + option = input("Select an option: ") + try: + choice = int(option) + + if choice == 1: + return_value = os.system(f"pip install {package} -qq") + if return_value == 0: + return + print(f"{Fore.RED}Installation with pip failed{Style.RESET_ALL}") + sys.exit(return_value) + + elif choice == 2: + input("Install via you preferred option, and hit [Enter] when done") + return + + except ValueError: + pass + + print(f"{Fore.RED}Please enter a valid option{Style.RESET_ALL}") + return install_package(package) \ No newline at end of file diff --git a/scripts/hooks/v1.py b/scripts/hooks/v1.py index 176b813..07776b1 100644 --- a/scripts/hooks/v1.py +++ b/scripts/hooks/v1.py @@ -54,7 +54,7 @@ def add_attachments(): def install_colorama(): - os.system("pip install colorama -qq") + utils.install_package("colorama") """ @@ -144,7 +144,7 @@ def base_url_parameter_added(): def install_qrcode(): - os.system("pip install qrcode -qq") + utils.install_package("qrcode") """ @@ -171,3 +171,12 @@ def move_thumbnails(): os.makedirs(os.path.join(config.instance, "cache", "thumbnails"), exist_ok=True) os.makedirs(os.path.join(config.instance, "cache", "search-thumbnails"), exist_ok=True) + + +""" + v1.7.* +""" + + +def install_babel(): + utils.install_package("flask-babel") \ No newline at end of file diff --git a/scripts/migration.py b/scripts/migration.py index 4434bbb..a93302c 100644 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -34,7 +34,8 @@ hooks = [ ), ("v1.4.1", [("Install qrcode", v1_hooks.install_qrcode)]), ("v1.5.0", [("Move to instance directory", v1_hooks.move_instance)]), - ("v1.5.1", [("Move thumbnails", v1_hooks.move_thumbnails)]) + ("v1.5.1", [("Move thumbnails", v1_hooks.move_thumbnails)]), + ("v1.7.0", [("Install babel", v1_hooks.install_babel)]) ]