diff --git a/.version b/.version index a625450..e703481 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.3.1 \ No newline at end of file +2.3.2 \ No newline at end of file diff --git a/builder.py b/builder.py index 7687466..484c2eb 100755 --- a/builder.py +++ b/builder.py @@ -101,8 +101,8 @@ def copy_static_files(_args: Args) -> None: logger.info("found foldericon", extra={"foldericon": foldericon}) break if "url" in foldericon: - shutil.copyfile(_args.theme_path, os.path.join(static_dir, "theme.css")) logger.info("foldericon in theme file, using it") + shutil.copyfile(_args.theme_path, os.path.join(static_dir, "theme.css")) return with open(os.path.join(SCRIPTDIR, foldericon), "r", encoding="utf-8") as f: logger.info("Reading foldericon svg") @@ -110,10 +110,8 @@ def copy_static_files(_args: Args) -> None: if "svg.j2" in foldericon: logger.info("foldericon in theme file is a jinja2 template") colorscheme = extract_colorscheme(_args.theme_path) - svg = svg.replace("{{ color1 }}", colorscheme["color1"]) - svg = svg.replace("{{ color2 }}", colorscheme["color2"]) - svg = svg.replace("{{ color3 }}", colorscheme["color3"]) - svg = svg.replace("{{ color4 }}", colorscheme["color4"]) + for color_key, color_value in colorscheme.items(): + svg = svg.replace(f"{{{{ {color_key} }}}}", color_value) logger.info("replaced colors in svg") svg = urllib.parse.quote(svg) with open(os.path.join(static_dir, "theme.css"), "x", encoding="utf-8") as f: diff --git a/generate_previews.py b/generate_previews.py index e76e536..87c4e9b 100644 --- a/generate_previews.py +++ b/generate_previews.py @@ -4,21 +4,18 @@ import sys import time import shutil import base64 -import logging import fileinput import urllib.parse import urllib.request from typing import List from selenium import webdriver +from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options -from selenium.webdriver.common.by import By +from modules.logger import consolelogger as logger from modules.css_color import extract_colorscheme -# Set up logging -logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") - def replace_all(file, search_exp, replace_exp): for line in fileinput.input(file, inplace=1): @@ -36,11 +33,14 @@ def take_screenshot(html_file_path: str, css_file: str, output_file: str, driver output_file (str): Path where the screenshot will be saved. driver (webdriver.Chrome): The Chrome WebDriver instance. """ + logger.info("taking screenshot for %s", css_file) try: # Open the HTML file or URL if html_file_path.startswith(("http://", "https://")): + logger.info("opening URL: %s", html_file_path) driver.get(html_file_path) else: + logger.info("opening file: %s", html_file_path) driver.get(f"file://{os.path.abspath(html_file_path)}") # Remove current theme.css @@ -52,9 +52,11 @@ def take_screenshot(html_file_path: str, css_file: str, output_file: str, driver } }); """ + logger.info("removing current theme.css") driver.execute_script(remove_css_script) with open(css_file, "r", encoding="utf-8") as f: + logger.info("reading CSS file: %s", css_file) css_content = f.read() # Extract folder icon content @@ -65,20 +67,26 @@ def take_screenshot(html_file_path: str, css_file: str, output_file: str, driver folder_icon_content = re.sub(r"/\*.*\*/", "", folder_icon_content) for match in re.finditer(r"content: (.*);", folder_icon_content): + logger.info("found foldericon", extra={"foldericon": folder_icon_content}) folder_icon_content = match.group(1).replace('"', "") break if "url" not in folder_icon_content: + logger.info("Reading foldericon svg") with open(folder_icon_content, "r", encoding="utf-8") as f: svg = f.read() if "svg.j2" in folder_icon_content: + logger.info("foldericon in theme file is a jinja2 template") colorscheme = extract_colorscheme(css_file) for color_key, color_value in colorscheme.items(): svg = svg.replace(f"{{{{ {color_key} }}}}", color_value) + logger.info("replaced colors in svg") svg = urllib.parse.quote(svg) + css_content = f'{css_head}\n.foldericon {{\n content: url("data:image/svg+xml,{svg}");\n}}\n{css_tail}' # Encode CSS content as Base64 + logger.info("encoding css content as base64") encoded_css = base64.b64encode(css_content.encode("utf-8")).decode("utf-8") # Inject CSS into HTML using JavaScript @@ -87,24 +95,28 @@ def take_screenshot(html_file_path: str, css_file: str, output_file: str, driver style.innerHTML = atob('{encoded_css}'); document.head.appendChild(style); """ + logger.info("injecting CSS into HTML") driver.execute_script(apply_css_script) # Wait for a while to ensure CSS is applied - time.sleep(2) + # time.sleep(1) # Move mouse to info + logger.info("moving mouse to info") hoverable = driver.find_element(By.CLASS_NAME, "tooltip") webdriver.ActionChains(driver).move_to_element(hoverable).perform() # Capture screenshot + logger.info("taking screenshot") driver.save_screenshot(output_file) - logging.info("Screenshot saved to %s", output_file) + logger.info("screenshot saved to %s", output_file) except Exception as e: - logging.error("Failed to take screenshot for %s: %s", css_file, e) + logger.error("failed to take screenshot for %s: %s", css_file, e) def create_preview(html_file_path: str, css_file: str, previews_folder: str): + logger.info("creating preview for %s", css_file) out_file = os.path.basename(css_file).removesuffix(".css") + ".html" urllib.request.urlretrieve(html_file_path, os.path.join(previews_folder, out_file)) basename = os.path.basename(css_file) @@ -127,21 +139,25 @@ def create_preview(html_file_path: str, css_file: str, previews_folder: str): foldericon = foldericon.replace('"', "") break if "url" in foldericon: + logger.info("foldericon in theme file, using it") shutil.copyfile(css_file, os.path.join(path, "previews", basename)) - else: - with open(os.path.join(path, foldericon.removeprefix("themes/")), "r", encoding="utf-8") as f: - svg = f.read() - if "svg.j2" in foldericon: - colorscheme = extract_colorscheme(css_file) - svg = svg.replace("{{ color1 }}", colorscheme["color1"]) - svg = svg.replace("{{ color2 }}", colorscheme["color2"]) - svg = svg.replace("{{ color3 }}", colorscheme["color3"]) - svg = svg.replace("{{ color4 }}", colorscheme["color4"]) - svg = urllib.parse.quote(svg) - if os.path.exists(os.path.join(path, "previews", basename)): - os.remove(os.path.join(path, "previews", basename)) - with open(os.path.join(path, "previews", basename), "x", encoding="utf-8") as f: - f.write(themehead + '\n.foldericon {\n content: url("data:image/svg+xml,' + svg + '");\n}\n' + themetail) + return + with open(os.path.join(path, foldericon.removeprefix("themes/")), "r", encoding="utf-8") as f: + logger.info("Reading foldericon svg") + svg = f.read() + if "svg.j2" in foldericon: + logger.info("foldericon in theme file is a jinja2 template") + colorscheme = extract_colorscheme(css_file) + for color_key, color_value in colorscheme.items(): + svg = svg.replace(f"{{{{ {color_key} }}}}", color_value) + logger.info("replaced colors in svg") + svg = urllib.parse.quote(svg) + if os.path.exists(os.path.join(path, "previews", basename)): + os.remove(os.path.join(path, "previews", basename)) + with open(os.path.join(path, "previews", basename), "x", encoding="utf-8") as f: + logger.info("writing theme file") + f.write(themehead + '\n.foldericon {\n content: url("data:image/svg+xml,' + svg + '");\n}\n' + themetail) + logger.info("preview created for %s", css_file) def write_readme(directory_path: str, themes: List[str]) -> None: @@ -155,6 +171,7 @@ def write_readme(directory_path: str, themes: List[str]) -> None: readme_path = os.path.join(directory_path, "README.md") try: with open(readme_path, "r", encoding="utf-8") as f: + logger.info("reading README.md", extra={"file": readme_path}) readme = f.read() readme_head = readme.split("## Previews of included themes")[0] @@ -162,14 +179,15 @@ def write_readme(directory_path: str, themes: List[str]) -> None: readme_head += "".join([f"\n### {theme}\n\n![{theme}](screenshots/{theme}.png)\n" for theme in themes]) with open(readme_path, "w", encoding="utf-8") as f: + logger.info("writing README.md", extra={"file": readme_path}) f.write(readme_head) - logging.info("README.md updated with previews of included themes.") + logger.info("README.md updated with previews of included themes.") except FileNotFoundError: - logging.error("README.md not found in %s", directory_path) + logger.error("README.md not found in %s", directory_path) except Exception as e: - logging.error("Failed to write README.md: %s", e) + logger.error("failed to write README.md: %s", e) def write_index(directory_path: str, themes: List[str]) -> None: @@ -198,7 +216,7 @@ def main(directory_path: str, html_file_path: str) -> None: html_file_path (str): Path to the HTML file or URL for rendering. """ if not os.path.exists(directory_path): - logging.error('Error: Folder path "%s" does not exist.', directory_path) + logger.error('Error: Folder path "%s" does not exist.', directory_path) return # Setup Chrome options @@ -207,8 +225,9 @@ def main(directory_path: str, html_file_path: str) -> None: chrome_options.add_argument("--window-size=1920,1080") # Set window size to at least 1920x1080 # Initialize Chrome WebDriver - chromedriver_path = "/usr/bin/chromedriver" # Replace with your actual path + chromedriver_path = "/usr/bin/chromedriver" service = Service(chromedriver_path) + logger.info("Using chromedriver at %s", chromedriver_path, extra={"chrome_options": chrome_options}) driver = webdriver.Chrome(service=service, options=chrome_options) try: @@ -235,13 +254,16 @@ def main(directory_path: str, html_file_path: str) -> None: write_index(directory_path, themes) finally: + logger.info("closing chrome webdriver") driver.quit() if __name__ == "__main__": if len(sys.argv) != 3: - logging.error("Usage: python script_name.py directory_path html_file_path") + logger.error("Usage: python script_name.py directory_path html_file_path") else: dir_path = sys.argv[1] html_path = sys.argv[2] + logger.info("Starting script", extra={"directory_path": dir_path, "html_file_path": html_path}) main(dir_path, html_path) + logger.info("Done!", extra={"directory_path": dir_path}) diff --git a/modules/css_color.py b/modules/css_color.py index b05f03e..fb23bee 100644 --- a/modules/css_color.py +++ b/modules/css_color.py @@ -33,8 +33,7 @@ def extract_colorscheme(theme_path: str) -> Dict[str, str]: color_value = match[1] hex_color_value = css_color_to_hex(color_value) colorscheme[variable_name] = hex_color_value - logger.debug("extracted variable", extra={"variable": variable_name, "value": hex_color_value}) - logger.info("extracted color scheme", extra={"colorscheme": colorscheme}) + logger.debug("extracted variable", extra={"variable": variable_name, "value": hex_color_value}) return colorscheme diff --git a/modules/logger.py b/modules/logger.py index 8f4ed0b..385d0f1 100644 --- a/modules/logger.py +++ b/modules/logger.py @@ -77,7 +77,7 @@ def setup_logger(): logging.Logger: A configured logger instance that can be used to log messages. """ rotate_log_file() - app_logger = logging.getLogger() + _logger = logging.getLogger() supported_keys = ["asctime", "created", "filename", "funcName", "levelname", "levelno", "lineno", "module", "msecs", "message", "name", "pathname", "process", "processName", "relativeCreated", "thread", "threadName", "taskName"] @@ -87,10 +87,23 @@ def setup_logger(): log_handler = logging.FileHandler(LATEST_LOG_FILE) log_handler.setFormatter(formatter) - app_logger.addHandler(log_handler) - app_logger.setLevel(logging.INFO) + _logger.addHandler(log_handler) + _logger.setLevel(logging.INFO) - return app_logger + return _logger + + +def setup_consolelogger(): + """ + Configures the logging system to output logs in console format. + + Returns: + logging.Logger: A configured logger instance that can be used to log messages. + """ + _logger = setup_logger() + _logger.addHandler(logging.StreamHandler()) + return _logger logger = setup_logger() +consolelogger = setup_consolelogger() diff --git a/themes/carnation.css b/themes/carnation.css index eeeafbf..f115e7f 100644 --- a/themes/carnation.css +++ b/themes/carnation.css @@ -5,22 +5,22 @@ --color2: #b22222; --color3: #ff4500; --color4: #6e0000; - --bcolor1: #ebebeb; + --bcolor1: #171717; --bcolor2: #191919; - --bcolor3: #171717; + --bcolor3: #ebebeb; --bcolor4: #0a0a0a; } .navbar { font-weight: bold; - color: var(--bcolor1); + color: var(--bcolor3); background-color: var(--color1); font-weight: 900; } .navbar li a { font-weight: 800; - color: var(--bcolor1); + color: var(--bcolor3); } /* Change the link color on hover */ @@ -30,7 +30,7 @@ } .footer { - color: var(--bcolor1); + color: var(--bcolor3); background-color: var(--color3); font-weight: 700; } diff --git a/themes/cornflower.css b/themes/cornflower.css index f42a1da..b4ed888 100644 --- a/themes/cornflower.css +++ b/themes/cornflower.css @@ -5,22 +5,22 @@ --color2: #1346a4; --color3: #0e3377; --color4: #3674e7; - --bcolor1: #ebebeb; + --bcolor1: #171717; --bcolor2: #191919; - --bcolor3: #171717; + --bcolor3: #ebebeb; --bcolor4: #0a0a0a; } .navbar { font-weight: bold; - color: var(--bcolor1); + color: var(--bcolor3); background-color: var(--color1); font-weight: 900; } .navbar li a { font-weight: 800; - color: var(--bcolor1); + color: var(--bcolor3); } /* Change the link color on hover */ @@ -30,7 +30,7 @@ } .footer { - color: var(--bcolor1); + color: var(--bcolor3); background-color: var(--color3); font-weight: 700; } diff --git a/themes/icons/catpuccin.svg.j2 b/themes/icons/catpuccin.svg.j2 index e3386ac..7ede9d7 100644 --- a/themes/icons/catpuccin.svg.j2 +++ b/themes/icons/catpuccin.svg.j2 @@ -1,6 +1,6 @@ - - + + \ No newline at end of file diff --git a/themes/ivy.css b/themes/ivy.css index 14819e8..2a29d83 100644 --- a/themes/ivy.css +++ b/themes/ivy.css @@ -5,22 +5,22 @@ --color2: #008000; --color3: #32cd32; --color4: #004300; - --bcolor1: #ebebeb; + --bcolor1: #171717; --bcolor2: #191919; - --bcolor3: #171717; + --bcolor3: #ebebeb; --bcolor4: #0a0a0a; } .navbar { font-weight: bold; - color: var(--bcolor1); + color: var(--bcolor3); background-color: var(--color1); font-weight: 900; } .navbar li a { font-weight: 800; - color: var(--bcolor1); + color: var(--bcolor3); } /* Change the link color on hover */ @@ -30,7 +30,7 @@ } .footer { - color: var(--bcolor1); + color: var(--bcolor3); background-color: var(--color3); font-weight: 700; } diff --git a/themes/screenshots/alpenglow-dark.png b/themes/screenshots/alpenglow-dark.png index ce6a3a3..0099cff 100644 Binary files a/themes/screenshots/alpenglow-dark.png and b/themes/screenshots/alpenglow-dark.png differ diff --git a/themes/screenshots/alpenglow.png b/themes/screenshots/alpenglow.png index 2872c61..51d0126 100644 Binary files a/themes/screenshots/alpenglow.png and b/themes/screenshots/alpenglow.png differ diff --git a/themes/screenshots/aritim-dark.png b/themes/screenshots/aritim-dark.png index c7969fa..8f4eb8a 100644 Binary files a/themes/screenshots/aritim-dark.png and b/themes/screenshots/aritim-dark.png differ diff --git a/themes/screenshots/aritim.png b/themes/screenshots/aritim.png index cb9aa9e..aee86f1 100644 Binary files a/themes/screenshots/aritim.png and b/themes/screenshots/aritim.png differ diff --git a/themes/screenshots/autumn.png b/themes/screenshots/autumn.png index 8b65920..ca1bbe1 100644 Binary files a/themes/screenshots/autumn.png and b/themes/screenshots/autumn.png differ diff --git a/themes/screenshots/carnation.png b/themes/screenshots/carnation.png index 18b9ad7..a964fe9 100644 Binary files a/themes/screenshots/carnation.png and b/themes/screenshots/carnation.png differ diff --git a/themes/screenshots/catpuccin.png b/themes/screenshots/catpuccin.png index b38fe37..62e1ff4 100644 Binary files a/themes/screenshots/catpuccin.png and b/themes/screenshots/catpuccin.png differ diff --git a/themes/screenshots/cornflower.png b/themes/screenshots/cornflower.png index d6527ab..d3c85a3 100644 Binary files a/themes/screenshots/cornflower.png and b/themes/screenshots/cornflower.png differ diff --git a/themes/screenshots/default-dark.png b/themes/screenshots/default-dark.png index 7713541..7cb1841 100644 Binary files a/themes/screenshots/default-dark.png and b/themes/screenshots/default-dark.png differ diff --git a/themes/screenshots/default.png b/themes/screenshots/default.png index 8228f51..abfe791 100644 Binary files a/themes/screenshots/default.png and b/themes/screenshots/default.png differ diff --git a/themes/screenshots/ivy.png b/themes/screenshots/ivy.png index 64ba62c..817f5c6 100644 Binary files a/themes/screenshots/ivy.png and b/themes/screenshots/ivy.png differ diff --git a/themes/screenshots/kjoe.png b/themes/screenshots/kjoe.png index 42a247a..6dbc1ce 100644 Binary files a/themes/screenshots/kjoe.png and b/themes/screenshots/kjoe.png differ diff --git a/themes/screenshots/monokai-vibrant.png b/themes/screenshots/monokai-vibrant.png index bd4dcd3..fc2a921 100644 Binary files a/themes/screenshots/monokai-vibrant.png and b/themes/screenshots/monokai-vibrant.png differ diff --git a/themes/screenshots/rainbow.png b/themes/screenshots/rainbow.png index a5fb726..ce6b1d4 100644 Binary files a/themes/screenshots/rainbow.png and b/themes/screenshots/rainbow.png differ diff --git a/themes/screenshots/spring.png b/themes/screenshots/spring.png index b9f103b..c497eee 100644 Binary files a/themes/screenshots/spring.png and b/themes/screenshots/spring.png differ diff --git a/themes/screenshots/steam.png b/themes/screenshots/steam.png index 7df684a..2112848 100644 Binary files a/themes/screenshots/steam.png and b/themes/screenshots/steam.png differ diff --git a/themes/screenshots/summer.png b/themes/screenshots/summer.png index f9abd36..172a2f1 100644 Binary files a/themes/screenshots/summer.png and b/themes/screenshots/summer.png differ diff --git a/themes/screenshots/sunflower.png b/themes/screenshots/sunflower.png index 96008e7..78008ae 100644 Binary files a/themes/screenshots/sunflower.png and b/themes/screenshots/sunflower.png differ diff --git a/themes/screenshots/winter.png b/themes/screenshots/winter.png index 082bc92..6e8652b 100644 Binary files a/themes/screenshots/winter.png and b/themes/screenshots/winter.png differ diff --git a/themes/sunflower.css b/themes/sunflower.css index 3db6714..8bb0f2f 100644 --- a/themes/sunflower.css +++ b/themes/sunflower.css @@ -5,9 +5,9 @@ --color2: #ffd700; --color3: #ffe135; --color4: #ce8c00; - --bcolor1: #ebebeb; + --bcolor1: #171717; --bcolor2: #191919; - --bcolor3: #171717; + --bcolor3: #ebebeb; --bcolor4: #0a0a0a; } @@ -60,7 +60,7 @@ .row a { font-weight: 800; - color: var(--color2); + color: var(--color1); text-decoration: none; } @@ -70,7 +70,7 @@ .tooltiptext { font-weight: 600; - color: var(--bcolor1); + color: var(--bcolor3); background-color: var(--bcolor2); }