From a1381c3fc922b561b328eb48dcaecb33707e4429 Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Mon, 11 Nov 2024 15:49:01 +0000 Subject: [PATCH] feature: tweak console outputs --- src/lib/create_target_dir.py | 8 +++++--- src/lib/generate_index_file.py | 14 ++++++++++---- src/lib/transfer_files.py | 19 ++++++++++++------- src/lib/transform_links.py | 11 ++++++----- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/lib/create_target_dir.py b/src/lib/create_target_dir.py index b7bbb33..fbc997f 100644 --- a/src/lib/create_target_dir.py +++ b/src/lib/create_target_dir.py @@ -1,6 +1,7 @@ import os import shutil import uuid + from termcolor import colored @@ -16,8 +17,8 @@ def create_target_dir(target_dir, source_dir): os.makedirs(f"{target_dir}/{str(unique_dir_name)}") print( colored( - f"  Created new Neuron output directory: {source_dir}/{unique_dir_name}", - "green", + f"SUCCESS Created new Neuron output directory: {source_dir}/{unique_dir_name}", + "light_green", ) ) return unique_dir_name @@ -25,6 +26,7 @@ def create_target_dir(target_dir, source_dir): except Exception as e: print( colored( - f"  Error occurred when creating target directory: {str(e)}", "red" + f"ERROR occurred when creating target directory: {str(e)}", + "light_red", ) ) diff --git a/src/lib/generate_index_file.py b/src/lib/generate_index_file.py index 9a6fc9b..709ed0a 100644 --- a/src/lib/generate_index_file.py +++ b/src/lib/generate_index_file.py @@ -1,5 +1,7 @@ from datetime import datetime + from termcolor import colored + from lib.list_entries import list_entries @@ -13,7 +15,7 @@ def generate_wikilinks(entries): def generate_index_file(target_dir, unique_dir_name, source_dir): try: - print(colored("  Creating index file...", "blue")) + print(colored("INFO Creating index file...", "light_blue")) index_file = f"{target_dir}/index.md" build_date = datetime.now() build_date = build_date.strftime("%a %d %b %Y %H:%M:%S") @@ -28,7 +30,7 @@ def generate_index_file(target_dir, unique_dir_name, source_dir): recent_notes = list_entries(f"{source_dir}/zk") recents = sorted(recent_notes, key=lambda item: item["modified"], reverse=True) - recents = recents[:8] + recents = recents[:12] recents = get_entry_titles(recents) recents_formatted = generate_wikilinks(recents) @@ -46,6 +48,10 @@ def generate_index_file(target_dir, unique_dir_name, source_dir): f.write(note) f.close() - print(colored("  Index file created!", "green")) + print(colored("SUCCESS Index file created", "light_green")) except Exception as e: - print(colored(f"  Error occurred when transferring files: {str(e)}", "red")) + print( + colored( + f"ERROR Error occurred when transferring files: {str(e)}", "light_red" + ) + ) diff --git a/src/lib/transfer_files.py b/src/lib/transfer_files.py index 8507acd..5b3c423 100644 --- a/src/lib/transfer_files.py +++ b/src/lib/transfer_files.py @@ -1,30 +1,35 @@ import shutil + from termcolor import colored def transfer_files(target_dir, source_dir): try: # Copy templates - print(colored("  Copying HTML/MD templates...", "blue")) + print(colored("INFO Copying HTML/MD templates...", "light_blue")) shutil.copytree( f"{source_dir}/.neuron-generator/templates", target_dir, dirs_exist_ok=True ) neuron_template = open(f"{target_dir}/neuron.dhall", "x") neuron_template.close() - print(colored("  Templates transferred!", "green")) + print(colored("SUCCESS Templates transferred", "light_green")) # Copy images to /static - print(colored("  Copying static files...", "blue")) + print(colored("INFO Copying static files...", "light_blue")) shutil.copytree( f"{source_dir}/img", f"{target_dir}/static", ) - print(colored("  Static files transferred!", "green")) + print(colored("SUCCESS Static files transferred", "light_green")) - print(colored("  Copying zettels...", "blue")) + print(colored("INFO Copying zettels...", "light_blue")) # Copy notes shutil.copytree(f"{source_dir}/zk", f"{target_dir}", dirs_exist_ok=True) - print(colored("  Zettels transferred!", "green")) + print(colored("SUCCESS Zettels transferred", "light_green")) except Exception as e: - print(colored(f"  Error occurred when transferring files: {str(e)}", "red")) + print( + colored( + f"ERROR Error occurred when transferring files: {str(e)}", "light_red" + ) + ) diff --git a/src/lib/transform_links.py b/src/lib/transform_links.py index a152c1d..d94cef5 100644 --- a/src/lib/transform_links.py +++ b/src/lib/transform_links.py @@ -1,5 +1,6 @@ import os import re + from termcolor import colored image_rgx = r"!\[.*?\]\((.*?)\)" @@ -11,16 +12,16 @@ def process_image_links(line, links): stripped_img_ref = re.search(r"[^/\\]+$", link) if stripped_img_ref: stripped_img_ref = stripped_img_ref.group() - new_img_ref = f"/static/{stripped_img_ref}" + new_img_ref = f"static/{stripped_img_ref}" line = line.replace(f"({link})", f"({new_img_ref})") # print(colored(f"  {links}", "green")) return line except Exception as e: - print(colored(f" Error when transforming link: {str(e)}", "red")) + print(colored(f"ERROR Error when transforming link: {str(e)}", "light_red")) def transform_links(target_dir): - print(colored("  Updating links...", "blue")) + print(colored("INFO: Updating links...", "light_blue")) for filename in os.listdir(target_dir): if filename.endswith(".md"): file_path = os.path.join(target_dir, filename) @@ -44,7 +45,7 @@ def transform_links(target_dir): f.writelines(new_lines) print( colored( - "  Links updated!", - "green", + "SUCCESS Links updated", + "light_green", ) )