2022-08-23 17:38:09 +00:00
|
|
|
# utils.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 re
|
2022-08-24 09:08:52 +00:00
|
|
|
import logging
|
2022-10-02 19:52:30 +00:00
|
|
|
import os
|
2022-08-23 17:38:09 +00:00
|
|
|
|
2022-10-02 19:52:30 +00:00
|
|
|
from subprocess import run
|
2022-08-23 17:38:09 +00:00
|
|
|
from anyascii import anyascii
|
2022-10-10 19:45:47 +00:00
|
|
|
|
2022-08-23 17:38:09 +00:00
|
|
|
from gradience.constants import build_type
|
|
|
|
|
2022-09-10 14:00:57 +00:00
|
|
|
|
2022-08-24 09:08:52 +00:00
|
|
|
if build_type == "debug":
|
2022-09-11 12:22:46 +00:00
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.DEBUG, format="[%(levelname)s] [%(name)s] %(message)s"
|
|
|
|
)
|
2022-08-24 09:08:52 +00:00
|
|
|
else:
|
2022-09-11 12:22:46 +00:00
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.WARNING, format="[%(levelname)s] [%(name)s] %(message)s"
|
|
|
|
)
|
2022-08-24 09:08:52 +00:00
|
|
|
|
2022-08-23 17:38:09 +00:00
|
|
|
|
|
|
|
def to_slug_case(non_slug):
|
|
|
|
return re.sub(r"[^0-9a-z]+", "-", anyascii(non_slug).lower()).strip("-")
|
|
|
|
|
2022-09-11 12:22:46 +00:00
|
|
|
|
2022-08-24 22:29:14 +00:00
|
|
|
# Use it instead of print(), so there isn't any output in stdout if
|
2022-09-10 14:00:57 +00:00
|
|
|
# Gradience is build in release mode
|
2022-08-23 17:38:09 +00:00
|
|
|
def buglog(*args):
|
2022-08-24 09:08:52 +00:00
|
|
|
logging.debug(*args)
|
2022-10-02 19:52:30 +00:00
|
|
|
|
|
|
|
def run_command(command, *args, **kwargs):
|
|
|
|
|
2022-10-05 12:30:28 +00:00
|
|
|
if isinstance(command, str): # run on the host
|
2022-10-02 19:52:30 +00:00
|
|
|
command = [command]
|
2022-10-05 12:30:28 +00:00
|
|
|
if os.environ.get('FLATPAK_ID'): # run in flatpak
|
2022-10-02 19:52:30 +00:00
|
|
|
command = ['flatpak-spawn', '--host'] + command
|
|
|
|
|
|
|
|
return run(command, *args, **kwargs)
|