From c617bf3756e10751a3599d4aa320bf47fe1dbb54 Mon Sep 17 00:00:00 2001 From: ful1e5 <24286590+ful1e5@users.noreply.github.com> Date: Fri, 9 Oct 2020 12:47:47 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20CursorBuilder=20module=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder/cursor.py | 95 +++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 69 deletions(-) diff --git a/builder/cursor.py b/builder/cursor.py index 0b310f4e..add44f4d 100644 --- a/builder/cursor.py +++ b/builder/cursor.py @@ -1,11 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import tempfile -import shutil -from os import path, listdir, rename, remove, makedirs - -from .config import ConfigProvider +from .bundler import Bundler +from .config import ConfigProvider, hotspots, sizes, delay from clickgen import build_x11_cursor_theme, build_cursor_theme, build_win_cursor_theme @@ -14,89 +11,49 @@ class CursorBuilder(): Bibata cursors builder 🚀 """ - def __init__(self, name: str, config: ConfigProvider): - self.__config = config + def __init__(self, name: str, config: ConfigProvider) -> None: self.__name = name - self.__x11_out = name - self.__windows_out = name + "-" + "Windows" - self.__temp_out_dir = tempfile.mkdtemp() + self.__config = config + self.__bundler = Bundler(name, config) - def __window_bundle(self, win_theme_dir: str): - # Remove & Rename cursors - # If Key found => Rename else Remove - for cursor in listdir(win_theme_dir): - old_path = path.join(win_theme_dir, cursor) - - try: - new_path = path.join( - win_theme_dir, self.__config.windows_cursors[cursor]) - rename(old_path, new_path) - except KeyError: - remove(old_path) - - # creating install.inf file - install_inf_path = path.join(win_theme_dir, "install.inf") - content = self.__config.get_windows_script( - theme_name=self.__name, author="Kaiz Khatri") - - with open(install_inf_path, "w") as file: - file.write(content) - - def __pack_win(self): - win_out_dir = path.join(self.__config.out_dir, self.__windows_out) - cur_dir = path.join(self.__temp_out_dir, self.__name, "win") - - src = path.abspath(cur_dir) - dest = path.abspath(win_out_dir) - shutil.move(src, dest) - - # create install.inf file in Windows Theme - self.__window_bundle(win_theme_dir=dest) - - def __pack_x11(self): - x11_out_dir = path.join(self.__config.out_dir, self.__x11_out) - cur_dir = path.join(self.__temp_out_dir, self.__name, "x11") - - src = path.abspath(cur_dir) - dest = path.abspath(x11_out_dir) - shutil.move(src, dest) - - def build_x11_cursors(self): + def build_x11_cursors(self) -> None: print('🌈 Building %s Theme ...' % self.__name) build_x11_cursor_theme( name=self.__name, image_dir=self.__config.bitmaps_dir, - cursor_sizes=self.__config.sizes, - hotspots=self.__config.hotspots, - out_path=self.__temp_out_dir, + cursor_sizes=sizes, + hotspots=hotspots, + out_path=self.__config.temp_out_dir, archive=False, - delay=self.__config.delay + delay=delay ) - self.__pack_x11() - def build_win_cursors(self): + self.__bundler.x11_bundle() + + def build_win_cursors(self) -> None: print('🌈 Building %s Theme ...' % self.__name) build_win_cursor_theme( name=self.__name, image_dir=self.__config.bitmaps_dir, - cursor_sizes=self.__config.sizes, - hotspots=self.__config.hotspots, - out_path=self.__temp_out_dir, + cursor_sizes=sizes, + hotspots=hotspots, + out_path=self.__config.temp_out_dir, archive=False, - delay=self.__config.delay + delay=delay ) - self.__pack_win() - def build_cursors(self): + self.__bundler.win_bundle() + + def build_cursors(self) -> None: print('🌈 Building %s Theme ...' % self.__name) build_cursor_theme( name=self.__name, image_dir=self.__config.bitmaps_dir, - cursor_sizes=self.__config.sizes, - hotspots=self.__config.hotspots, - out_path=self.__temp_out_dir, + cursor_sizes=sizes, + hotspots=hotspots, + out_path=self.__config.temp_out_dir, archive=False, - delay=self.__config.delay + delay=delay ) - self.__pack_x11() - self.__pack_win() + + self.__bundler.bundle()