From 03b36a4c186101aaec49d4fc8feeaaed97d6fae8 Mon Sep 17 00:00:00 2001 From: Preston Landers Date: Sun, 8 Nov 2020 13:44:20 -0600 Subject: [PATCH] Don't blow up in the decorator if not on Windows; just run the function even if not root. --- CHANGELOG.md | 5 +++-- README.md | 6 ++++-- pyuac/decorator.py | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 228e98d..0768e4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Changes -## 0.0.1 +## 0.0.2 - - Initial package release based on a cleaned up version of my Gist originally published here: + - Initial public release of a package based on a cleaned up version of my Gist that +was originally published here: https://gist.github.com/Preston-Landers/267391562bc96959eb41 diff --git a/README.md b/README.md index e791770..d0af00a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PyUAC - Python User Access Control +# PyUAC - Python User Access Control for Windows This package provides a way to invoke User Access Control (UAC) in Windows from Python. @@ -22,7 +22,9 @@ See also [tests/example_usage.py](tests/example_usage.py) ### Decorator The decorator is an easy way to ensure your script's main() function will respawn itself -as Admin if necessary. +as Admin if necessary. Note that the decorator has no effect unless on the Windows platform. +It does NOT currently relaunch the script with 'sudo' on Linux or other POSIX platforms. +On non-Windows platforms, it's a no-op. #### Decorator usage example diff --git a/pyuac/decorator.py b/pyuac/decorator.py index 9878d8a..20dc0dd 100644 --- a/pyuac/decorator.py +++ b/pyuac/decorator.py @@ -64,6 +64,9 @@ def main_requires_admin( If return_output is True, the output of the decorated function is a 2-tuple of (stdout, stderr) strings. """ + if os.name != 'nt': + log.debug("Invoked main_requires_admin on a non-Windows platform; doing nothing!") + return run_function(*args, **kwargs) # Should we add another function parameter to run the in the "not-admin" case?