2023-01-08 15:14:35 +00:00
|
|
|
import datetime
|
|
|
|
now = datetime.datetime.now()
|
2023-01-01 14:31:28 +00:00
|
|
|
import sys
|
2023-01-06 23:46:12 +00:00
|
|
|
import shutil
|
2023-01-01 14:31:28 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
class Sassy():
|
|
|
|
def __init__(self, theme):
|
2023-01-06 15:47:58 +00:00
|
|
|
print("### OnlyLegs Theme Manager ###")
|
2023-01-08 15:14:35 +00:00
|
|
|
print(f"{now.hour}:{now.minute}:{now.second} - Loading theme...")
|
2023-01-06 15:47:58 +00:00
|
|
|
|
2023-01-01 14:31:28 +00:00
|
|
|
try:
|
|
|
|
import sass
|
|
|
|
except ImportError:
|
2023-01-06 15:47:58 +00:00
|
|
|
print("Could not find libsass!")
|
2023-01-01 14:31:28 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2023-01-06 23:46:12 +00:00
|
|
|
theme_path = os.path.join('usr', 'themes', theme, 'style.scss')
|
2023-01-01 14:31:28 +00:00
|
|
|
|
2023-01-06 23:46:12 +00:00
|
|
|
if os.path.exists(theme_path):
|
|
|
|
print(f"Theme '{theme}' found at:", theme_path)
|
2023-01-01 14:31:28 +00:00
|
|
|
self.sass = sass
|
2023-01-06 23:46:12 +00:00
|
|
|
self.loadTheme(theme_path)
|
2023-01-01 14:31:28 +00:00
|
|
|
else:
|
2023-01-06 15:47:58 +00:00
|
|
|
print("No theme found!")
|
2023-01-01 14:31:28 +00:00
|
|
|
sys.exit(1)
|
2023-01-06 23:46:12 +00:00
|
|
|
|
|
|
|
font_path = os.path.join('usr', 'themes', theme, 'fonts')
|
|
|
|
|
|
|
|
if os.path.exists(font_path):
|
|
|
|
print("Fonts found at:", font_path)
|
|
|
|
self.loadFonts(font_path)
|
|
|
|
else:
|
|
|
|
print("No fonts found!")
|
|
|
|
|
2023-01-08 15:14:35 +00:00
|
|
|
print(f"{now.hour}:{now.minute}:{now.second} - Done!\n")
|
2023-01-01 14:31:28 +00:00
|
|
|
|
|
|
|
def loadTheme (self, theme):
|
2023-01-08 22:27:01 +00:00
|
|
|
with open('static/theme/style.css', 'w') as f:
|
2023-01-01 14:31:28 +00:00
|
|
|
try:
|
|
|
|
f.write(self.sass.compile(filename=theme, output_style='compressed'))
|
2023-01-06 23:46:12 +00:00
|
|
|
print("Compiled successfully to:", f.name)
|
2023-01-01 14:31:28 +00:00
|
|
|
except self.sass.CompileError as e:
|
2023-01-06 23:46:12 +00:00
|
|
|
print("Failed to compile!\nFull error:", e)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def loadFonts (self, font_path):
|
2023-01-08 22:27:01 +00:00
|
|
|
dest = os.path.join('static', 'theme', 'fonts')
|
2023-01-06 23:46:12 +00:00
|
|
|
|
|
|
|
if os.path.exists(dest):
|
|
|
|
print("Removing old fonts...")
|
|
|
|
try:
|
|
|
|
shutil.rmtree(dest)
|
|
|
|
print("Removed old fonts!")
|
|
|
|
except Exception as e:
|
|
|
|
print("Failed to remove old fonts!\nFull error:", e)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
shutil.copytree(font_path, dest)
|
|
|
|
print("Copied fonts to:", dest)
|
|
|
|
except Exception as e:
|
|
|
|
print("Failed to copy fonts!\nFull error:", e)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
#print ("Removing old fonts from:", dest)
|
|
|
|
#for old in os.listdir(dest):
|
|
|
|
# dir = os.path.join(dest , old)
|
|
|
|
#
|
|
|
|
# try:
|
|
|
|
# if os.path.isfile(dir) or os.path.islink(dir):
|
|
|
|
# os.unlink(dir)
|
|
|
|
# print("Removed:", old)
|
|
|
|
# elif os.path.isdir(dir):
|
|
|
|
# shutil.rmtree(dir)
|
|
|
|
# print("Removed:", old)
|
|
|
|
# except Exception as e:
|
|
|
|
# print("Failed to remove:", dir)
|
|
|
|
# print("Full error:", e)
|
|
|
|
|
|
|
|
#print ("Loading new fonts")
|
|
|
|
#for font in os.listdir(font_path):
|
|
|
|
# dir = os.path.join(font_path, dest)
|
|
|
|
# new_dir = os.path.join(dest, font)
|
|
|
|
#
|
|
|
|
# try:
|
|
|
|
# if os.path.isfile(dir):
|
|
|
|
# shutil.copy(dir, new_dir)
|
|
|
|
# print("Copied font:", font)
|
|
|
|
# except Exception as e:
|
|
|
|
# print("Failed to copy font:", font)
|
|
|
|
# print("Full error:", e)
|