mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26:16 +00:00
Add a manifest file for themes
This may be removed later
This commit is contained in:
parent
4dfaa17c44
commit
266e959605
2 changed files with 35 additions and 7 deletions
7
gallery/themes/default/manifest.json
Normal file
7
gallery/themes/default/manifest.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"version": "23.04.03",
|
||||||
|
"author": "Michał Gdula",
|
||||||
|
"description": "Default theme for OnlyLegs",
|
||||||
|
"uses": "sass"
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import sys
|
||||||
import shutil
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import sass
|
import sass
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
def compile_theme(theme_name, app_path):
|
def compile_theme(theme_name, app_path):
|
||||||
|
@ -16,7 +17,7 @@ def compile_theme(theme_name, app_path):
|
||||||
|
|
||||||
# Set Paths
|
# Set Paths
|
||||||
theme_source = os.path.join(app_path, 'themes', theme_name)
|
theme_source = os.path.join(app_path, 'themes', theme_name)
|
||||||
theme_destination = os.path.join(app_path, 'static', 'theme')
|
theme_target = os.path.join(app_path, 'static', 'theme')
|
||||||
|
|
||||||
# If the theme doesn't exist, exit
|
# If the theme doesn't exist, exit
|
||||||
if not os.path.exists(theme_source):
|
if not os.path.exists(theme_source):
|
||||||
|
@ -24,16 +25,31 @@ def compile_theme(theme_name, app_path):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# If the destination folder doesn't exist, create it
|
# If the destination folder doesn't exist, create it
|
||||||
if not os.path.exists(theme_destination):
|
if not os.path.exists(theme_target):
|
||||||
os.makedirs(theme_destination)
|
os.makedirs(theme_target)
|
||||||
|
|
||||||
# Theme source file doesn't exist, exit
|
# Theme source file doesn't exist, exit
|
||||||
if not os.path.join(theme_source, 'style.sass'):
|
if not os.path.join(theme_source, 'style.sass'):
|
||||||
print("No sass file found!")
|
print("No sass file found!")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Check if the theme has a manifest.json file
|
||||||
|
if os.path.exists(os.path.join(theme_source, 'manifest.json')):
|
||||||
|
source_info = json.load(open(os.path.join(theme_source, 'manifest.json'), encoding='utf-8', mode='r'))
|
||||||
|
else:
|
||||||
|
print("Theme lacks a manifest.json file, exiting as its required!")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Check if the theme is upto date
|
||||||
|
if os.path.exists(os.path.join(theme_target, 'manifest.json')):
|
||||||
|
target_info = json.load(open(os.path.join(theme_target, 'manifest.json'), encoding='utf-8', mode='r'))
|
||||||
|
|
||||||
|
if source_info['version'] == target_info['version'] and source_info['name'] == target_info['name']:
|
||||||
|
print("Theme is up to date!")
|
||||||
|
return
|
||||||
|
|
||||||
# Compile the theme
|
# Compile the theme
|
||||||
with open(os.path.join(theme_destination, 'style.css'),
|
with open(os.path.join(theme_target, 'style.css'),
|
||||||
encoding='utf-8', mode='w+') as file:
|
encoding='utf-8', mode='w+') as file:
|
||||||
try:
|
try:
|
||||||
file.write(sass.compile(filename=os.path.join(theme_source, 'style.sass'),
|
file.write(sass.compile(filename=os.path.join(theme_source, 'style.sass'),
|
||||||
|
@ -44,12 +60,17 @@ def compile_theme(theme_name, app_path):
|
||||||
print("Compiled successfully!")
|
print("Compiled successfully!")
|
||||||
|
|
||||||
# If the destination folder exists, remove it
|
# If the destination folder exists, remove it
|
||||||
if os.path.exists(os.path.join(theme_destination, 'fonts')):
|
if os.path.exists(os.path.join(theme_target, 'fonts')):
|
||||||
shutil.rmtree(os.path.join(theme_destination, 'fonts'))
|
shutil.rmtree(os.path.join(theme_target, 'fonts'))
|
||||||
|
|
||||||
# Copy the fonts
|
# Copy the fonts
|
||||||
shutil.copytree(os.path.join(theme_source, 'fonts'),
|
shutil.copytree(os.path.join(theme_source, 'fonts'),
|
||||||
os.path.join(theme_destination, 'fonts'))
|
os.path.join(theme_target, 'fonts'))
|
||||||
print("Fonts copied successfully!")
|
print("Fonts copied successfully!")
|
||||||
|
|
||||||
|
# Copy the manifest
|
||||||
|
shutil.copyfile(os.path.join(theme_source, 'manifest.json'),
|
||||||
|
os.path.join(theme_target, 'manifest.json'))
|
||||||
|
print("Manifest copied successfully!")
|
||||||
|
|
||||||
print(f"{datetime.now().hour}:{datetime.now().minute}:{datetime.now().second} - Done!\n")
|
print(f"{datetime.now().hour}:{datetime.now().minute}:{datetime.now().second} - Done!\n")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue