updated structure a bit.

This commit is contained in:
Matt Troutman 2024-10-02 16:37:20 -05:00
parent 46156f7bdd
commit 358e94cde7
No known key found for this signature in database
7 changed files with 61 additions and 15 deletions

View file

@ -0,0 +1,76 @@
import requests, os
GITEA_URL = "https://git.trtmn.io"
API_TOKEN = "315d5a6d692eeea061f714725f0d116b819ea62b"
organization = "fonts"
headers = {
"Authorization": f"token {API_TOKEN}",
"Content-Type": "application/json"
}
def get_folders_in_folder(path="./font_files"):
return [file for file in os.listdir(path) if os.path.isdir(os.path.join(path, file))]
folders = ["folder-1", "folder-2", "folder-3", "folder-4", "folder-5"]
# def make_local_repos(folder_list=folders):
# for folder in folder_list:
# # Create a local folder
# print(f"Creating folder {folder}")
# os.makedirs(folder, exist_ok=True)
# # Create a README.md file in the folder
# with open(f"{folder}/README.md", "w") as f:
# f.write(f"# {folder}\n\nThis is a repo for {folder}")
# #git init
# os.system(f"cd {folder} && git init")
# #git create branch "main" and switch to it
# os.system(f"cd {folder} && git checkout -b main")
# #git add README.md
# os.system(f"cd {folder} && git add README.md")
# #git commit -m "Initial commit"
# os.system(f"cd {folder} && git commit -m 'Initial commit'")
# #git remote add origin
# os.system(f"cd {folder} && git remote add origin {GITEA_URL}/{organization}/{folder}.git")
# #git push -u origin master
# os.system(f"cd {folder} && git push --force -u origin main")
# def clone_repos(folder_list=folders):
# for folder in folder_list:
# os.system(f"git clone {GITEA_URL}/{organization}/{folder}.git")
def add_as_submodule(folder_list=folders):
for folder in folder_list:
os.system(f"git submodule add {GITEA_URL}/{organization}/{folder}.git")
def create_repos(folder_list=folders):
for folder in folder_list:
data = {
"name": folder,
"description": f"Repo for {folder}",
"private": False,
"auto_init": True
}
response = requests.post(f"{GITEA_URL}/api/v1/orgs/{organization}/repos", json=data, headers=headers)
if response.status_code == 201:
print(f"Successfully created repo for {folder}")
else:
print(f"Failed to create repo for {folder}: {response.status_code} {response.text}")
def delete_repos(folder_list=folders):
for folder in folder_list:
response = requests.delete(f"{GITEA_URL}/api/v1/repos/{organization}/{folder}", headers=headers)
if response.status_code == 204:
print(f"Successfully deleted repo for {folder}")
else:
print(f"Failed to delete repo for {folder}: {response.status_code} {response.text}")
if __name__ == '__main__':
# create_repos()
# make_local_repos()
# add_as_submodule()
# delete_repos()
print(get_folders_in_folder())

View file

