From: Aneurin Price Date: Fri, 13 May 2011 13:19:42 +0000 (+0100) Subject: Add is_superuser() helper function X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=9a733b8cba5c27df0f5e844076ac1b3efd00ea68;p=packages%2Fb%2Fbup.git Add is_superuser() helper function This checks for an effective UID of 0 on most platforms, or the result of the IsUserAnAdmin shell32 function on Cygwin. Signed-off-by: Aneurin Price --- diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index 13125af..d9d177c 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -1,7 +1,7 @@ """Helper functions and classes for bup.""" import sys, os, pwd, subprocess, errno, socket, select, mmap, stat, re, struct -import heapq, operator, time +import heapq, operator, time, platform from bup import _version, _helpers import bup._helpers as _helpers @@ -203,6 +203,14 @@ def detect_fakeroot(): return os.getenv("FAKEROOTKEY") != None +def is_superuser(): + if platform.system().startswith('CYGWIN'): + import ctypes + return ctypes.cdll.shell32.IsUserAnAdmin() + else: + return os.geteuid() == 0 + + _username = None def username(): """Get the user's login name."""