mirror of
https://github.com/imarkoff/Marble-shell-theme.git
synced 2025-09-18 09:17:54 -07:00
Fixed GDM installation, reworked label_files.py, fixed theme removing
This commit is contained in:
@@ -33,10 +33,11 @@ def main():
|
|||||||
|
|
||||||
if args.remove or args.reinstall:
|
if args.remove or args.reinstall:
|
||||||
installer.remove()
|
installer.remove()
|
||||||
else:
|
|
||||||
|
if not args.remove:
|
||||||
installer.install()
|
installer.install()
|
||||||
|
|
||||||
if not args.gdm and args.remove == args.reinstall:
|
if not args.gdm and not args.remove:
|
||||||
apply_gnome_theme()
|
apply_gnome_theme()
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,8 +2,9 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from .theme import Theme
|
from .theme import Theme
|
||||||
from .utils import label_files, remove_properties, remove_keywords, gnome
|
from .utils import remove_properties, remove_keywords, gnome
|
||||||
from . import config
|
from . import config
|
||||||
|
from .utils.files_labeler import FilesLabeler
|
||||||
|
|
||||||
|
|
||||||
class ThemePrepare:
|
class ThemePrepare:
|
||||||
@@ -11,7 +12,7 @@ class ThemePrepare:
|
|||||||
Theme object prepared for installation
|
Theme object prepared for installation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, theme, theme_file, should_label=False):
|
def __init__(self, theme: Theme, theme_file, should_label=False):
|
||||||
self.theme = theme
|
self.theme = theme
|
||||||
self.theme_file = theme_file
|
self.theme_file = theme_file
|
||||||
self.should_label = should_label
|
self.should_label = should_label
|
||||||
@@ -38,7 +39,7 @@ class GlobalTheme:
|
|||||||
|
|
||||||
self.backup_file = f"{self.destination_file}.backup"
|
self.backup_file = f"{self.destination_file}.backup"
|
||||||
self.backup_trigger = "\n/* Marble theme */\n" # trigger to check if theme is installed
|
self.backup_trigger = "\n/* Marble theme */\n" # trigger to check if theme is installed
|
||||||
self.extracted_theme = os.path.join(self.temp_folder, config.extracted_gdm_folder)
|
self.extracted_theme: str = os.path.join(self.temp_folder, config.extracted_gdm_folder)
|
||||||
self.gst = os.path.join(self.destination_folder, self.destination_file) # use backup file if theme is installed
|
self.gst = os.path.join(self.destination_folder, self.destination_file) # use backup file if theme is installed
|
||||||
|
|
||||||
self.themes: list[ThemePrepare] = []
|
self.themes: list[ThemePrepare] = []
|
||||||
@@ -46,7 +47,7 @@ class GlobalTheme:
|
|||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
|
||||||
|
|
||||||
def __create_theme(self, theme_type, mode=None, should_label=False, is_filled=False):
|
def __create_theme(self, theme_type: str, mode=None, should_label=False, is_filled=False):
|
||||||
"""Helper to create theme objects"""
|
"""Helper to create theme objects"""
|
||||||
theme = Theme(theme_type, self.colors_json, self.theme_folder,
|
theme = Theme(theme_type, self.colors_json, self.theme_folder,
|
||||||
self.extracted_theme, self.temp_folder,
|
self.extracted_theme, self.temp_folder,
|
||||||
@@ -111,16 +112,18 @@ class GlobalTheme:
|
|||||||
:param sat: color saturation
|
:param sat: color saturation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for theme in self.themes:
|
for theme_prepare in self.themes:
|
||||||
if theme.should_label:
|
if theme_prepare.should_label:
|
||||||
label_files(theme.theme.temp_folder, "light", theme.theme.main_styles)
|
temp_folder = theme_prepare.theme.temp_folder
|
||||||
|
main_styles = theme_prepare.theme.main_styles
|
||||||
|
FilesLabeler(temp_folder, main_styles).append_label("light")
|
||||||
|
|
||||||
remove_keywords(theme.theme_file, "!important")
|
remove_keywords(theme_prepare.theme_file, "!important")
|
||||||
remove_properties(theme.theme_file, "background-color", "color", "box-shadow", "border-radius")
|
remove_properties(theme_prepare.theme_file, "background-color", "color", "box-shadow", "border-radius")
|
||||||
|
|
||||||
self.__add_gnome_styles(theme.theme)
|
self.__add_gnome_styles(theme_prepare.theme)
|
||||||
|
|
||||||
theme.theme.install(hue, color, sat, destination=self.extracted_theme)
|
theme_prepare.theme.install(hue, color, sat, destination=self.extracted_theme)
|
||||||
|
|
||||||
|
|
||||||
def __backup(self):
|
def __backup(self):
|
||||||
|
@@ -20,9 +20,13 @@ class GlobalThemeInstaller(ThemeInstaller):
|
|||||||
gdm_temp, mode=self.args.mode, is_filled=self.args.filled)
|
gdm_temp, mode=self.args.mode, is_filled=self.args.filled)
|
||||||
|
|
||||||
def _install_theme(self, hue, theme_name, sat):
|
def _install_theme(self, hue, theme_name, sat):
|
||||||
self.theme.prepare()
|
|
||||||
self.theme.install(hue, sat)
|
self.theme.install(hue, sat)
|
||||||
|
|
||||||
def _apply_tweaks_to_theme(self):
|
def _apply_tweaks_to_theme(self):
|
||||||
for theme in self.theme.themes:
|
for theme in self.theme.themes:
|
||||||
self._apply_tweaks(theme.theme)
|
self._apply_tweaks(theme.theme)
|
||||||
|
|
||||||
|
def _after_install(self):
|
||||||
|
print("\nGDM theme installed successfully.")
|
||||||
|
print("You need to restart gdm.service to apply changes.")
|
||||||
|
print("Run \"systemctl restart gdm.service\" to restart GDM.")
|
@@ -10,12 +10,8 @@ class LocalThemeInstaller(ThemeInstaller):
|
|||||||
theme: Theme
|
theme: Theme
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
args = self.args
|
|
||||||
colors = self.colors.colors
|
colors = self.colors.colors
|
||||||
if args.remove or args.reinstall:
|
remove_files(self.args, colors)
|
||||||
remove_files(args, colors)
|
|
||||||
if not args.reinstall:
|
|
||||||
return
|
|
||||||
|
|
||||||
def _define_theme(self):
|
def _define_theme(self):
|
||||||
theme_folder = os.path.join(config.raw_theme_folder, config.gnome_folder)
|
theme_folder = os.path.join(config.raw_theme_folder, config.gnome_folder)
|
||||||
@@ -29,3 +25,6 @@ class LocalThemeInstaller(ThemeInstaller):
|
|||||||
|
|
||||||
def _apply_tweaks_to_theme(self):
|
def _apply_tweaks_to_theme(self):
|
||||||
self._apply_tweaks(self.theme)
|
self._apply_tweaks(self.theme)
|
||||||
|
|
||||||
|
def _after_install(self):
|
||||||
|
print("\nTheme installed successfully.")
|
@@ -1,11 +1,13 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
from scripts.install.colors_definer import ColorsDefiner
|
from scripts.install.colors_definer import ColorsDefiner
|
||||||
from scripts.theme import Theme
|
from scripts.theme import Theme
|
||||||
from scripts.tweaks_manager import TweaksManager
|
from scripts.tweaks_manager import TweaksManager
|
||||||
|
|
||||||
|
|
||||||
class ThemeInstaller:
|
class ThemeInstaller(ABC):
|
||||||
|
"""Base class for theme installers"""
|
||||||
theme: Theme
|
theme: Theme
|
||||||
|
|
||||||
def __init__(self, args: argparse.Namespace, colors: ColorsDefiner):
|
def __init__(self, args: argparse.Namespace, colors: ColorsDefiner):
|
||||||
@@ -14,24 +16,39 @@ class ThemeInstaller:
|
|||||||
self.stop_after_first_installed_color = False
|
self.stop_after_first_installed_color = False
|
||||||
self._define_theme()
|
self._define_theme()
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def remove(self):
|
def remove(self):
|
||||||
|
"""Method for removing already installed themes"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
self.theme.prepare()
|
self.theme.prepare()
|
||||||
self._apply_tweaks_to_theme()
|
self._apply_tweaks_to_theme()
|
||||||
self._apply_colors()
|
self._apply_colors()
|
||||||
|
self._after_install()
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def _define_theme(self):
|
def _define_theme(self):
|
||||||
|
"""Here is the place to define the theme object"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _install_theme(self, hue, theme_name, sat):
|
@abstractmethod
|
||||||
pass
|
|
||||||
|
|
||||||
def _apply_tweaks_to_theme(self):
|
def _apply_tweaks_to_theme(self):
|
||||||
|
"""Should apply the tweaks for prepared theme"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def _install_theme(self, hue, theme_name, sat):
|
||||||
|
"""Should say how to install the defined theme"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def _after_install(self):
|
||||||
|
"""Method to be called after the theme is installed. Can be used for logging or other actions"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _apply_tweaks(self, theme):
|
def _apply_tweaks(self, theme):
|
||||||
|
"""This method should be called in the _apply_tweaks_to_theme method"""
|
||||||
tweaks_manager = TweaksManager()
|
tweaks_manager = TweaksManager()
|
||||||
tweaks_manager.apply_tweaks(self.args, theme, self.colors)
|
tweaks_manager.apply_tweaks(self.args, theme, self.colors)
|
||||||
|
|
||||||
|
@@ -3,7 +3,6 @@ from .copy_files import copy_files
|
|||||||
from .destinaiton_return import destination_return
|
from .destinaiton_return import destination_return
|
||||||
from .generate_file import generate_file
|
from .generate_file import generate_file
|
||||||
from .hex_to_rgba import hex_to_rgba
|
from .hex_to_rgba import hex_to_rgba
|
||||||
from .label_files import label_files
|
|
||||||
from .remove_files import remove_files
|
from .remove_files import remove_files
|
||||||
from .remove_keywords import remove_keywords
|
from .remove_keywords import remove_keywords
|
||||||
from .remove_properties import remove_properties
|
from .remove_properties import remove_properties
|
||||||
|
51
scripts/utils/files_labeler.py
Normal file
51
scripts/utils/files_labeler.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
type LabeledFileGroup = tuple[str, str]
|
||||||
|
|
||||||
|
class FilesLabeler:
|
||||||
|
def __init__(self, directory: str, *args: str):
|
||||||
|
"""
|
||||||
|
Initialize the working directory and files to change
|
||||||
|
"""
|
||||||
|
self.directory = directory
|
||||||
|
self.files = args
|
||||||
|
|
||||||
|
def append_label(self, label: str):
|
||||||
|
"""
|
||||||
|
Append a label to all files in the directory
|
||||||
|
and update references in the files
|
||||||
|
"""
|
||||||
|
labeled_files = self._label_files(label)
|
||||||
|
self._update_references(labeled_files)
|
||||||
|
|
||||||
|
def _label_files(self, label: str) -> list[LabeledFileGroup]:
|
||||||
|
labeled_files = []
|
||||||
|
for filename in os.listdir(self.directory):
|
||||||
|
if label in filename: continue
|
||||||
|
|
||||||
|
name, extension = os.path.splitext(filename)
|
||||||
|
new_filename = f"{name}-{label}{extension}"
|
||||||
|
|
||||||
|
old_filepath = os.path.join(self.directory, filename)
|
||||||
|
new_filepath = os.path.join(self.directory, new_filename)
|
||||||
|
os.rename(old_filepath, new_filepath)
|
||||||
|
|
||||||
|
labeled_files.append((filename, new_filename))
|
||||||
|
return labeled_files
|
||||||
|
|
||||||
|
def _update_references(self, labeled_files: list[LabeledFileGroup]):
|
||||||
|
for file_path in self.files:
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
file_content = file.read()
|
||||||
|
|
||||||
|
file_content = self._update_references_in_file(file_content, labeled_files)
|
||||||
|
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
file.write(file_content)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _update_references_in_file(file_content: str, labeled_files: list[LabeledFileGroup]) -> str:
|
||||||
|
replaced_content = file_content
|
||||||
|
for old_name, new_name in labeled_files:
|
||||||
|
replaced_content = replaced_content.replace(old_name, new_name)
|
||||||
|
return replaced_content
|
@@ -1,44 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
def label_files(directory, label, *args):
|
|
||||||
"""
|
|
||||||
Add a label to all files in a directory
|
|
||||||
:param directory: folder where files are located
|
|
||||||
:param label: label to add
|
|
||||||
:param args: files to change links to labeled files
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Open all files
|
|
||||||
files = [open(file, 'r') for file in args]
|
|
||||||
read_files = []
|
|
||||||
|
|
||||||
filenames = []
|
|
||||||
|
|
||||||
for filename in os.listdir(directory):
|
|
||||||
# Skip if the file is already labeled
|
|
||||||
if label in filename:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Split the filename into name and extension
|
|
||||||
name, extension = os.path.splitext(filename)
|
|
||||||
|
|
||||||
# Form the new filename and rename the file
|
|
||||||
new_filename = f"{name}-{label}{extension}"
|
|
||||||
os.rename(os.path.join(directory, filename), os.path.join(directory, new_filename))
|
|
||||||
|
|
||||||
filenames.append((filename, new_filename))
|
|
||||||
|
|
||||||
# Replace the filename in all files
|
|
||||||
for i, file in enumerate(files):
|
|
||||||
read_file = file.read()
|
|
||||||
read_file.replace(filenames[i][0], filenames[i][1])
|
|
||||||
read_files.append(read_file)
|
|
||||||
file.close()
|
|
||||||
|
|
||||||
write_files = [open(file, 'w') for file in args]
|
|
||||||
|
|
||||||
# Write the changes to the files and close them
|
|
||||||
for i, file in enumerate(write_files):
|
|
||||||
file.write(read_files[i])
|
|
||||||
file.close()
|
|
Reference in New Issue
Block a user