fix: rework zipping of files, better build CI
Thanks to @npv12 for this PR!
This commit is contained in:
@@ -1,77 +1,84 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from typing import List
|
||||
|
||||
from scripts.ctp_colors import ctp_colors
|
||||
from scripts.recolor import recolor
|
||||
from scripts.utils import zip_multiple_folders
|
||||
from scripts.var import def_color_map, theme_name, tmp_dir, work_dir
|
||||
|
||||
|
||||
def create_theme(type: str, accent: str, dest: str = tmp_dir, link: bool = False, name: str = theme_name, size: str = "standard", tweaks=[]) -> str:
|
||||
def create_theme(types: List[str], accents: List[str], dest: str = tmp_dir, link: bool = False,
|
||||
name: str = theme_name, size: str = "standard", tweaks=[], zip = False) -> None:
|
||||
|
||||
try:
|
||||
os.makedirs(tmp_dir) # Create our temporary directory
|
||||
os.makedirs(dest) # Create our destination directory
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
# Recolor colloid wrt our selection like mocha. latte
|
||||
recolor(ctp_colors[type], accent)
|
||||
theme_style: str = "light" if type == "latte" else "dark"
|
||||
install_cmd: str = f"./install.sh -c {theme_style} -s {size} -n {name} -d {dest} -t {def_color_map[accent]}"
|
||||
if tweaks:
|
||||
install_cmd += f" --tweaks {' '.join([tweak for tweak in tweaks])}"
|
||||
|
||||
os.chdir(work_dir)
|
||||
# Install the theme globally for you
|
||||
subprocess.call(install_cmd, shell=True)
|
||||
# reset colloid repo to original state
|
||||
subprocess.call("git reset --hard HEAD", shell=True)
|
||||
for type in types:
|
||||
for accent in accents:
|
||||
# Recolor colloid wrt our selection like mocha. latte
|
||||
print(type, accent)
|
||||
recolor(ctp_colors[type], accent)
|
||||
theme_style: str = "light" if type == "latte" else "dark"
|
||||
install_cmd: str = f"./install.sh -c {theme_style} -s {size} -n {name} -d {dest} -t {def_color_map[accent]}"
|
||||
if tweaks:
|
||||
install_cmd += f" --tweaks {' '.join([tweak for tweak in tweaks])}"
|
||||
|
||||
try:
|
||||
# Rename colloid generated files as per catppuccin
|
||||
new_filename = f"{theme_name}-{type.capitalize()}-{size.capitalize()}-{accent.capitalize()}"
|
||||
filename = f"{theme_name}"
|
||||
if def_color_map[accent] != 'default':
|
||||
filename += f"-{def_color_map[accent].capitalize()}"
|
||||
filename += f"-{theme_style.capitalize()}"
|
||||
if size == 'compact':
|
||||
filename += '-Compact'
|
||||
try:
|
||||
shutil.rmtree(dest + "/" + new_filename + '-hdpi')
|
||||
shutil.rmtree(dest + "/" + new_filename + '-xhdpi')
|
||||
shutil.rmtree(dest + "/" + new_filename)
|
||||
except:
|
||||
pass
|
||||
os.rename(dest + "/" + filename + '-hdpi',
|
||||
dest + "/" + new_filename + '-hdpi')
|
||||
os.rename(dest + "/" + filename + '-xhdpi',
|
||||
dest + "/" + new_filename + '-xhdpi')
|
||||
os.rename(dest + "/" + filename, dest + "/" + new_filename)
|
||||
print("Successfully renamed file")
|
||||
except Exception as e:
|
||||
print("Failed to rename the files due to:", e)
|
||||
return ""
|
||||
|
||||
if link:
|
||||
try:
|
||||
# Attempte relinking all the libadvaita files
|
||||
subprocess.call(
|
||||
'rm -rf "${HOME}/.config/gtk-4.0/"{assets,gtk.css,gtk-dark.css}', shell=True)
|
||||
HOME = os.path.expanduser('~')
|
||||
os.chdir(work_dir)
|
||||
# Install the theme globally for you
|
||||
subprocess.call(install_cmd, shell=True)
|
||||
# reset colloid repo to original state
|
||||
subprocess.call("git reset --hard HEAD", shell=True)
|
||||
|
||||
try:
|
||||
os.makedirs(f"{HOME}/.config/gtk-4.0")
|
||||
except FileExistsError:
|
||||
pass
|
||||
os.symlink(f"{dest + '/' + new_filename}/gtk-4.0/assets",
|
||||
f"{HOME}/.config/gtk-4.0/assets")
|
||||
os.symlink(f"{dest + '/' + new_filename}/gtk-4.0/gtk.css",
|
||||
f"{HOME}/.config/gtk-4.0/gtk.css")
|
||||
os.symlink(f"{dest + '/' + new_filename}/gtk-4.0/gtk-dark.css",
|
||||
f"{HOME}/.config/gtk-4.0/gtk-dark.css")
|
||||
print("Successfully created symlinks for libadvaita")
|
||||
except Exception as e:
|
||||
print("Failed to link due to :", e)
|
||||
return ""
|
||||
# Rename colloid generated files as per catppuccin
|
||||
new_filename = dest + \
|
||||
f"/{theme_name}-{type.capitalize()}-{size.capitalize()}-{accent.capitalize()}"
|
||||
filename = f"{theme_name}"
|
||||
if def_color_map[accent] != 'default':
|
||||
filename += f"-{def_color_map[accent].capitalize()}"
|
||||
filename += f"-{theme_style.capitalize()}"
|
||||
if size == 'compact':
|
||||
filename += '-Compact'
|
||||
try:
|
||||
shutil.rmtree(new_filename + '-hdpi')
|
||||
shutil.rmtree(new_filename + '-xhdpi')
|
||||
shutil.rmtree(new_filename)
|
||||
except:
|
||||
pass
|
||||
os.rename(dest + "/" + filename + '-hdpi',
|
||||
new_filename + '-hdpi')
|
||||
os.rename(dest + "/" + filename + '-xhdpi',
|
||||
new_filename + '-xhdpi')
|
||||
os.rename(dest + "/" + filename, new_filename)
|
||||
print("Successfully renamed file")
|
||||
except Exception as e:
|
||||
print("Failed to rename the files due to:", e)
|
||||
|
||||
return new_filename
|
||||
if link:
|
||||
try:
|
||||
# Attempte relinking all the libadvaita files
|
||||
subprocess.call(
|
||||
'rm -rf "${HOME}/.config/gtk-4.0/"{assets,gtk.css,gtk-dark.css}', shell=True)
|
||||
HOME = os.path.expanduser('~')
|
||||
|
||||
try:
|
||||
os.makedirs(f"{HOME}/.config/gtk-4.0")
|
||||
except FileExistsError:
|
||||
pass
|
||||
os.symlink(f"{new_filename}/gtk-4.0/assets",
|
||||
f"{HOME}/.config/gtk-4.0/assets")
|
||||
os.symlink(f"{new_filename}/gtk-4.0/gtk.css",
|
||||
f"{HOME}/.config/gtk-4.0/gtk.css")
|
||||
os.symlink(f"{new_filename}/gtk-4.0/gtk-dark.css",
|
||||
f"{HOME}/.config/gtk-4.0/gtk-dark.css")
|
||||
print("Successfully created symlinks for libadvaita")
|
||||
except Exception as e:
|
||||
print("Failed to link due to :", e)
|
||||
|
||||
if zip:
|
||||
foldernames = [new_filename, new_filename + '-xhdpi', new_filename + '-hdpi']
|
||||
zip_multiple_folders(foldernames, new_filename + ".zip", not link)
|
||||
|
@@ -7,9 +7,9 @@ ctp_colors = {
|
||||
"macchiato": Flavour.macchiato()
|
||||
}
|
||||
|
||||
def get_all_accent(flavor):
|
||||
def get_all_accent():
|
||||
accent = {}
|
||||
for key, value in flavor.__dict__.items():
|
||||
for key, value in Flavour.latte().__dict__.items():
|
||||
if key not in ['white', 'black', 'text', 'subtext0', 'subtext1', 'overlay0', 'overlay1', 'overlay2', 'surface0', 'surface1', 'surface2', 'base', 'mantle', 'crust']:
|
||||
accent[key] = value
|
||||
|
||||
|
@@ -1,4 +1,7 @@
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import zipfile
|
||||
|
||||
|
||||
def replacetext(file_name: str, search_text: str, replace_text: str) -> None:
|
||||
@@ -20,3 +23,25 @@ def replacetext(file_name: str, search_text: str, replace_text: str) -> None:
|
||||
f.seek(0)
|
||||
f.write(file)
|
||||
f.truncate()
|
||||
|
||||
|
||||
def zipdir(path, ziph):
|
||||
"""
|
||||
Takes in a oath of a directory and zips it in a ziph.
|
||||
Util to zip a directory.
|
||||
Thanks https://stackoverflow.com/questions/46229764/python-zip-multiple-directories-into-one-zip-file
|
||||
"""
|
||||
for root, _, files in os.walk(path):
|
||||
for file in files:
|
||||
ziph.write(os.path.join(root, file),
|
||||
os.path.relpath(os.path.join(root, file),
|
||||
os.path.join(path, '..')))
|
||||
|
||||
|
||||
def zip_multiple_folders(dir_list, zip_name, remove = True):
|
||||
zipf = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED)
|
||||
for dir in dir_list:
|
||||
zipdir(dir, zipf)
|
||||
if remove:
|
||||
shutil.rmtree(dir)
|
||||
zipf.close()
|
||||
|
Reference in New Issue
Block a user