feature: tweak console outputs

This commit is contained in:
thomasabishop 2024-11-11 15:49:01 +00:00
parent f9e11e2b71
commit a1381c3fc9
4 changed files with 33 additions and 19 deletions

View file

@ -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",
)
)

View file

@ -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"
)
)

View file

@ -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"
)
)

View file

@ -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",
)
)