apple_cursor/helper.py

76 lines
2.1 KiB
Python
Raw Normal View History

2020-07-29 01:03:52 -04:00
import shutil
2020-08-02 10:20:17 -04:00
import json
import sys
2020-07-29 01:03:52 -04:00
2020-08-10 01:56:24 -04:00
from config import name, temp_folder, bitmaps_dir, win_out, x11_out, window_install_inf, windows_cursors
from os import path, listdir, rename, remove
2020-07-29 01:03:52 -04:00
package_dir = "./packages"
x11_out_dir = path.join(package_dir, x11_out)
win_out_dir = path.join(package_dir, win_out)
2020-08-09 09:26:33 -04:00
def window_bundle() -> None:
2020-08-10 01:56:24 -04:00
# Remove & Rename cursors
# If Key found => Rename else Remove
for cursor in listdir(win_out_dir):
old_path = path.join(win_out_dir, cursor)
try:
new_path = path.join(win_out_dir, windows_cursors[cursor])
rename(old_path, new_path)
except KeyError:
remove(old_path)
# creating install.inf file
install_inf_path = path.join(win_out_dir, "install.inf")
with open(install_inf_path, "w") as file:
file.write(install_inf_path)
2020-08-09 09:26:33 -04:00
2020-07-29 01:03:52 -04:00
def init_build() -> None:
2020-07-29 01:11:11 -04:00
"""
2020-08-02 10:20:17 -04:00
Print build version.
Remove previously built packages && Check Bitmaps.
2020-07-29 01:11:11 -04:00
"""
2020-08-02 10:20:17 -04:00
with open("./package.json", "r") as package_file:
data = json.loads(package_file.read())
version = data['version']
print("⚡ Build Version %s" % version)
# cleanup old packages
2020-07-29 01:03:52 -04:00
if path.exists(package_dir):
shutil.rmtree(package_dir)
2020-08-02 10:20:17 -04:00
# Checking Bitmaps directory
if not path.exists(bitmaps_dir):
print(
2020-07-31 02:02:31 -04:00
"⚠ BITMAPS NOT FOUND.\n\n`yarn install && yarn render` to Generates Bitmaps")
sys.exit(1)
2020-07-29 01:03:52 -04:00
2020-07-29 01:11:11 -04:00
def pack_it() -> None:
2020-07-29 01:03:52 -04:00
"""
2020-07-29 01:11:11 -04:00
Create Crisp 📦 Packages for Windows & X11 Cursor Theme.
2020-07-29 01:03:52 -04:00
"""
# Rename directory
shutil.move(path.join(temp_folder, name, "x11"), x11_out_dir)
shutil.move(path.join(temp_folder, name, "win"), win_out_dir)
2020-08-09 09:26:33 -04:00
# create install.inf file in Windows Theme
window_bundle()
2020-07-29 01:03:52 -04:00
# Packaging
# - .tar archive for X11
# - .zip archive for Windows
shutil.make_archive(x11_out_dir, "tar", x11_out_dir)
shutil.make_archive(win_out_dir, "zip", win_out_dir)
# Clenaup
shutil.rmtree(temp_folder)
for f in listdir(package_dir):
f_path = path.join(package_dir, f)
if path.isdir(f_path):
shutil.rmtree(f_path)