2023-03-04 13:45:26 +00:00
|
|
|
"""
|
|
|
|
OnlyLegs - Theme Manager
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import shutil
|
|
|
|
from datetime import datetime
|
|
|
|
import sass
|
|
|
|
|
|
|
|
|
2023-04-01 16:59:17 +00:00
|
|
|
def compile_theme(theme_name, app_path):
|
2023-03-04 13:45:26 +00:00
|
|
|
"""
|
|
|
|
Compiles the theme into the static folder
|
|
|
|
"""
|
2023-04-01 16:59:17 +00:00
|
|
|
print(f"Loading '{theme_name}' theme...")
|
2023-03-04 13:45:26 +00:00
|
|
|
|
2023-04-01 16:59:17 +00:00
|
|
|
# Set Paths
|
2023-04-01 17:40:42 +00:00
|
|
|
theme_source = os.path.join(app_path, 'themes', theme_name)
|
|
|
|
theme_destination = os.path.join(app_path, 'static', 'theme')
|
2023-03-04 13:45:26 +00:00
|
|
|
|
2023-04-01 16:59:17 +00:00
|
|
|
# If the theme doesn't exist, exit
|
2023-04-01 17:40:42 +00:00
|
|
|
if not os.path.exists(theme_source):
|
2023-04-01 16:59:17 +00:00
|
|
|
print("Theme does not exist!")
|
|
|
|
sys.exit(1)
|
2023-03-04 13:45:26 +00:00
|
|
|
|
2023-04-01 16:59:17 +00:00
|
|
|
# If the destination folder doesn't exist, create it
|
2023-04-01 17:40:42 +00:00
|
|
|
if not os.path.exists(theme_destination):
|
|
|
|
os.makedirs(theme_destination)
|
2023-03-04 13:45:26 +00:00
|
|
|
|
2023-04-01 16:59:17 +00:00
|
|
|
# Theme source file doesn't exist, exit
|
2023-04-01 17:40:42 +00:00
|
|
|
if not os.path.join(theme_source, 'style.sass'):
|
2023-04-01 16:59:17 +00:00
|
|
|
print("No sass file found!")
|
|
|
|
sys.exit(1)
|
2023-03-04 13:45:26 +00:00
|
|
|
|
2023-04-01 16:59:17 +00:00
|
|
|
# Compile the theme
|
2023-04-01 17:40:42 +00:00
|
|
|
with open(os.path.join(theme_destination, 'style.css'),
|
|
|
|
encoding='utf-8', mode='w+') as file:
|
2023-04-01 16:59:17 +00:00
|
|
|
try:
|
2023-04-01 17:40:42 +00:00
|
|
|
file.write(sass.compile(filename=os.path.join(theme_source, 'style.sass'),
|
|
|
|
output_style='compressed'))
|
2023-04-01 16:59:17 +00:00
|
|
|
except sass.CompileError as err:
|
|
|
|
print("Failed to compile!\n", err)
|
2023-03-04 13:45:26 +00:00
|
|
|
sys.exit(1)
|
2023-04-01 16:59:17 +00:00
|
|
|
print("Compiled successfully!")
|
2023-04-01 17:40:42 +00:00
|
|
|
|
2023-04-01 16:59:17 +00:00
|
|
|
# If the destination folder exists, remove it
|
2023-04-01 17:40:42 +00:00
|
|
|
if os.path.exists(os.path.join(theme_destination, 'fonts')):
|
2023-03-04 13:45:26 +00:00
|
|
|
try:
|
2023-04-01 17:40:42 +00:00
|
|
|
shutil.rmtree(os.path.join(theme_destination, 'fonts'))
|
2023-03-04 13:45:26 +00:00
|
|
|
except Exception as err:
|
2023-04-01 16:59:17 +00:00
|
|
|
print("Failed to remove old fonts!\n", err)
|
2023-03-04 13:45:26 +00:00
|
|
|
sys.exit(1)
|
2023-03-20 17:57:47 +00:00
|
|
|
|
2023-04-01 16:59:17 +00:00
|
|
|
# Copy the fonts
|
|
|
|
try:
|
2023-04-01 17:40:42 +00:00
|
|
|
shutil.copytree(os.path.join(theme_source, 'fonts'),
|
|
|
|
os.path.join(theme_destination, 'fonts'))
|
2023-03-12 13:12:38 +00:00
|
|
|
print("Fonts copied successfully!")
|
2023-04-01 16:59:17 +00:00
|
|
|
except Exception as err:
|
|
|
|
print("Failed to copy fonts!\n", err)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
print(f"{datetime.now().hour}:{datetime.now().minute}:{datetime.now().second} - Done!\n")
|