Skip to content

Instantly share code, notes, and snippets.

@GreatBahram
Created March 31, 2020 11:52
Show Gist options
  • Save GreatBahram/c8644026f5feb520f78ffa6422a5d969 to your computer and use it in GitHub Desktop.
Save GreatBahram/c8644026f5feb520f78ffa6422a5d969 to your computer and use it in GitHub Desktop.
Useful decorators
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