Created
March 31, 2020 11:52
-
-
Save GreatBahram/c8644026f5feb520f78ffa6422a5d969 to your computer and use it in GitHub Desktop.
Useful decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from functools import wraps | |
def sudo_required(func): | |
"""Check sudo permission, if it hasn't, it'll exit non-zero.""" | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
if os.getuid() != 0: | |
print("Sudo access is required!", file=sys.stderr) | |
raise SystemExit(1) | |
return func(*args, **kwargs) | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment