Browse Source

Added arguments parser

sisyphus
JezerM 3 years ago
parent
commit
adb5435af4
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 70
      web-greeter/__main__.py
  2. 3
      web-greeter/browser/browser.py
  3. 3
      web-greeter/browser/devtools.py
  4. 8
      web-greeter/config.py

70
web-greeter/__main__.py

@ -26,17 +26,77 @@
# along with Web Greeter; If not, see <http://www.gnu.org/licenses/>. # along with Web Greeter; If not, see <http://www.gnu.org/licenses/>.
# Standard lib # Standard lib
import sys import sys, argparse, os
import ruamel.yaml as yaml from typing import List
import os
# 3rd-Party Libs # 3rd-Party Libs
from browser.browser import Browser
from logger import logger
import globals import globals
import config import config
def list_themes() -> List[str]:
themes_dir = config.web_greeter_config["app"]["theme_dir"]
themes_dir = themes_dir if os.path.exists(themes_dir) else "/usr/share/web-greeter/themes"
filenames = os.listdir(themes_dir)
dirlist = []
for file in filenames:
if os.path.isdir(os.path.join(themes_dir, file)):
dirlist.append(file)
return dirlist
def print_themes():
themes_dir = config.web_greeter_config["app"]["theme_dir"]
themes_dir = themes_dir if os.path.exists(themes_dir) else "/usr/share/web-greeter/themes"
themes = list_themes()
print("Themes are located in {themes_dir}\n".format(themes_dir = themes_dir))
for theme in themes:
print("-", theme)
def set_theme(theme: str):
config.web_greeter_config["config"]["greeter"]["theme"] = theme
def set_debug(value: bool):
conf = config.web_greeter_config["config"]
app = config.web_greeter_config["app"]
conf["greeter"]["debug_mode"] = value
app["decorated"] = value
app["fullscreen"] = not value
def parse(argv):
version = config.web_greeter_config["app"]["version"]["full"]
parser = argparse.ArgumentParser(prog="web-greeter", add_help=False)
parser.add_argument("-h", "--help", action="help", help="Show this help message and exit")
parser.add_argument("-v", "--version", action="version", version=version, help="Show version number")
parser.add_argument("--debug", action="store_true", help="Run the greeter in debug mode", dest="debug", default=None)
parser.add_argument("--normal", action="store_false", help="Run in non-debug mode", dest="debug")
parser.add_argument("--list", action="store_true", help="List available themes")
parser.add_argument("--theme", help="Set the theme to use", metavar="[name]")
args: argparse.Namespace
try:
args = parser.parse_args(argv)
except argparse.ArgumentError:
sys.exit()
# print(args)
if (args.list):
print_themes()
sys.exit()
if (args.theme):
set_theme(args.theme)
if (args.debug != None):
set_debug(args.debug)
if __name__ == '__main__': if __name__ == '__main__':
parse(sys.argv[1:])
from browser.browser import Browser
globals.greeter = Browser() globals.greeter = Browser()
greeter = globals.greeter greeter = globals.greeter
greeter.run() greeter.run()

3
web-greeter/browser/browser.py

@ -29,7 +29,7 @@
# Standard lib # Standard lib
from browser.window import MainWindow from browser.window import MainWindow
from bridge.devtools import DevTools from browser.devtools import DevTools
import os import os
from typing import ( from typing import (
Dict, Dict,
@ -138,7 +138,6 @@ class Browser(Application):
def init(self): def init(self):
logger.debug("Initializing Browser Window") logger.debug("Initializing Browser Window")
web_greeter_config["config"]["greeter"]["debug_mode"] = True
if web_greeter_config["config"]["greeter"]["debug_mode"]: if web_greeter_config["config"]["greeter"]["debug_mode"]:
os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = '12345' os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = '12345'

3
web-greeter/bridge/devtools.py → web-greeter/browser/devtools.py

@ -32,6 +32,8 @@ from PyQt5.QtWebEngineWidgets import (
QWebEnginePage, QWebEnginePage,
) )
from logger import logger
class DevTools: class DevTools:
def __init__(self): def __init__(self):
@ -42,4 +44,5 @@ class DevTools:
self.view.load(QUrl('http://127.0.0.1:12345')) self.view.load(QUrl('http://127.0.0.1:12345'))
self.view.show() self.view.show()
logger.debug("DevTools initialized")

8
web-greeter/config.py

@ -66,7 +66,13 @@ web_greeter_config = {
"fullscreen": True, "fullscreen": True,
"frame": False, "frame": False,
"debug_mode": False, "debug_mode": False,
"theme_dir": "/usr/share/web-greeter/themes/" "theme_dir": "/usr/share/web-greeter/themes/",
"version": {
"full": "3.0.0",
"major": 3,
"minor": 3,
"micro": 0,
},
} }
} }

Loading…
Cancel
Save