mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 11:36:16 +00:00
Moved some scripts to a utils folder
Renamed upload route to file as its more approprete Fixed random CSS issues that occur on older browsers or Safari
This commit is contained in:
parent
9cfb8befd2
commit
3008a55899
19 changed files with 102 additions and 76 deletions
|
@ -1,82 +0,0 @@
|
|||
"""
|
||||
OnlyLegs - Theme Manager
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
import sass
|
||||
|
||||
|
||||
class CompileTheme:
|
||||
"""
|
||||
Compiles the theme into the static folder
|
||||
"""
|
||||
def __init__(self, theme_name, app_path):
|
||||
"""
|
||||
Initialize the theme manager
|
||||
Compiles the theme into the static folder and loads the fonts
|
||||
"""
|
||||
|
||||
print(f"Loading '{theme_name}' theme...")
|
||||
|
||||
theme_path = os.path.join(app_path, 'themes', theme_name)
|
||||
theme_dest = os.path.join(app_path, 'static', 'theme')
|
||||
|
||||
if not os.path.exists(theme_path):
|
||||
print("Theme does not exist!")
|
||||
sys.exit(1)
|
||||
|
||||
if not os.path.exists(theme_dest):
|
||||
os.makedirs(theme_dest)
|
||||
|
||||
self.load_sass(theme_path, theme_dest)
|
||||
self.load_fonts(theme_path, theme_dest)
|
||||
|
||||
print(f"{datetime.now().hour}:{datetime.now().minute}:{datetime.now().second} - Done!\n")
|
||||
|
||||
@staticmethod
|
||||
def load_sass(source_path, css_dest):
|
||||
"""
|
||||
Compile the sass (or scss) file into css and save it to the static folder
|
||||
"""
|
||||
if os.path.join(source_path, 'style.sass'):
|
||||
sass_path = os.path.join(source_path, 'style.sass')
|
||||
elif os.path.join(source_path, 'style.scss'):
|
||||
sass_path = os.path.join(source_path, 'style.scss')
|
||||
else:
|
||||
print("No sass file found!")
|
||||
sys.exit(1)
|
||||
|
||||
with open(os.path.join(css_dest, 'style.css'), encoding='utf-8', mode='w+') as file:
|
||||
try:
|
||||
file.write(sass.compile(filename=sass_path,output_style='compressed'))
|
||||
except sass.CompileError as err:
|
||||
print("Failed to compile!\n", err)
|
||||
sys.exit(1)
|
||||
|
||||
print("Compiled successfully!")
|
||||
|
||||
@staticmethod
|
||||
def load_fonts(source_path, font_dest):
|
||||
"""
|
||||
Copy the fonts folder to the static folder
|
||||
"""
|
||||
# Append fonts to the destination path
|
||||
source_path = os.path.join(source_path, 'fonts')
|
||||
font_dest = os.path.join(font_dest, 'fonts')
|
||||
|
||||
if os.path.exists(font_dest):
|
||||
try:
|
||||
shutil.rmtree(font_dest)
|
||||
except Exception as err:
|
||||
print("Failed to remove old fonts!\n", err)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
shutil.copytree(source_path, font_dest)
|
||||
except Exception as err:
|
||||
print("Failed to copy fonts!\n", err)
|
||||
sys.exit(1)
|
||||
|
||||
print("Fonts copied successfully!")
|
Loading…
Add table
Add a link
Reference in a new issue