Add flask-babel installation hook

This commit is contained in:
augustin64 2024-01-26 19:30:41 +01:00
parent c219f28a37
commit a97070eb2e
3 changed files with 41 additions and 3 deletions

View File

@ -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)

View File

@ -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")

View File

@ -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)])
]