From b9ad8dbf6a04f637b7c05f3f94831a20ccbc4b7e Mon Sep 17 00:00:00 2001 From: ful1e5 <24286590+ful1e5@users.noreply.github.com> Date: Sat, 10 Oct 2020 17:20:01 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Separate=20configs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder/bundler.py | 25 +++++++++++++------------ builder/config.py | 9 ++++++--- builder/cursor.py | 29 ++++++++++++++--------------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/builder/bundler.py b/builder/bundler.py index c07b2373..1d8ee474 100644 --- a/builder/bundler.py +++ b/builder/bundler.py @@ -31,14 +31,15 @@ class Bundler(): Create crisp package for Bibata Windows & X11 packages 📦. """ - def __init__(self, theme_name: str, config: ConfigProvider) -> None: + def __init__(self, config: ConfigProvider) -> None: """ docsstring """ - self.__name = theme_name - self.__x11_dest = path.join(config.out_dir, theme_name) - self.__win_dest = path.join(config.out_dir, theme_name + "-Windows") - self.__content = config.get_windows_script(theme_name) + self.__name = config.name + self.__tmpdir = config.tmpdir + self.__x11_dest = path.join(config.out_dir, self.__name) + self.__win_dest = path.join(config.out_dir, self.__name + "-Windows") + self.__content = config.get_windows_script() def __save_win_install_script(self) -> None: """ @@ -65,28 +66,28 @@ class Bundler(): self.__save_win_install_script() - def win_bundle(self, tempdir) -> None: + def win_bundle(self) -> None: """ docstring """ - src = path.join(tempdir, self.__name, "win") + src = path.join(self.__tmpdir, self.__name, "win") shutil.copytree(src, self.__win_dest) self.__clean_win_bundle() - def x11_bundle(self, tempdir) -> None: + def x11_bundle(self) -> None: """ docstring """ - src = path.join(tempdir, self.__name, "x11") + src = path.join(self.__tmpdir, self.__name, "x11") shutil.copytree(src, self.__x11_dest, symlinks=True) - def bundle(self, tempdir) -> None: + def bundle(self) -> None: """ docstring """ - x11_src = path.join(tempdir, self.__name, "x11") + x11_src = path.join(self.__tmpdir, self.__name, "x11") shutil.copytree(x11_src, self.__x11_dest, symlinks=True) - win_src = path.join(tempdir, self.__name, "win") + win_src = path.join(self.__tmpdir, self.__name, "win") shutil.copytree(win_src, self.__win_dest) self.__clean_win_bundle() diff --git a/builder/config.py b/builder/config.py index 18a8c261..6c9b37cf 100644 --- a/builder/config.py +++ b/builder/config.py @@ -5,6 +5,7 @@ import sys import json import shutil from os import path, mkdir +import tempfile from . import __path__, __author__ @@ -22,7 +23,7 @@ class ConfigProvider(): Configure `Bibata` building process 🔧. """ - def __init__(self, bitmaps_dir: str, out_dir: str) -> None: + def __init__(self, name: str, bitmaps_dir: str, out_dir: str) -> None: """ docsstring """ @@ -38,16 +39,18 @@ class ConfigProvider(): "⚠ BITMAPS NOT FOUND.\n\n`yarn install && yarn render` to Generates Bitmaps") sys.exit(1) + self.name: str = name self.bitmaps_dir: str = path.abspath(bitmaps_dir) + self.tmpdir: str = tempfile.mkdtemp() self.out_dir: str = path.abspath(out_dir) - def get_windows_script(self, theme_name: str) -> str: + def get_windows_script(self) -> str: """ docsstring """ with open(path.join(__path__[0], "windows.inf")) as f: data = f.read() inf_content = data.replace( - "", theme_name+" Cursors").replace("", __author__) + "", self.name+" Cursors").replace("", __author__) return inf_content diff --git a/builder/cursor.py b/builder/cursor.py index aaacebec..b9da9bd8 100644 --- a/builder/cursor.py +++ b/builder/cursor.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import tempfile 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 @@ -12,14 +11,14 @@ class CursorBuilder(): Build Bibata Windows & X11 cursors 🚀. """ - def __init__(self, name: str, config: ConfigProvider) -> None: + def __init__(self, config: ConfigProvider) -> None: """ docstring """ - self.__name = name - self.__config = config - self.__bundler = Bundler(name, config) - self.tmpdir = tempfile.mkdtemp() + self.__name = config.name + self.__bitmaps_dir = config.bitmaps_dir + self.__bundler = Bundler(config) + self.__tmpdir = config.tmpdir def build_x11_cursors(self) -> None: """ @@ -28,15 +27,15 @@ class CursorBuilder(): print('🌈 Building %s Theme ...' % self.__name) build_x11_cursor_theme( name=self.__name, - image_dir=self.__config.bitmaps_dir, + image_dir=self.__bitmaps_dir, cursor_sizes=sizes, hotspots=hotspots, - out_path=self.tmpdir, + out_path=self.__tmpdir, archive=False, delay=delay ) - self.__bundler.x11_bundle(self.tmpdir) + self.__bundler.x11_bundle() def build_win_cursors(self) -> None: """ @@ -45,15 +44,15 @@ class CursorBuilder(): print('🌈 Building %s Theme ...' % self.__name) build_win_cursor_theme( name=self.__name, - image_dir=self.__config.bitmaps_dir, + image_dir=self.__bitmaps_dir, cursor_sizes=sizes, hotspots=hotspots, - out_path=self.tmpdir, + out_path=self.__tmpdir, archive=False, delay=delay ) - self.__bundler.win_bundle(self.tmpdir) + self.__bundler.win_bundle() def build_cursors(self) -> None: """ @@ -62,12 +61,12 @@ class CursorBuilder(): print('🌈 Building %s Theme ...' % self.__name) build_cursor_theme( name=self.__name, - image_dir=self.__config.bitmaps_dir, + image_dir=self.__bitmaps_dir, cursor_sizes=sizes, hotspots=hotspots, - out_path=self.tmpdir, + out_path=self.__tmpdir, archive=False, delay=delay ) - self.__bundler.bundle(self.tmpdir) + self.__bundler.bundle()