Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Introduce a command-line interface #675

Merged
merged 31 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e834e55
backend/models: refactor Preset model object
tfuxu Dec 8, 2022
22f476f
backend: create new modules for preset generation utilities
tfuxu Dec 8, 2022
e1e244d
backend/theming: move apply, restore and reset preset functions to ba…
tfuxu Dec 8, 2022
674848e
backend: include backend/theming modules in meson compilation
tfuxu Dec 10, 2022
527a9dc
backend: seperate JSON encoding in Preset module to a new function
tfuxu Dec 10, 2022
f0afbd8
frontend: introduce initial CLI interface
tfuxu Dec 10, 2022
1245d24
Merge branch 'main' into cli-support
tfuxu Dec 10, 2022
c74bd9b
backend: allow functions in flatpak_override module to be used withou…
tfuxu Dec 11, 2022
24d3429
backend/globals: move official Gradience preset repositories list to …
tfuxu Dec 11, 2022
7c1a295
frontend/cli: add rudimentary logic code for apply, download and flat…
tfuxu Dec 11, 2022
ffe09dc
Merge branch 'main' into cli-support
tfuxu Dec 11, 2022
7f8e3cc
backend: convert preset_downloader module to class
tfuxu Dec 11, 2022
b36669b
frontend/cli: add logic to import command, and finish download command
tfuxu Dec 11, 2022
1d1654d
Merge branch 'main' into cli-support
tfuxu Dec 13, 2022
3c85038
frontend/cli: change some help messages
tfuxu Dec 13, 2022
38bb148
Merge branch 'main' into cli-support
tfuxu Dec 14, 2022
9db8eaa
Merge branch 'main' into cli-support
tfuxu Dec 17, 2022
da0300e
frontend/cli: use from now backend/logger module functions to print m…
tfuxu Dec 17, 2022
d3df5c3
backend: change the structure of log messages, and move preset listin…
tfuxu Dec 17, 2022
5020561
frontend/cli: fix local builds support, add logic code for all remain…
tfuxu Dec 17, 2022
d328735
Merge branch 'main' into cli-support
tfuxu Dec 17, 2022
20994df
frontend/cli: add information for Flatpak users about `monet` command
tfuxu Dec 18, 2022
d9f63e9
Merge branch 'main' into cli-support
tfuxu Dec 18, 2022
6872919
fix: allow spaces in argument values when executing CLI from `local_c…
tfuxu Dec 18, 2022
db7347c
frontend/cli: add more messages in CLI to make it more user-friendly
tfuxu Dec 18, 2022
1e8de79
fix: text
daudix Dec 18, 2022
354010a
frontend/cli: fix `download` command failing after indexing first preset
tfuxu Dec 18, 2022
c9d101d
backend/flatpak_overrides: add new functions for file access overrides
tfuxu Dec 19, 2022
03a63e7
frontend/cli: add new `access-file` command
tfuxu Dec 19, 2022
ca84565
build-aux/flatpak: add `xdg-download` read-only as a allowed directory
tfuxu Dec 19, 2022
61eb5fb
frontend/cli: reenable `monet` command on Flatpak builds
tfuxu Dec 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"--filesystem=xdg-config/gtk-3.0",
"--filesystem=xdg-config/gtk-4.0",
"--filesystem=xdg-run/gvfsd",
"--filesystem=xdg-download:ro",
"--filesystem=~/.mozilla/firefox",
"--filesystem=~/.librewolf",
"--filesystem=~/.var/app/org.mozilla.firefox/.mozilla/firefox",
Expand Down
1 change: 1 addition & 0 deletions build-aux/flatpak/com.github.GradienceTeam.Gradience.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"--filesystem=xdg-config/gtk-3.0",
"--filesystem=xdg-config/gtk-4.0",
"--filesystem=xdg-run/gvfsd",
"--filesystem=xdg-download:ro",
"--filesystem=~/.mozilla/firefox",
"--filesystem=~/.librewolf",
"--filesystem=~/.var/app/org.mozilla.firefox/.mozilla/firefox",
Expand Down
253 changes: 200 additions & 53 deletions gradience/backend/flatpak_overrides.py

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions gradience/backend/globals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# globals.py
#
# Change the look of Adwaita, with ease
# Copyright (C) 2022 Gradience Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import os

from gi.repository import Xdp


presets_dir = os.path.join(
os.environ.get("XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"),
"presets"
)

preset_repos = {
"Official": "https://github.com/GradienceTeam/Community/raw/next/official.json",
"Curated": "https://github.com/GradienceTeam/Community/raw/next/curated.json"
}

def get_gtk_theme_dir(app_type):
if app_type == "gtk4":
theme_dir = os.path.join(
os.environ.get("XDG_CONFIG_HOME",
os.environ["HOME"] + "/.config"),
"gtk-4.0"
)
elif app_type == "gtk3":
theme_dir = os.path.join(
os.environ.get("XDG_CONFIG_HOME",
os.environ["HOME"] + "/.config"),
"gtk-3.0"
)

return theme_dir

def is_sandboxed():
portal = Xdp.Portal()

is_sandboxed = self.portal.running_under_sandbox()

return is_sandboxed

def get_available_sassc():
pass
36 changes: 25 additions & 11 deletions gradience/backend/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,45 @@ class Logger(logging.getLoggerClass()):
"""
This is a wrapper of `logging` module. It provides
custom formatting for log messages.

Attributes:
logger_name (str): Custom name of the logger.
formatter (dict): Custom formatter for the logger.
"""
log_colors = {
"debug": 37,
"debug": 32,
"info": 36,
"warning": 33,
"error": 31,
"critical": 41
}

log_format = {
'fmt': '\033[1m[%(levelname)s]\033[0m [%(name)s] %(message)s'
'fmt': '[%(name)s] %(message)s'
}

def __set_color(self, level, message: str):
def __set_level_color(self, level, message: str):
if message is not None and "\n" in message:
message = message.replace("\n", "\n\t") + "\n"
color_id = self.log_colors[level]
return "\033[%dm%s\033[0m" % (color_id, message)
return "\033[1;%dm%s:\033[0m %s" % (color_id, level.upper(), message)

def __init__(self, logger_name=None, formatter=None):
"""
The constructor for Logger class.

def __init__(self, formatter=None):
When initializing this class, you should specify a logger name for debugging purposes,
even if you didn't wrote any debug messages in your code.
The logger name should usually be a name of your module's main class or module name.
"""
if formatter is None:
formatter = self.log_format
formatter = logging.Formatter(**formatter)

self.root.name = "gradience"
if logger_name:
self.root.name = "Gradience.%s" % (logger_name)
else:
self.root.name = "Gradience"

if build_type == "debug":
self.root.setLevel(logging.DEBUG)
Expand All @@ -62,19 +76,19 @@ def __init__(self, formatter=None):
self.root.addHandler(handler)

def debug(self, message, **kwargs):
self.root.debug(self.__set_color("debug", str(message)), )
self.root.debug(self.__set_level_color("debug", str(message)), )

def info(self, message, **kwargs):
self.root.info(self.__set_color("info", str(message)), )
self.root.info(self.__set_level_color("info", str(message)), )

def warning(self, message, **kwargs):
self.root.warning(self.__set_color("warning", str(message)),)
self.root.warning(self.__set_level_color("warning", str(message)),)

def error(self, message, **kwargs):
self.root.error(self.__set_color("error", str(message)), )
self.root.error(self.__set_level_color("error", str(message)), )

def critical(self, message, **kwargs):
self.root.critical(self.__set_color("critical", str(message)), )
self.root.critical(self.__set_level_color("critical", str(message)), )

def set_silent(self):
self.root.handlers = []
2 changes: 2 additions & 0 deletions gradience/backend/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ configure_file(
)

subdir('models')
subdir('theming')
subdir('utils')

gradience_sources = [
'__init__.py',
'css_parser.py',
'flatpak_overrides.py',
'globals.py',
'logger.py',
'preset_downloader.py'
]
Expand Down
Loading