Skip to content

Commit

Permalink
Typing&Linter as usual
Browse files Browse the repository at this point in the history
  • Loading branch information
C0rn3j committed Sep 28, 2024
1 parent 8136ec0 commit 6e84a28
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 87 deletions.
File renamed without changes.
7 changes: 2 additions & 5 deletions scc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
"""
SC-Controller
"""SC-Controller.
Copyright (C) 2018 Kozec
This program is free software; you can redistribute it and/or modify
Expand All @@ -16,5 +15,3 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""

pass
4 changes: 1 addition & 3 deletions scc/gui/editor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
"""
SC-Controller - Action Editor
"""SC-Controller - Action Editor.
Allows to edit button or trigger action.
"""
Expand Down
89 changes: 43 additions & 46 deletions scc/paths.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
"""
SC-Controller - Paths
"""SC-Controller - Paths.
Methods in this module are used to determine stuff like where user data is stored,
where sccdaemon can be executed from and similar.
Expand All @@ -10,12 +8,12 @@
All this is needed since I want to have entire thing installable, runnable
from source tarball *and* debugable in working folder.
"""
import os, sys, __main__
import os
import sys

def get_config_path() -> str:
"""Return configuration directory.
def get_config_path():
"""
Returns configuration directory.
~/.config/scc under normal conditions.
"""
confdir = os.path.expanduser("~/.config")
Expand All @@ -24,93 +22,93 @@ def get_config_path():
return os.path.join(confdir, "scc")


def get_profiles_path():
"""
Returns directory where profiles are stored.
def get_profiles_path() -> str:
"""Return directory where profiles are stored.
~/.config/scc/profiles under normal conditions.
"""
return os.path.join(get_config_path(), "profiles")


def get_default_profiles_path():
"""
Returns directory where default profiles are stored.
def get_default_profiles_path() -> str:
"""Return directory where default profiles are stored.
Probably something like /usr/share/scc/default_profiles,
or $SCC_SHARED/default_profiles if program is being started from
script extracted from source tarball
"""
return os.path.join(get_share_path(), "default_profiles")


def get_menuicons_path():
"""
Returns directory where menu icons are stored.
def get_menuicons_path() -> str:
"""Return directory where menu icons are stored.
~/.config/scc/menu-icons under normal conditions.
"""
return os.path.join(get_config_path(), "menu-icons")


def get_default_menuicons_path():
"""
Returns directory where default menu icons are stored.
def get_default_menuicons_path() -> str:
"""Return directory where default menu icons are stored.
Probably something like /usr/share/scc/images/menu-icons,
or $SCC_SHARED/images/menu-icons if program is being started from
script extracted from source tarball
"""
return os.path.join(get_share_path(), "images/menu-icons")


def get_button_images_path():
"""
Returns directory where button images are stored.
def get_button_images_path() -> str:
"""Return directory where button images are stored.
/usr/share/scc/images/button-images by default.
"""
return os.path.join(get_share_path(), "images/button-images")


def get_menus_path():
"""
Returns directory where profiles are stored.
def get_menus_path() -> str:
"""Return directory where profiles are stored.
~/.config/scc/profiles under normal conditions.
"""
return os.path.join(get_config_path(), "menus")


def get_default_menus_path():
"""
Returns directory where default profiles are stored.
def get_default_menus_path() -> str:
"""Return directory where default profiles are stored.
Probably something like /usr/share/scc/default_profiles,
or ./default_profiles if program is being started from
extracted source tarball
"""
return os.path.join(get_share_path(), "default_menus")


def get_controller_icons_path():
"""
Returns directory where controller icons are stored.
def get_controller_icons_path() -> str:
"""Return directory where controller icons are stored.
~/.config/scc/controller-icons under normal conditions.
This directory may not exist.
"""
return os.path.join(get_config_path(), "controller-icons")


def get_default_controller_icons_path():
"""
Returns directory where controller icons are stored.
def get_default_controller_icons_path() -> str:
"""Return directory where controller icons are stored.
Probably something like /usr/share/scc/images/controller-icons,
or ./images/controller-icons if program is being started from
extracted source tarball.
This directory should always exist.
"""
return os.path.join(get_share_path(), "images", "controller-icons")


