From 38eff8149d7505d1af5d2a67d2f2d7a5bc94d221 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Thu, 28 Jun 2018 14:18:27 +0200 Subject: [PATCH] Changed cofig editor to system default (#41), used more readable code for user detection (#46) --- debian/postinst | 2 +- src/cli.py | 10 +++++++--- src/cli/config.py | 7 ++----- src/config.ini | 3 +-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/debian/postinst b/debian/postinst index 5c40df6..e551f71 100755 --- a/debian/postinst +++ b/debian/postinst @@ -223,7 +223,7 @@ if "HOWDY_NO_PROMPT" not in os.environ: diag_out += "```" # Print it all as a clickable link to a new github issue - print("https://github.com/Boltgolt/howdy-reports/issues/new?title=Post-installation%20camera%20information&body=" + urllib.parse.quote_plus(diag_out) + "\n") + print("https://github.com/boltgolt/howdy-reports/issues/new?title=Post-installation%20camera%20information&body=" + urllib.parse.quote_plus(diag_out) + "\n") # Let the user know what to do with the link print("Installation complete.") diff --git a/src/cli.py b/src/cli.py index 31cc9c1..a937594 100755 --- a/src/cli.py +++ b/src/cli.py @@ -10,10 +10,13 @@ import argparse import builtins # Try to get the original username (not "root") from shell -user = subprocess.check_output("echo $(logname 2>/dev/null || echo $SUDO_USER)", shell=True).decode("ascii").strip() +try: + user = os.getlogin() +except: + user = os.environ.get("SUDO_USER") # If that fails, try to get the direct user -if user == "root" or user == "": +if user == "root" or user == None: env_user = getpass.getuser().strip() # If even that fails, error out @@ -73,7 +76,8 @@ builtins.howdy_user = args.user # Check if we have rootish rights # This is this far down the file so running the command for help is always possible if os.getenv("SUDO_USER") is None: - print("Please run this command with sudo") + print("Please run this command as root:\n") + print("\tsudo howdy " + " ".join(sys.argv[1:])) sys.exit(1) # Beond this point the user can't change anymore, if we still have root as user we need to abort diff --git a/src/cli/config.py b/src/cli/config.py index 0df3a15..9606f24 100644 --- a/src/cli/config.py +++ b/src/cli/config.py @@ -6,10 +6,7 @@ import time import subprocess # Let the user know what we're doing -print("Opening config.ini in gedit") +print("Opening config.ini in the default editor") # Open gedit as a subprocess and fork it -subprocess.Popen(["gedit", os.path.dirname(os.path.realpath(__file__)) + "/../config.ini"], - cwd="/", - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) +subprocess.call(["/etc/alternatives/editor", os.path.dirname(os.path.realpath(__file__)) + "/../config.ini"]) diff --git a/src/config.ini b/src/config.ini index ac5e06d..dfdd304 100644 --- a/src/config.ini +++ b/src/config.ini @@ -1,4 +1,5 @@ # Howdy config file +# Press CTRL + X to save in the nano editor [core] # Do not print anything when a face verification succeeds @@ -46,5 +47,3 @@ dark_threshold = 50 [debug] # Show a short but detailed diagnostic report in console end_report = false - -dummy = true