本文整理汇总了Python中stat.ST_MODE属性的典型用法代码示例。如果您正苦于以下问题:Python stat.ST_MODE属性的具体用法?Python stat.ST_MODE怎么用?Python stat.ST_MODE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类stat
的用法示例。
在下文中一共展示了stat.ST_MODE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def __call__(self, step):
slavever = step.slaveVersion('stat')
if not slavever:
raise BuildSlaveTooOldError("slave is too old, does not know "
"about stat")
def commandComplete(cmd):
if cmd.rc != 0:
return False
s = cmd.updates["stat"][-1]
filemode = s[stat.ST_MODE]
if stat.S_ISREG(filemode) or stat.S_ISLNK(filemode):
# True only if this is a file or a link and not any other file
# system object.
return True
else:
return False
cmd = LoggedRemoteCommand('stat', {'file': self.filename})
d = step.runCommand(cmd)
d.addCallback(lambda res: commandComplete(cmd))
return d
示例2: _check_cert
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def _check_cert(filename):
"""
Does this certificate file look okay?
Returns error message, or None if okay
"""
try:
st = os.stat(filename)
except OSError:
return filename + " doesn't exist"
else:
good_perm = stat.S_IFREG | stat.S_IRUSR # | stat.S_IWUSR
if (st[stat.ST_UID], st[stat.ST_GID]) != (0,0):
return 'not owned by root.root'
perm = st[stat.ST_MODE]
if good_perm != perm:
return "expected permissions %o but found %o." % (good_perm, perm)
示例3: unpack_and_compile
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def unpack_and_compile(self, egg_path, destination):
to_compile = []
to_chmod = []
def pf(src, dst):
if dst.endswith('.py') and not src.startswith('EGG-INFO/'):
to_compile.append(dst)
elif dst.endswith('.dll') or dst.endswith('.so'):
to_chmod.append(dst)
self.unpack_progress(src, dst)
return not self.dry_run and dst or None
unpack_archive(egg_path, destination, pf)
self.byte_compile(to_compile)
if not self.dry_run:
for f in to_chmod:
mode = ((os.stat(f)[stat.ST_MODE]) | 0o555) & 0o7755
chmod(f, mode)
示例4: __init__
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def __init__(self, devname=None):
if devname is None:
self.name = "/dev/urandom"
else:
self.name = devname
# Test that /dev/urandom is a character special device
f = open(self.name, "rb", 0)
fmode = os.fstat(f.fileno())[stat.ST_MODE]
if not stat.S_ISCHR(fmode):
f.close()
raise TypeError("%r is not a character special device" % (self.name,))
self.__file = f
BaseRNG.__init__(self)
示例5: writefile
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def writefile(cluster, indices, source, destination, timeout=DEFAULT_AGENT_TIMEOUT):
try:
with open(source) as f:
source_data = f.read()
perms = os.stat(source)[stat.ST_MODE]
except IOError as err:
raise PcoccError("unable to read source file for copy: {}".format(err))
start_time = time.time()
ret = AgentCommand.writefile(cluster, indices,
path=destination, data=source_data,
perms=perms, append=False, timeout=timeout)
for k, e in ret.iterate():
click.secho("vm{}: {}".format(k, e), fg='red', err=True)
click.secho("{} VMs answered in {:.2f}s".format(
len(indices), time.time() - start_time),
fg='green', err=True)
ret.raise_errors()
示例6: copyFunc
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def copyFunc(dest, source, env):
"""Install a source file or directory into a destination by copying,
(including copying permission/mode bits)."""
if os.path.isdir(source):
if os.path.exists(dest):
if not os.path.isdir(dest):
raise SCons.Errors.UserError("cannot overwrite non-directory `%s' with a directory `%s'" % (str(dest), str(source)))
else:
parent = os.path.split(dest)[0]
if not os.path.exists(parent):
os.makedirs(parent)
scons_copytree(source, dest)
else:
shutil.copy2(source, dest)
st = os.stat(source)
os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
return 0
#
# Functions doing the actual work of the InstallVersionedLib Builder.
#
示例7: CacheRetrieveFunc
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def CacheRetrieveFunc(target, source, env):
t = target[0]
fs = t.fs
cd = env.get_CacheDir()
cachedir, cachefile = cd.cachepath(t)
if not fs.exists(cachefile):
cd.CacheDebug('CacheRetrieve(%s): %s not in cache\n', t, cachefile)
return 1
cd.CacheDebug('CacheRetrieve(%s): retrieving from %s\n', t, cachefile)
if SCons.Action.execute_actions:
if fs.islink(cachefile):
fs.symlink(fs.readlink(cachefile), t.get_internal_path())
else:
env.copy_from_cache(cachefile, t.get_internal_path())
try:
os.utime(cachefile, None)
except OSError:
pass
st = fs.stat(cachefile)
fs.chmod(t.get_internal_path(), stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
return 0
示例8: unpack_and_compile
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def unpack_and_compile(self, egg_path, destination):
to_compile = []
to_chmod = []
def pf(src, dst):
if dst.endswith('.py') and not src.startswith('EGG-INFO/'):
to_compile.append(dst)
elif dst.endswith('.dll') or dst.endswith('.so'):
to_chmod.append(dst)
self.unpack_progress(src,dst)
return not self.dry_run and dst or None
unpack_archive(egg_path, destination, pf)
self.byte_compile(to_compile)
if not self.dry_run:
for f in to_chmod:
mode = ((os.stat(f)[stat.ST_MODE]) | 0o555) & 0o7755
chmod(f, mode)
示例9: CacheRetrieveFunc
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def CacheRetrieveFunc(target, source, env):
t = target[0]
fs = t.fs
cd = env.get_CacheDir()
cachedir, cachefile = cd.cachepath(t)
if not fs.exists(cachefile):
cd.CacheDebug('CacheRetrieve(%s): %s not in cache\n', t, cachefile)
return 1
cd.CacheDebug('CacheRetrieve(%s): retrieving from %s\n', t, cachefile)
if SCons.Action.execute_actions:
if fs.islink(cachefile):
fs.symlink(fs.readlink(cachefile), t.get_internal_path())
else:
env.copy_from_cache(cachefile, t.get_internal_path())
st = fs.stat(cachefile)
fs.chmod(t.get_internal_path(), stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
return 0
示例10: copyFunc
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def copyFunc(dest, source, env):
"""Install a source file or directory into a destination by copying,
(including copying permission/mode bits)."""
if os.path.isdir(source):
if os.path.exists(dest):
if not os.path.isdir(dest):
raise SCons.Errors.UserError("cannot overwrite non-directory `%s' with a directory `%s'" % (str(dest), str(source)))
else:
parent = os.path.split(dest)[0]
if not os.path.exists(parent):
os.makedirs(parent)
shutil.copytree(source, dest)
else:
shutil.copy2(source, dest)
st = os.stat(source)
os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
return 0
示例11: __init__
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def __init__(self, name, directory, defaultMode=None):
"""
Create a log file.
@param name: name of the file
@param directory: directory holding the file
@param defaultMode: permissions used to create the file. Default to
current permissions of the file if the file exists.
"""
self.directory = directory
self.name = name
self.path = os.path.join(directory, name)
if defaultMode is None and os.path.exists(self.path):
self.defaultMode = stat.S_IMODE(os.stat(self.path)[stat.ST_MODE])
else:
self.defaultMode = defaultMode
self._openFile()
示例12: getPermissionString
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def getPermissionString(path):
""" Get permissions string for a file's mode.
Qt.py compatibility fix since QFileInfo.permissions isn't in PySide2.
:Parameters:
path : `str`
File path
:Returns:
String corresponding to read (r), write (w), and execute (x) permissions for file.
"""
mode = os.stat(path)[stat.ST_MODE]
perms = "-"
for who in "USR", "GRP", "OTH":
for what in "R", "W", "X":
if mode & getattr(stat, "S_I" + what + who):
perms += what.lower()
else:
perms += "-"
return perms
示例13: test_cache_failure_warns
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def test_cache_failure_warns(self, testdir, monkeypatch):
monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1")
cache_dir = str(testdir.tmpdir.ensure_dir(".pytest_cache"))
mode = os.stat(cache_dir)[stat.ST_MODE]
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0)
try:
testdir.makepyfile("def test_error(): raise Exception")
result = testdir.runpytest()
assert result.ret == 1
# warnings from nodeids, lastfailed, and stepwise
result.stdout.fnmatch_lines(
[
# Validate location/stacklevel of warning from cacheprovider.
"*= warnings summary =*",
"*/cacheprovider.py:*",
" */cacheprovider.py:*: PytestCacheWarning: could not create cache path "
"{}/v/cache/nodeids".format(cache_dir),
' config.cache.set("cache/nodeids", sorted(self.cached_nodeids))',
"*1 failed, 3 warnings in*",
]
)
finally:
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(mode)
示例14: check_and_process
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def check_and_process(pathname, atftype, verbose=False):
mode = os.stat(pathname)[ST_MODE]
if S_ISREG(mode) and pathname.lower().endswith('.atf'):
# It's a file, call the callback function
if verbose:
click.echo('Info: Parsing {0}.'.format(pathname))
check_atf(pathname, atftype, verbose)
示例15: findall
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MODE [as 别名]
def findall(dir = os.curdir):
"""Find all files under 'dir' and return the list of full filenames
(relative to 'dir').
"""
from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK
list = []
stack = [dir]
pop = stack.pop
push = stack.append
while stack:
dir = pop()
names = os.listdir(dir)
for name in names:
if dir != os.curdir: # avoid the dreaded "./" syndrome
fullname = os.path.join(dir, name)
else:
fullname = name
# Avoid excess stat calls -- just one will do, thank you!
stat = os.stat(fullname)
mode = stat[ST_MODE]
if S_ISREG(mode):
list.append(fullname)
elif S_ISDIR(mode) and not S_ISLNK(mode):
push(fullname)
return list