def get_share_path():
"""
Returns directory where shared files are kept.
def get_share_path() -> str:
"""Return directory where shared files are kept.
Usually "/usr/share/scc" or $SCC_SHARED if program is being started from
script extracted from source tarball
"""
Expand All @@ -128,18 +126,17 @@ def get_share_path():
return "/usr/share/scc"


def get_pid_file():
"""
Returns path to PID file.
def get_pid_file() -> str:
"""Return path to PID file.
~/.config/scc/daemon.pid under normal conditions.
"""
return os.path.join(get_config_path(), "daemon.pid")


def get_daemon_socket():
"""
Returns path to socket that can be used to controll sccdaemon.
def get_daemon_socket() -> str:
"""Return path to socket that can be used to control sccdaemon.
~/.config/scc/daemon.socket under normal conditions.
"""
return os.path.join(get_config_path(), "daemon.socket")
26 changes: 14 additions & 12 deletions scripts/scc-daemon
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/usr/bin/env python3
import argparse

from scc.paths import get_daemon_socket, get_pid_file
from scc.sccdaemon import SCCDaemon
from scc.paths import get_pid_file, get_daemon_socket
from scc.tools import init_logging

import argparse

def main():
def main() -> None:
"""SCCDaemon launcher."""
init_logging()
parser = argparse.ArgumentParser()
parser.add_argument('profile', type=str, nargs='*')
parser.add_argument('command', type=str, choices=['start', 'stop', 'restart', 'debug'])
parser.add_argument('--alone', action='store_true', help="prevent scc-daemon from launching osd-daemon and autoswitch-daemon")
parser.add_argument('--once', action='store_true', help="use with 'stop' to send single SIGTERM without waiting for daemon to exit")
parser.add_argument("profile", type=str, nargs="*")
parser.add_argument("command", type=str, choices=["start", "stop", "restart", "debug"])
parser.add_argument("--alone", action="store_true", help="prevent scc-daemon from launching osd-daemon and autoswitch-daemon")
parser.add_argument("--once", action="store_true", help="use with 'stop' to send single SIGTERM without waiting for daemon to exit")
daemon = SCCDaemon(get_pid_file(), get_daemon_socket())
args = parser.parse_args()
daemon.alone = args.alone
Expand All @@ -22,15 +24,15 @@ def main():
# If no default_profile is set, daemon will try to load last used
# from config

if 'start' == args.command:
if args.command == "start":
daemon.start()
elif 'stop' == args.command:
elif args.command == "stop":
daemon.stop(once = args.once)
elif 'restart' == args.command:
elif args.command == "restart":
daemon.restart()
elif 'debug' == args.command:
elif args.command == "debug":
daemon.debug()


if __name__ == '__main__':
if __name__ == "__main__":
main()
47 changes: 26 additions & 21 deletions scripts/scc-osd-message
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#!/usr/bin/env python3
import os, sys, signal, argparse
import signal
import sys

def sigint(*a):
print("\n*break*")
sys.exit(0)
def main() -> None:
def sigint(*a):
print("\n*break*")
sys.exit(0)

if __name__ == "__main__":
signal.signal(signal.SIGINT, sigint)
if __name__ == "__main__":
signal.signal(signal.SIGINT, sigint)

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Rsvg', '2.0')
gi.require_version('GdkX11', '3.0')

from scc.tools import init_logging
from scc.paths import get_share_path
init_logging()

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Rsvg', '2.0')
gi.require_version('GdkX11', '3.0')

from scc.tools import init_logging
from scc.paths import get_share_path
init_logging()

from scc.osd.message import Message
m = Message()
if not m.parse_argumets(sys.argv):
sys.exit(1)
m.run()
sys.exit(m.get_exit_code())
from scc.osd.message import Message
m = Message()
if not m.parse_argumets(sys.argv):
sys.exit(1)
m.run()
sys.exit(m.get_exit_code())

if __name__ == "__main__":
main()

0 comments on commit 6e84a28

Please sign in to comment.