本文整理汇总了Python中os.getegid方法的典型用法代码示例。如果您正苦于以下问题:Python os.getegid方法的具体用法?Python os.getegid怎么用?Python os.getegid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.getegid方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tearDown
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def tearDown(self):
dist_coverage_path = os.path.join(MARS_ROOT, '.dist-coverage')
if os.path.exists(dist_coverage_path):
# change ownership of coverage files
if find_executable('sudo'):
proc = subprocess.Popen(['sudo', '-n', 'chown', '-R', '%d:%d' % (os.geteuid(), os.getegid()),
dist_coverage_path], shell=False)
proc.wait()
# rewrite paths in coverage result files
for fn in glob.glob(os.path.join(dist_coverage_path, '.coverage.*')):
if 'COVERAGE_FILE' in os.environ:
new_cov_file = os.environ['COVERAGE_FILE'] \
+ os.path.basename(fn).replace('.coverage', '')
else:
new_cov_file = fn.replace('.dist-coverage' + os.sep, '')
shutil.copyfile(fn, new_cov_file)
shutil.rmtree(dist_coverage_path)
示例2: tearDown
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def tearDown(self):
time.sleep(5)
dist_coverage_path = os.path.join(MARS_ROOT, '.dist-coverage')
if os.path.exists(dist_coverage_path):
# change ownership of coverage files
if find_executable('sudo'):
proc = subprocess.Popen(['sudo', '-n', 'chown', '-R', '%d:%d' % (os.geteuid(), os.getegid()),
dist_coverage_path], shell=False)
proc.wait()
# rewrite paths in coverage result files
for fn in glob.glob(os.path.join(dist_coverage_path, '.coverage.*')):
cov_db = sqlite3.connect(fn)
c = cov_db.cursor()
c.execute('UPDATE file SET path=REPLACE(path, \'%s\', \'\')' % (MARS_ROOT + os.path.sep))
cov_db.commit()
cov_db.close()
if 'COVERAGE_FILE' in os.environ:
new_cov_file = os.environ['COVERAGE_FILE'] \
+ os.path.basename(fn).replace('.coverage', '')
else:
new_cov_file = fn.replace('.dist-coverage' + os.sep, '')
shutil.copyfile(fn, new_cov_file)
shutil.rmtree(dist_coverage_path)
示例3: check_enableusersite
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def check_enableusersite():
"""Check if user site directory is safe for inclusion
The function tests for the command line flag (including environment var),
process uid/gid equal to effective uid/gid.
None: Disabled for security reasons
False: Disabled by user (command line option)
True: Safe and enabled
"""
if sys.flags.no_user_site:
return False
if hasattr(os, "getuid") and hasattr(os, "geteuid"):
# check process uid == effective uid
if os.geteuid() != os.getuid():
return None
if hasattr(os, "getgid") and hasattr(os, "getegid"):
# check process gid == effective gid
if os.getegid() != os.getgid():
return None
return True
示例4: testNoArgFunctions
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def testNoArgFunctions(self):
# test posix functions which take no arguments and have
# no side-effects which we need to cleanup (e.g., fork, wait, abort)
NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdu", "uname",
"times", "getloadavg", "tmpnam",
"getegid", "geteuid", "getgid", "getgroups",
"getpid", "getpgrp", "getppid", "getuid",
]
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "", DeprecationWarning)
for name in NO_ARG_FUNCTIONS:
posix_func = getattr(posix, name, None)
if posix_func is not None:
posix_func()
self.assertRaises(TypeError, posix_func, 1)
示例5: test_getgroups
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def test_getgroups(self):
with os.popen('id -G 2>/dev/null') as idg:
groups = idg.read().strip()
ret = idg.close()
if ret != None or not groups:
raise unittest.SkipTest("need working 'id -G'")
# Issues 16698: OS X ABIs prior to 10.6 have limits on getgroups()
if sys.platform == 'darwin':
import sysconfig
dt = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') or '10.0'
if tuple(int(n) for n in dt.split('.')[0:2]) < (10, 6):
raise unittest.SkipTest("getgroups(2) is broken prior to 10.6")
# 'id -G' and 'os.getgroups()' should return the same
# groups, ignoring order and duplicates.
# #10822 - it is implementation defined whether posix.getgroups()
# includes the effective gid so we include it anyway, since id -G does
self.assertEqual(
set([int(x) for x in groups.split()]),
set(posix.getgroups() + [posix.getegid()]))
示例6: check_enableusersite
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def check_enableusersite():
"""Check if user site directory is safe for inclusion
The function tests for the command line flag (including environment var),
process uid/gid equal to effective uid/gid.
None: Disabled for security reasons
False: Disabled by user (command line option)
True: Safe and enabled
"""
if hasattr(sys, 'flags') and getattr(sys.flags, 'no_user_site', False):
return False
if hasattr(os, "getuid") and hasattr(os, "geteuid"):
# check process uid == effective uid
if os.geteuid() != os.getuid():
return None
if hasattr(os, "getgid") and hasattr(os, "getegid"):
# check process gid == effective gid
if os.getegid() != os.getgid():
return None
return True
示例7: test_getgroups
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def test_getgroups(self):
with os.popen('id -G') as idg:
groups = idg.read().strip()
ret = idg.close()
if ret != None or not groups:
raise unittest.SkipTest("need working 'id -G'")
# Issues 16698: OS X ABIs prior to 10.6 have limits on getgroups()
if sys.platform == 'darwin':
import sysconfig
dt = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') or '10.0'
if float(dt) < 10.6:
raise unittest.SkipTest("getgroups(2) is broken prior to 10.6")
# 'id -G' and 'os.getgroups()' should return the same
# groups, ignoring order and duplicates.
# #10822 - it is implementation defined whether posix.getgroups()
# includes the effective gid so we include it anyway, since id -G does
self.assertEqual(
set([int(x) for x in groups.split()]),
set(posix.getgroups() + [posix.getegid()]))
示例8: _execChild
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def _execChild(self, path, uid, gid, executable, args, environment):
"""
The exec() which is done in the forked child.
"""
if path:
os.chdir(path)
if uid is not None or gid is not None:
if uid is None:
uid = os.geteuid()
if gid is None:
gid = os.getegid()
# set the UID before I actually exec the process
os.setuid(0)
os.setgid(0)
switchUID(uid, gid)
os.execvpe(executable, args, environment)
示例9: test_getPrivateKeysAsRoot
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def test_getPrivateKeysAsRoot(self):
"""
L{OpenSSHFactory.getPrivateKeys} should switch to root if the keys
aren't readable by the current user.
"""
keyFile = self.keysDir.child("ssh_host_two_key")
# Fake permission error by changing the mode
keyFile.chmod(0000)
self.addCleanup(keyFile.chmod, 0o777)
# And restore the right mode when seteuid is called
savedSeteuid = os.seteuid
def seteuid(euid):
keyFile.chmod(0o777)
return savedSeteuid(euid)
self.patch(os, "seteuid", seteuid)
keys = self.factory.getPrivateKeys()
self.assertEqual(len(keys), 2)
keyTypes = keys.keys()
self.assertEqual(set(keyTypes), set([b'ssh-rsa', b'ssh-dss']))
self.assertEqual(self.mockos.seteuidCalls, [0, os.geteuid()])
self.assertEqual(self.mockos.setegidCalls, [0, os.getegid()])
示例10: create_user
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def create_user():
try:
subprocess.check_output(['sudo', 'useradd', '-m', TEST_USER, '-g',
str(os.getegid())])
except OSError as e:
if e.errno == errno.ENOENT:
raise unittest.SkipTest(
"The 'useradd' command did not exist so unable to test "
"impersonation; Skipping Test. These tests can only be run on a "
"linux host that supports 'useradd'."
)
else:
raise unittest.SkipTest(
"The 'useradd' command exited non-zero; Skipping tests. Does the "
"current user have permission to run 'useradd' without a password "
"prompt (check sudoers file)?"
)
示例11: check_enableusersite
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def check_enableusersite():
"""Check if user site directory is safe for inclusion
The function tests for the command line flag (including environment var),
process uid/gid equal to effective uid/gid.
None: Disabled for security reasons
False: Disabled by user (command line option)
True: Safe and enabled
"""
if hasattr(sys, "flags") and getattr(sys.flags, "no_user_site", False):
return False
if hasattr(os, "getuid") and hasattr(os, "geteuid"):
# check process uid == effective uid
if os.geteuid() != os.getuid():
return None
if hasattr(os, "getgid") and hasattr(os, "getegid"):
# check process gid == effective gid
if os.getegid() != os.getgid():
return None
return True
示例12: test_getgroups
# 需要导入模块: import os [as 别名]
# 或者: from os import getegid [as 别名]
def test_getgroups(self):
with os.popen('id -G 2>/dev/null') as idg:
groups = idg.read().strip()
ret = idg.close()
if ret is not None or not groups:
raise unittest.SkipTest("need working 'id -G'")
# Issues 16698: OS X ABIs prior to 10.6 have limits on getgroups()
if sys.platform == 'darwin':
import sysconfig
dt = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') or '10.0'
if tuple(int(n) for n in dt.split('.')[0:2]) < (10, 6):
raise unittest.SkipTest("getgroups(2) is broken prior to 10.6")
# 'id -G' and 'os.getgroups()' should return the same
# groups, ignoring order and duplicates.
# #10822 - it is implementation defined whether posix.getgroups()
# includes the effective gid so we include it anyway, since id -G does
self.assertEqual(
set([int(x) for x in groups.split()]),
set(posix.getgroups() + [posix.getegid()]))
# tests for the posix *at functions follow