add-font.py helper for the repo.
This commit is contained in:
parent
5a1f46b683
commit
a2b7cf2226
1 changed files with 52 additions and 5 deletions
57
add-font.py
57
add-font.py
|
|
@ -2,6 +2,8 @@ import os
|
|||
import hashlib
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
def get_font_files(font_folder):
|
||||
|
|
@ -32,7 +34,7 @@ def create_zip(font_files, font_folder, zip_path):
|
|||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
for file in font_files:
|
||||
# Add the font file with its relative path
|
||||
arcname = os.path.relpath(file, font_folder) # Now using font_folder
|
||||
arcname = os.path.relpath(file, font_folder)
|
||||
zipf.write(file, arcname)
|
||||
print(f"Added {file} to the zip as {arcname}")
|
||||
|
||||
|
|
@ -60,6 +62,33 @@ end
|
|||
formula_file.write(formula_content)
|
||||
print(f"Ruby file created at {formula_path}")
|
||||
|
||||
return formula_path
|
||||
|
||||
|
||||
def move_formula_to_formula_folder(formula_path):
|
||||
"""Move the formula file to the Formula directory in the tap."""
|
||||
formula_folder = "./Formula"
|
||||
if not os.path.exists(formula_folder):
|
||||
os.makedirs(formula_folder)
|
||||
|
||||
shutil.move(formula_path, os.path.join(formula_folder, os.path.basename(formula_path)))
|
||||
print(f"Moved {formula_path} to {formula_folder}/")
|
||||
|
||||
|
||||
def commit_and_push_changes(font_name):
|
||||
"""Commit and push the changes to the GitHub repository."""
|
||||
print(f"Committing and pushing changes for {font_name}...")
|
||||
subprocess.run(["git", "add", "Formula"], check=True)
|
||||
subprocess.run(["git", "commit", "-m", f"Add {font_name} font"], check=True)
|
||||
subprocess.run(["git", "push", "origin", "main"], check=True)
|
||||
print("Changes pushed to GitHub.")
|
||||
|
||||
|
||||
def font_exists(font_name):
|
||||
"""Check if the formula already exists in the Formula folder."""
|
||||
formula_path = f"./Formula/font-{font_name.lower()}.rb"
|
||||
return os.path.exists(formula_path)
|
||||
|
||||
|
||||
def main():
|
||||
font_folder = input("Enter the location of the font folder: ").strip()
|
||||
|
|
@ -75,18 +104,36 @@ def main():
|
|||
|
||||
font_name = input("Enter the name of the font (e.g., FiraCode): ").strip()
|
||||
|
||||
# Add the "font-" prefix to the font name
|
||||
font_package_name = f"font-{font_name.lower()}"
|
||||
|
||||
# Check if the font already exists in the Formula folder
|
||||
if font_exists(font_name):
|
||||
update = input(
|
||||
f"The font '{font_package_name}' already exists. Do you want to update it? (y/n): ").strip().lower()
|
||||
if update != 'y':
|
||||
print("Font update canceled.")
|
||||
return
|
||||
|
||||
# Create the folder for the font
|
||||
font_folder_path = Path(f"./{font_name.lower()}")
|
||||
font_folder_path = Path(f"./{font_package_name}")
|
||||
font_folder_path.mkdir(exist_ok=True)
|
||||
|
||||
zip_path = f"./{font_name.lower()}/{font_name.lower()}.zip"
|
||||
zip_path = f"./{font_package_name}/{font_package_name}.zip"
|
||||
create_zip(font_files, font_folder, zip_path)
|
||||
|
||||
sha256_hash = generate_sha256(zip_path)
|
||||
print(f"SHA256 hash generated: {sha256_hash}")
|
||||
|
||||
create_ruby_file(font_name, zip_path, sha256_hash)
|
||||
print(f"Font {font_name} has been added successfully.")
|
||||
formula_path = create_ruby_file(font_package_name, zip_path, sha256_hash)
|
||||
|
||||
# Move the formula to the Formula directory
|
||||
move_formula_to_formula_folder(formula_path)
|
||||
|
||||
# Commit and push the changes to the tap repository
|
||||
commit_and_push_changes(font_package_name)
|
||||
|
||||
print(f"Font {font_package_name} has been added successfully.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue