aboutsummaryrefslogtreecommitdiff
path: root/logout-manager-ncurses.py
diff options
context:
space:
mode:
Diffstat (limited to 'logout-manager-ncurses.py')
-rwxr-xr-xlogout-manager-ncurses.py38
1 files changed, 25 insertions, 13 deletions
diff --git a/logout-manager-ncurses.py b/logout-manager-ncurses.py
index 99801d7..ab3b99b 100755
--- a/logout-manager-ncurses.py
+++ b/logout-manager-ncurses.py
@@ -1,25 +1,41 @@
#!/usr/bin/env python3
-# File: logout-manager-tui.py
+# File: logout-manager-ncurses.py
# License: MIT
# Author: adamlamers, bgstack15
# Startdate: 2020-03-09 17:06
# Title: ncurses based logout manager
# Usage:
-#
+# logout-manager-ncurses.py
# Reference:
# https://docs.python.org/3/howto/curses.html
# ripped straight from http://adamlamers.com/post/FTPD9KNRA8CT
# https://stackoverflow.com/questions/3061/calling-a-function-of-a-module-by-using-its-name-a-string/12025554#12025554
+# https://robinislam.me/blog/reading-environment-variables-in-python/
# Improve:
-# add "disabled" option in menu, with default=enabled
+# Dependencies:
+# Devuan: python3-dotenv
# Documentation:
# Improvements for CursesMenu class over origin:
# accepts number key inputs
# accepts enabled attribute
# add "zeroindex" bool
-import curses, sys, os
-sys.path.append("/home/bgirton/dev/logout-manager")
+import curses, os, platform, sys
+from dotenv import load_dotenv
+
+# all this to load the libpath
+try:
+ defaultdir="/etc/sysconfig"
+ thisplatform = platform.platform().lower()
+ if 'debian' in thisplatform or 'devuan' in thisplatform:
+ defaultdir="/etc/default"
+ # load_dotenv keeps existing environment variables as higher precedent
+ load_dotenv(os.path.join(defaultdir,"logout-manager"))
+except:
+ pass
+if 'LOGOUT_MANAGER_LIBPATH' in os.environ:
+ for i in os.environ['LOGOUT_MANAGER_LIBPATH'].split(":"):
+ sys.path.append(i)
import lmlib
class CursesMenu(object):
@@ -146,19 +162,16 @@ class CursesMenu(object):
self.running = False
return {'title' : 'Cancel', 'type' : 'exitmenu'}
-option_1 = {'title' : 'Hello World',
- 'type' : 'command',
- 'command' : 'echo Hello World!'}
-
-# build menu object from config.
-config = lmlib.Initialize_config()
+# load configs
+config = lmlib.Initialize_config(os.environ['LOGOUT_MANAGER_CONF'])
actions = lmlib.Actions
+# MAIN LOOP
menu = {
'title' : 'Logout Manager',
'type' : 'menu',
'subtitle' : 'Use arrows or number keys',
- 'zeroindex' : True,
+ 'zeroindex' : False,
'options' : [
{'title': 'Lock', 'type': 'action', 'action': 'lock'},
{'title': 'Logout', 'type': 'action', 'action': 'logout'},
@@ -167,7 +180,6 @@ menu = {
{'title': 'Reboot', 'type': 'action', 'action': 'reboot'}
]
}
-
m = CursesMenu(menu)
selected_action = m.display()
bgstack15