@ -3,6 +3,8 @@ import time
from fileinput import filename
repo_location = '/Users/fishy/custom_fonts'
os.system(f"cd ")
font_location = f'{repo_location}/font_files'
bad_phrases = [' Free',

View file

@ -0,0 +1,51 @@
import os
import subprocess
import sys
def main():
mydir = os.path.dirname(__file__)
# Define the absolute path to the prep script
prep_script = os.path.join(mydir, 'prep 1 font.sh')
# Activate python environment
env_activate = os.path.join(mydir, '.env/bin/activate')
subprocess.run(['source', env_activate], shell=True, check=True)
# Move orphans before we do anything else
orphans_script = os.path.join(mydir, 'orphans.py')
subprocess.run(['python3', orphans_script], check=True)
# Check if the prep script exists
if not os.path.isfile(prep_script):
print(f"Prep script not found: {prep_script}")
sys.exit(1)
# Ensure the prep script is executable
os.chmod(prep_script, 0o755)
# Check if the prep script is executable
if not os.access(prep_script, os.X_OK):
print(f"Prep script not executable: {prep_script}")
sys.exit(1)
# Define the absolute path to the font_files directory
font_files_dir = os.path.join(mydir, 'font_files')
# Check if the font_files directory exists
if not os.path.isdir(font_files_dir):
print(f"font_files directory not found: {font_files_dir}")
sys.exit(1)
# Iterate over each folder in font_files
for folder in os.listdir(font_files_dir):
folder_path = os.path.join(font_files_dir, folder)
if os.path.isdir(folder_path):
os.chdir(folder_path)
subprocess.run(['zsh', prep_script], check=True)
os.chdir('..')
else:
print(f"No such directory: {folder}")
if __name__ == '__main__':
main()

View file

@ -0,0 +1,47 @@
#!/bin/zsh
mydir=$(dirname "$0")
# Define the absolute path to the prep script
PREP_SCRIPT="$(cd "$(dirname "$0")" && pwd)/prep 1 font.sh"
#activate python environment
source "$mydir"/.env/bin/activate
#move orphans before we do anything else
python3 "$mydir"/orphans.py
# Check if the prep script exists
if [[ ! -f "$PREP_SCRIPT" ]]; then
echo "Prep script not found: $PREP_SCRIPT"
exit 1
fi
# Ensure the prep script is executable
chmod u+x "$PREP_SCRIPT"
# Check if the prep script is executable
if [[ ! -x "$PREP_SCRIPT" ]]; then
echo "Prep script not executable: $PREP_SCRIPT"
exit 1
fi
# Define the absolute path to the font_files directory
FONT_FILES_DIR="$(cd "$(dirname "$0")" && pwd)/font_files"
# Check if the font_files directory exists
if [[ ! -d "$FONT_FILES_DIR" ]]; then
echo "font_files directory not found: $FONT_FILES_DIR"
exit 1
fi
# Iterate over each folder in font_files
for folder in "$FONT_FILES_DIR"/*; do
if [[ -d "$folder" ]]; then
cd "$folder" || continue
zsh "$PREP_SCRIPT"
cd ..
else
echo "No such directory: $folder"
fi
done

View file

@ -0,0 +1,21 @@
import os
# Define the absolute path to the font_files directory
FONT_FILES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'font_files')
# find all files that are otfs or ttfs at the root of the font_files directory
def handle_orphans(font_files_dir=FONT_FILES_DIR):
FONT_FILES = [file for file in os.listdir(FONT_FILES_DIR) if file.endswith('.otf') or file.endswith('.ttf')]
print(FONT_FILES)
for file in FONT_FILES:
#create a directory for the file
new_dir_path = os.path.join(FONT_FILES_DIR, file.split('.')[0])
if not os.path.exists(new_dir_path):
os.mkdir(new_dir_path)
print(f"Created directory: {new_dir_path}")
#move the file to the directory
new_file_path = os.path.join(new_dir_path, file)
os.rename(os.path.join(FONT_FILES_DIR, file), new_file_path)
print(f"Moved {file} to {new_file_path}")
if __name__ == '__main__':
handle_orphans()

View file

@ -0,0 +1,48 @@
#! /bin/zsh
#uncomment if you want to delete all .setup_complete files and process everything
#find . -name '*.setup_complete' -type f -delete
#if file name .setup_complete exists, exit
if [ -f .setup_complete ]; then
echo "This folder has already been prepped. Please delete the .setup_complete file if you would like to run this script again."
exit
fi
#if current working directory is named font_files or custom_fonts, exit
if [[ $PWD == *"font_files" ]] || [[ $PWD == *"custom_fonts" ]]; then
echo "You are in the wrong directory. Please move to the individual font folder."
exit
fi
#recursively find all .zip files and unzip them
find . -name '*.zip' -exec unzip {} \;
# Make otf and ttf folders if they don't exist
mkdir -p otf ttf "other files"
# Recurse through all folders and subfolders and move files that are not .ttf or .otf into the "other files" folder
find . -type f -exec mv {} "other files" \;
# Recurse through all folders and subfolders and delete all .DS_Store files
find . -name '.DS_Store' -type f -delete
# Recurse through all folders and subfolders and delete all .g2n files
find . -name '*.g2n' -type f -delete
find . -name '*.ofm' -type f -delete
find . -name '*.cfg' -type f -delete
find . -name '*.zip' -type f -delete
# Recurse through all folders and subfolders and move all .ttf files into the ttf folder
find . -name '*.ttf' -type f -exec mv {} ttf \;
# Recurse through all folders and subfolders and move all .ttc files into the ttf folder
find . -name '*.ttc' -type f -exec mv {} ttf \;
# Recurse through all folders and subfolders and move all .otf files into the otf folder
find . -name '*.otf' -type f -exec mv {} otf \;
# Recurse through all folders and subfolders and delete all empty folders
find . -type d -empty -delete
# create a .setup_complete file to indicate that the folder has been prepped
touch .setup_complete