diff --git a/generate-icons.py b/generate_icons.py similarity index 100% rename from generate-icons.py rename to generate_icons.py diff --git a/scc/__init__.py b/scc/__init__.py index 3e7a9aee..ba7a4bf9 100644 --- a/scc/__init__.py +++ b/scc/__init__.py @@ -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 @@ -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 diff --git a/scc/gui/editor.py b/scc/gui/editor.py index b6de0f81..dade9fd8 100644 --- a/scc/gui/editor.py +++ b/scc/gui/editor.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python3 -""" -SC-Controller - Action Editor +"""SC-Controller - Action Editor. Allows to edit button or trigger action. """ diff --git a/scc/paths.py b/scc/paths.py index d1a85d35..1baaf38d 100644 --- a/scc/paths.py +++ b/scc/paths.py @@ -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. @@ -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") @@ -24,17 +22,17 @@ 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 @@ -42,17 +40,17 @@ def get_default_profiles_path(): 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 @@ -60,25 +58,25 @@ def get_default_menuicons_path(): 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 @@ -86,31 +84,31 @@ def get_default_menus_path(): 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 """ @@ -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") diff --git a/scripts/scc-daemon b/scripts/scc-daemon index 9c910943..cddb83e8 100755 --- a/scripts/scc-daemon +++ b/scripts/scc-daemon @@ -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 @@ -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() diff --git a/scripts/scc-osd-message b/scripts/scc-osd-message index f453d5f9..aeda2f92 100755 --- a/scripts/scc-osd-message +++ b/scripts/scc-osd-message @@ -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()