Skip to content

Instantly share code, notes, and snippets.

@GreatBahram
Created March 31, 2020 11:52
Show Gist options
  • Select an option

  • Save GreatBahram/c8644026f5feb520f78ffa6422a5d969 to your computer and use it in GitHub Desktop.

Select an option

Save GreatBahram/c8644026f5feb520f78ffa6422a5d969 to your computer and use it in GitHub Desktop.

Revisions

  1. GreatBahram revised this gist Mar 31, 2020. No changes.
  2. GreatBahram created this gist Mar 31, 2020.
    15 changes: 15 additions & 0 deletions decorators.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    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