From b499fd8bbf3d455cbbdf57acc4091b911d96ee22 Mon Sep 17 00:00:00 2001 From: B Stack Date: Tue, 10 Mar 2020 17:23:25 -0400 Subject: rearrange src and add readme --- src/usr/share/logout-manager/lmlib.py | 286 ++++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 src/usr/share/logout-manager/lmlib.py (limited to 'src/usr/share') diff --git a/src/usr/share/logout-manager/lmlib.py b/src/usr/share/logout-manager/lmlib.py new file mode 100644 index 0000000..7c9dc1e --- /dev/null +++ b/src/usr/share/logout-manager/lmlib.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python3 +# File: lmlib.py +# License: CC-BY-SA 4.0 +# Author: bgstack15 +# Startdate: 2019-06-12 +# Title: Python libs for logout-manager +# Purpose: Store the common elements for operating a logout-manager +# History: +# Usage: +# In a logout-manager-gtk.py program +# Reference: +# platform info https://stackoverflow.com/questions/110362/how-can-i-find-the-current-os-in-python/10091465#10091465 +# Improve: +# Documentation: + +import configparser, platform, os + +logout_manager_version="2020-03-10a" + +class Actions: + + @staticmethod + def hibernate(config, event=None): + #print("need to run the /sys/power/state trick, if available") + print(config.get_hibernate_command()) + + @staticmethod + def lock(config, event=None): + #print("please lock the screen.") + print(config.get_lock_command()) + + @staticmethod + def logout(config, event=None): + #print("please log out of current session!") + print(config.get_logout_command()) + + @staticmethod + def reboot(config, event=None): + #print("please reboot.") + print(config.get_reboot_command()) + + @staticmethod + def shutdown(config, event=None): + #print("please shut yourself down!") + print(config.get_shutdown_command()) + +class Config: + def __init__(self): + # load defaults which can be overwritten + self.hibernate_command = "" + self.lock_command = "" + self.logout_command = "" + self.reboot_command = "" + self.shutdown_command = "" + self.hibernate_icon = "system-hibernate" + self.hibernate_fallback_icon = "system-hibernate" + self.lock_icon = "system-lock-screen" + self.lock_fallback_icon = "system-lock-screen" + self.logout_icon = "system-log-out" + self.logout_fallback_icon = "system-log-out" + self.reboot_icon = "system-reboot" + self.reboot_fallback_icon = "system-reboot" + self.shutdown_icon = "system-shutdown" + self.shutdown_fallback_icon = "system-shutdown" + self.icon_size = 24 + self.icon_theme = "default" + self.gtk3_default_icon_theme = "hicolor" + self.icon_category = "actions" + self.can_hibernate = False + self.application_icon=("system-log-out") + + def set_hibernate_command(self,hibernate_command): + self.hibernate_command = hibernate_command + + def set_lock_command(self,lock_command): + self.lock_command = lock_command + + def set_logout_command(self,logout_command): + self.logout_command = logout_command + + def set_reboot_command(self,reboot_command): + self.reboot_command = reboot_command + + def set_shutdown_command(self,shutdown_command): + self.shutdown_command = shutdown_command + + def set_hibernate_icon(self,hibernate_icon): + self.hibernate_icon = hibernate_icon + + def set_lock_icon(self,lock_icon): + self.lock_icon = lock_icon + + def set_logout_icon(self,logout_icon): + self.logout_icon = logout_icon + + def set_reboot_icon(self,reboot_icon): + self.reboot_icon = reboot_icon + + def set_shutdown_icon(self,shutdown_icon): + self.shutdown_icon = shutdown_icon + + def set_icon_size(self,icon_size): + self.icon_size = int(icon_size) + + def set_icon_theme(self,icon_theme): + self.icon_theme = icon_theme + + def set_gtk3_default_icon_theme(self,icon_theme): + self.gtk3_default_icon_theme= icon_theme + + def set_icon_category(self,icon_category): + self.icon_category = icon_category + + def set_can_hibernate(self,can_hibernate): + print("Setting can_hibernate:",can_hibernate) + self.can_hibernate = bool(can_hibernate) + + def get_hibernate_command(self): + return self.hibernate_command + + def get_lock_command(self): + return self.lock_command + + def get_logout_command(self): + return self.logout_command + + def get_reboot_command(self): + return self.reboot_command + + def get_shutdown_command(self): + return self.shutdown_command + + def get_hibernate_icon(self): + return self.hibernate_icon + + def get_lock_icon(self): + return self.lock_icon + + def get_logout_icon(self): + return self.logout_icon + + def get_reboot_icon(self): + return self.reboot_icon + + def get_shutdown_icon(self): + return self.shutdown_icon + + def get_hibernate_fallback_icon(self): + return self.hibernate_fallback_icon + + def get_lock_fallback_icon(self): + return self.lock_fallback_icon + + def get_logout_fallback_icon(self): + return self.logout_fallback_icon + + def get_reboot_fallback_icon(self): + return self.reboot_fallback_icon + + def get_shutdown_fallback_icon(self): + return self.shutdown_fallback_icon + + def get_icon_size(self): + return self.icon_size + + def get_icon_theme(self): + return self.icon_theme + + def get_gtk3_default_icon_theme(self): + return self.gtk3_default_icon_theme + + def get_icon_category(self): + return self.icon_category + + def get_can_hibernate(self): + return self.can_hibernate + +def get_gtk3_default_icon_theme(): + # abstracted so it does not clutter get_scaled_icon + name = "hicolor" + gtk3_config_path = os.path.join(os.path.expanduser("~"),".config","gtk-3.0","settings.ini") + gtk3_config = configparser.ConfigParser() + gtk3_config.read(gtk3_config_path) + try: + if 'Settings' in gtk3_config: + name = gtk3_config['Settings']['gtk-icon-theme-name'] + elif 'settings' in gtk3_config: + name = gtk3_config['settings']['gtk-icon-theme-name'] + except: + # supposed failsafe: keep name = hicolor + pass + print("Found gtk3 default theme:",name) + return name + +def Initialize_config(infile): + # Read config + config_in = configparser.ConfigParser() + config_in.read(infile) + config = Config() + try: + ci = config_in['logout-manager'] + except: + # no definition + print("Using default commands") + + try: + ci_icons = config_in['icons'] + except: + # no definition + print("Using default icons") + + # load up our custom class, which stores the defaults in case we do not set them here + if 'hibernate_command' in ci: + config.set_hibernate_command(ci['hibernate_command']) + if 'lock_command' in ci: + config.set_lock_command(ci['lock_command']) + if 'logout_command' in ci: + config.set_logout_command(ci['logout_command']) + if 'reboot_command' in ci: + config.set_reboot_command(ci['reboot_command']) + if 'shutdown_command' in ci: + config.set_shutdown_command(ci['shutdown_command']) + if 'hibernate' in ci_icons: + config.set_hibernate_icon(ci_icons['hibernate']) + if 'lock' in ci_icons: + config.set_lock_icon(ci_icons['lock']) + if 'logout' in ci_icons: + config.set_logout_icon(ci_icons['logout']) + if 'reboot' in ci_icons: + config.set_reboot_icon(ci_icons['reboot']) + if 'shutdown' in ci_icons: + config.set_shutdown_icon(ci_icons['shutdown']) + if 'size' in ci_icons: + config.set_icon_size(ci_icons['size']) + if 'theme' in ci_icons: + config.set_icon_theme(ci_icons['theme']) + # store the info about if hibernate is an option + can_hibernate = False + try: + with open('/sys/power/state') as r: + line = r.read() + if 'disk' in line: can_hibernate = True + except: + pass + config.set_can_hibernate(can_hibernate) + + # read gtk3_default_icon_theme + config.set_gtk3_default_icon_theme(get_gtk3_default_icon_theme()) + if config.get_icon_theme() == "default": + config.set_icon_theme(config.get_gtk3_default_icon_theme()) + + # set icon category + # written primarily for el7 which uses "app" for the system-reboot icons, etc. + a = platform.dist() + try: + if a[0] == "redhat" and int(a[1].split(".")[0]) <= 7: + config.set_icon_category("apps") + except: + pass + + # DEBUG, raw from conf file and system status + print("Raw values:") + for item in config_in.sections(): + print("["+item+"]") + for key in config_in[item]: + print(key+" = "+config_in[item][key]) + print("Can hibernate:",can_hibernate) + + # DEBUG, stored values + print("Stored values:") + print(config.get_hibernate_command()) + print(config.get_lock_command()) + print(config.get_logout_command()) + print(config.get_reboot_command()) + print(config.get_shutdown_command()) + print(config.get_hibernate_icon()) + print(config.get_lock_icon()) + print(config.get_logout_icon()) + print(config.get_reboot_icon()) + print(config.get_shutdown_icon()) + print(config.get_icon_size()) + print(config.get_icon_theme()) + print(config.get_icon_category()) + print("Can hibernate:",config.get_can_hibernate()) + + return config -- cgit From ffea6275fcb08b36c3d7f5182785cbd329f15e40 Mon Sep 17 00:00:00 2001 From: B Stack Date: Tue, 10 Mar 2020 20:40:39 -0400 Subject: add desktop file, some readme contents --- src/usr/share/applications/logout-manager.desktop | 12 +++++++ src/usr/share/doc/logout-manager/README.md | 38 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/usr/share/applications/logout-manager.desktop create mode 100644 src/usr/share/doc/logout-manager/README.md (limited to 'src/usr/share') diff --git a/src/usr/share/applications/logout-manager.desktop b/src/usr/share/applications/logout-manager.desktop new file mode 100644 index 0000000..4522a66 --- /dev/null +++ b/src/usr/share/applications/logout-manager.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Categories=Settings;HardwareSettings; +Comment=Prompt for common actions including lock screen, logout, etc. +Exec=/usr/bin/logout-manager +GenericName=Logout menu +Icon=system-log-out +Keywords=shutdown;hibernate;lockscreen;logout;reboot; +Name=Logout... +StartupNotify=true +Terminal=false +Type=Application +Version=1.0 diff --git a/src/usr/share/doc/logout-manager/README.md b/src/usr/share/doc/logout-manager/README.md new file mode 100644 index 0000000..baa6aeb --- /dev/null +++ b/src/usr/share/doc/logout-manager/README.md @@ -0,0 +1,38 @@ +# README for logout-manager +## Introduction +Logout Manager is a python3 utility that provides a simple menu for logout-type actions. The supported actions are presented: + * Lock + * Logout + * Hibernate (if supported by hardware) + * Shutdown + * Reboot + +## Alternatives +[oblogout](https://launchpad.net/oblogout) looks really old so I did not investigate personally, but it sounds like it does the same thing I am trying to do. +`apt-cache search logout` shows [lxsession-logout](http://manpages.ubuntu.com/manpages/precise/en/man1/lxsession-logout.1.html) which was compiled, as well as does not provide configurable options for changing executed commands or icons. + +## License +[logout-manager-ncurses.py](src/usr/bin/logout-manager-ncurses.py) is licensed under the [MIT license](http://choosealicense.com/licenses/mit) and is derived almost entirely from [adamlamers](http://adamlamers.com/post/FTPD9KNRA8CT). +Everything else is licensed under [CC-BY-SA 4.0](https://choosealicense.com/licenses/cc-by-sa-4.0/). + +## Description +This project is partially a programming playground for the [original author](https://bgstack15.wordpress.com) and partially a useful project for his migration to [Fluxbox](http://fluxbox.org/) on the desktop. + +## Upsides +* This project is the first to [demonstrate SVG images in tkinter in python3](https://bgstack15.wordpress.com/2019/07/13/display-svg-in-tkinter-python3/) that I could find on the Internet. +* I have learned how to work with ncurses, gtk, and tcl in python3. +* This will make Fluxbox systems easier to use for general users. + +## Downsides +This whole thing is more complex than just logging out of my user session, and selecting a logout-type action from the display manager. + +## Improve +* add makefile + * add the standard 'list' option + * add a `list_dependencies` option or similar, which does the grep command + + grep -h -A5 -riIE dependencies * | awk 'tolower($0) ~ /devuan/ {$1="";$2="";print}' | sort | uniq | xargs + +* add libexec/ helper scripts for actually running commands +* add debian/ dir + * and dsc file -- cgit From d118309b08c28c7ef7656828fe092d6c85a2e344 Mon Sep 17 00:00:00 2001 From: B Stack Date: Tue, 10 Mar 2020 21:18:03 -0400 Subject: WIP: add lm-helper lm-helper has most functionality there. needs work on logout, and bash_completion function. --- src/usr/share/doc/logout-manager/README.md | 9 +++++++++ .../share/doc/logout-manager/logout-manager.conf.example | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/usr/share/doc/logout-manager/logout-manager.conf.example (limited to 'src/usr/share') diff --git a/src/usr/share/doc/logout-manager/README.md b/src/usr/share/doc/logout-manager/README.md index baa6aeb..7b8ed3d 100644 --- a/src/usr/share/doc/logout-manager/README.md +++ b/src/usr/share/doc/logout-manager/README.md @@ -7,6 +7,15 @@ Logout Manager is a python3 utility that provides a simple menu for logout-type * Shutdown * Reboot +## Customization +The `lm-helper` logout command needs to be customized for every desktop environment. Some may need extra configurationon the window manager/desktop environment side. +### Fluxbox +For Fluxbox, you need to set a value in ~/.fluxbox/init + + session.screen0.allowRemoteActions: true + +Be aware that this is insecure. See man `fluxbox-remote(1)`. + ## Alternatives [oblogout](https://launchpad.net/oblogout) looks really old so I did not investigate personally, but it sounds like it does the same thing I am trying to do. `apt-cache search logout` shows [lxsession-logout](http://manpages.ubuntu.com/manpages/precise/en/man1/lxsession-logout.1.html) which was compiled, as well as does not provide configurable options for changing executed commands or icons. diff --git a/src/usr/share/doc/logout-manager/logout-manager.conf.example b/src/usr/share/doc/logout-manager/logout-manager.conf.example new file mode 100644 index 0000000..1a14909 --- /dev/null +++ b/src/usr/share/doc/logout-manager/logout-manager.conf.example @@ -0,0 +1,16 @@ +[logout-manager] +hibernate_command="printf 'disk' | sudo tee /sys/power/state" +lock_command="xscreensaver --locknow" +logout_command="logout from something" +reboot_command="sudo shutdown -r now" +shutdown_command="sudo shutdown -h now" + +[icons] +size = 24 +#theme = default +# use names as used by the icon theme, or give a full path here +hibernate = system-hibernate +lock = system-lock-screen +logout = system-log-out +reboot = system-reboot +shutdown = system-shutdown -- cgit From b278cce1e12a7ce9dcd49bfbab7cf2fa7e3b1d35 Mon Sep 17 00:00:00 2001 From: B Stack Date: Wed, 11 Mar 2020 08:34:06 -0400 Subject: add usage of sudo --- src/usr/share/doc/logout-manager/README.md | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/usr/share') diff --git a/src/usr/share/doc/logout-manager/README.md b/src/usr/share/doc/logout-manager/README.md index 7b8ed3d..cfc3843 100644 --- a/src/usr/share/doc/logout-manager/README.md +++ b/src/usr/share/doc/logout-manager/README.md @@ -36,12 +36,5 @@ This project is partially a programming playground for the [original author](htt This whole thing is more complex than just logging out of my user session, and selecting a logout-type action from the display manager. ## Improve -* add makefile - * add the standard 'list' option - * add a `list_dependencies` option or similar, which does the grep command - - grep -h -A5 -riIE dependencies * | awk 'tolower($0) ~ /devuan/ {$1="";$2="";print}' | sort | uniq | xargs - -* add libexec/ helper scripts for actually running commands * add debian/ dir * and dsc file -- cgit From 21a2eee53ad514061b2c8d5d21ec69fec219784d Mon Sep 17 00:00:00 2001 From: B Stack Date: Wed, 11 Mar 2020 10:45:48 -0400 Subject: add initial debuild stuff move bash completion to recommended one from lint improve make deplist with SEPARATOR --- src/usr/share/bash-completion/completions/logout-manager | 12 ++++++++++++ src/usr/share/doc/logout-manager/README.md | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 src/usr/share/bash-completion/completions/logout-manager (limited to 'src/usr/share') diff --git a/src/usr/share/bash-completion/completions/logout-manager b/src/usr/share/bash-completion/completions/logout-manager new file mode 100644 index 0000000..fd1267f --- /dev/null +++ b/src/usr/share/bash-completion/completions/logout-manager @@ -0,0 +1,12 @@ +# File: /etc/bash_completion.d/logout-manager +# Reference: +# bgscripts-core: /usr/bin/bp +# man complete + +_lm_helper() { + local cur prev words cword; + _init_completion || return + COMPREPLY=($( compgen -W "$( ~/dev/logout-manager/src/usr/libexec/logout-manager/lm-helper options )" -- "$cur" )) + return 0 +} && \ +complete -F _lm_helper -o bashdefault lm-helper diff --git a/src/usr/share/doc/logout-manager/README.md b/src/usr/share/doc/logout-manager/README.md index cfc3843..d34f02c 100644 --- a/src/usr/share/doc/logout-manager/README.md +++ b/src/usr/share/doc/logout-manager/README.md @@ -9,6 +9,7 @@ Logout Manager is a python3 utility that provides a simple menu for logout-type ## Customization The `lm-helper` logout command needs to be customized for every desktop environment. Some may need extra configurationon the window manager/desktop environment side. + ### Fluxbox For Fluxbox, you need to set a value in ~/.fluxbox/init @@ -29,12 +30,11 @@ This project is partially a programming playground for the [original author](htt ## Upsides * This project is the first to [demonstrate SVG images in tkinter in python3](https://bgstack15.wordpress.com/2019/07/13/display-svg-in-tkinter-python3/) that I could find on the Internet. +* This project demonstrates how to have the Makefile and debian/rules build a dependency list, from the Dependencies tags of the files themselves. * I have learned how to work with ncurses, gtk, and tcl in python3. * This will make Fluxbox systems easier to use for general users. +* Does not use dbus! ## Downsides -This whole thing is more complex than just logging out of my user session, and selecting a logout-type action from the display manager. - -## Improve -* add debian/ dir - * and dsc file +* This whole thing is more complex than just logging out of my user session, and selecting a logout-type action from the display manager. +* Depends on sudo instead of using native tools. -- cgit From be87206a369b09e595e498504eef1540e2c91c41 Mon Sep 17 00:00:00 2001 From: B Stack Date: Wed, 11 Mar 2020 12:35:10 -0400 Subject: use alternatives, and actually run commands --- src/usr/share/logout-manager/lmlib.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/usr/share') diff --git a/src/usr/share/logout-manager/lmlib.py b/src/usr/share/logout-manager/lmlib.py index 7c9dc1e..40ee3a0 100644 --- a/src/usr/share/logout-manager/lmlib.py +++ b/src/usr/share/logout-manager/lmlib.py @@ -13,36 +13,45 @@ # Improve: # Documentation: -import configparser, platform, os +import configparser, platform, os, subprocess logout_manager_version="2020-03-10a" class Actions: + def __take_action(command): + print(command) + command=str(command).split() + command2=[] + for i in command: + command2.append(str(i.strip('"'))) + command=command2 + subprocess.run(command) + @staticmethod def hibernate(config, event=None): #print("need to run the /sys/power/state trick, if available") - print(config.get_hibernate_command()) + Actions.__take_action(config.get_hibernate_command()) @staticmethod def lock(config, event=None): #print("please lock the screen.") - print(config.get_lock_command()) + Actions.__take_action(config.get_lock_command()) @staticmethod def logout(config, event=None): #print("please log out of current session!") - print(config.get_logout_command()) + Actions.__take_action(config.get_logout_command()) @staticmethod def reboot(config, event=None): #print("please reboot.") - print(config.get_reboot_command()) + Actions.__take_action(config.get_reboot_command()) @staticmethod def shutdown(config, event=None): #print("please shut yourself down!") - print(config.get_shutdown_command()) + Actions.__take_action(config.get_shutdown_command()) class Config: def __init__(self): -- cgit