本文整理汇总了Python中posix.stat函数的典型用法代码示例。如果您正苦于以下问题:Python stat函数的具体用法?Python stat怎么用?Python stat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_stat_unicode
def test_stat_unicode(self):
# test that passing unicode would not raise UnicodeDecodeError
import posix
try:
posix.stat(u"ą")
except OSError:
pass
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:test_posix2.py
示例2: exists
def exists(path):
"""Local re-implementation of os.path.exists."""
try:
stat(path)
except EnvironmentError:
return False
return True
开发者ID:cloudmatrix,项目名称:signedimp,代码行数:7,代码来源:bootstrap.py
示例3: cmp
def cmp(f1, f2): # Compare two files, use the cache if possible.
# Return 1 for identical files, 0 for different.
# Raise exceptions if either file could not be statted, read, etc.
s1, s2 = sig(posix.stat(f1)), sig(posix.stat(f2))
if s1[0] <> 8 or s2[0] <> 8:
# Either is a not a plain file -- always report as different
return 0
if s1 = s2:
# type, size & mtime match -- report same
return 1
开发者ID:asottile,项目名称:ancient-pythons,代码行数:10,代码来源:cmp.py
示例4: exists
def exists(path):
"""Local re-implementation of os.path.exists."""
try:
stat(path)
except EnvironmentError, e:
# TODO: how to get the errno under RPython?
if not __rpython__:
if e.errno not in (errno.ENOENT, errno.ENOTDIR, errno.ESRCH):
raise
return False
开发者ID:ccpgames,项目名称:esky,代码行数:10,代码来源:bootstrap.py
示例5: exists
def exists(path):
"""Local re-implementation of os.path.exists."""
try:
stat(path)
except EnvironmentError:
e = sys.exc_info()[1]
if e.errno not in (errno.ENOENT,errno.ENOTDIR,errno.ESRCH,):
raise
else:
return False
else:
return True
开发者ID:FunnyMan3595,项目名称:esky,代码行数:12,代码来源:bootstrap.py
示例6: ismount
def ismount(path):
try:
s1 = posix.stat(path)
s2 = posix.stat(join(path, '..'))
except posix.error:
return 0 # It doesn't exist -- so not a mount point :-)
dev1 = s1[stat.ST_DEV]
dev2 = s2[stat.ST_DEV]
if dev1 != dev2:
return 1 # path/.. on a different device as path
ino1 = s1[stat.ST_INO]
ino2 = s2[stat.ST_INO]
if ino1 == ino2:
return 1 # path/.. is the same i-node as path
return 0
开发者ID:asottile,项目名称:ancient-pythons,代码行数:15,代码来源:posixpath.py
示例7: files
def files(request, publication_id):
publication = get_object_or_404(Publication, pk=publication_id)
filepath = publication.file.__unicode__()
name, ext = splitext(filepath)
filepath_absolute = join(settings.MEDIA_ROOT, filepath)
if not exists(filepath_absolute):
raise Http404
statinfo = stat(filepath_absolute)
mimetype = mimetypes.guess_type(filepath_absolute)
mode = getattr(settings, 'PUBLICATIONS_DOWNLOAD_MODE', '')
if mode == 'apache':
response = HttpResponse(content_type=mimetype)
response['X-Sendfile'] = smart_str(filepath_absolute)
if mode == 'nginx':
response = HttpResponse(content_type=mimetype)
response['X-Accel-Redirect'] = smart_str(settings.MEDIA_URL + filepath)
else:
response = HttpResponse(open(filepath_absolute, "r"), content_type=mimetype)
response['Content-Length'] = statinfo.st_size
response['Content-Disposition'] = 'attachment; filename=%s%s' % (smart_str(publication.generate_identifier()), ext)
response['Cache-Control'] = 'no-cache, must-revalidate'
return response
开发者ID:lukacu,项目名称:django-publications,代码行数:31,代码来源:views.py
示例8: readable
def readable(path):
try:
mode = posix.stat(path)[stat.ST_MODE]
except OSError: # File doesn't exist
sys.stderr.write("%s not found\n"%path)
sys.exit(1)
if not stat.S_ISREG(mode): # or it's not readable
sys.stderr.write("%s not readable\n"%path)
sys.exit(1)
开发者ID:rpmcruz,项目名称:easy-assembly,代码行数:9,代码来源:vpu_tutor.py
示例9: test_posix_stat_result
def test_posix_stat_result(self):
try:
import posix
except ImportError:
return
expect = posix.stat(__file__)
encoded = jsonpickle.encode(expect)
actual = jsonpickle.decode(encoded)
self.assertEqual(expect, actual)
开发者ID:LyleScott,项目名称:jsonpickle,代码行数:9,代码来源:object_test.py
示例10: mkrealdir
def mkrealdir(name):
st = posix.stat(name) # Get the mode
mode = S_IMODE(st[ST_MODE])
linkto = posix.readlink(name)
files = posix.listdir(name)
posix.unlink(name)
posix.mkdir(name, mode)
posix.chmod(name, mode)
linkto = cat('..', linkto)
#
for file in files:
if file not in ('.', '..'):
posix.symlink(cat(linkto, file), cat(name, file))
开发者ID:asottile,项目名称:ancient-pythons,代码行数:13,代码来源:mkreal.py
示例11: mkrealfile
def mkrealfile(name):
st = posix.stat(name) # Get the mode
mode = S_IMODE(st[ST_MODE])
linkto = posix.readlink(name) # Make sure again it's a symlink
f_in = open(name, 'r') # This ensures it's a file
posix.unlink(name)
f_out = open(name, 'w')
while 1:
buf = f_in.read(BUFSIZE)
if not buf: break
f_out.write(buf)
del f_out # Flush data to disk before changing mode
posix.chmod(name, mode)
开发者ID:asottile,项目名称:ancient-pythons,代码行数:13,代码来源:mkreal.py
示例12: listdir
def listdir(path): # List directory contents, using cache
try:
cached_mtime, list = cache[path]
del cache[path]
except RuntimeError:
cached_mtime, list = -1, []
try:
mtime = posix.stat(path)[8]
except posix.error:
return []
if mtime <> cached_mtime:
try:
list = posix.listdir(path)
except posix.error:
return []
list.sort()
cache[path] = mtime, list
return list
开发者ID:tomjackbear,项目名称:python-0.9.1,代码行数:18,代码来源:dircache.py
示例13: stat
def stat(path):
if cache.has_key(path):
return cache[path]
cache[path] = ret = posix.stat(path)
return ret
开发者ID:asottile,项目名称:ancient-pythons,代码行数:5,代码来源:statcache.py
示例14: samefile
def samefile(f1, f2):
s1 = posix.stat(f1)
s2 = posix.stat(f2)
return samestat(s1, s2)
开发者ID:asottile,项目名称:ancient-pythons,代码行数:4,代码来源:posixpath.py
示例15: isfile
def isfile(path):
try:
st = posix.stat(path)
except posix.error:
return 0
return stat.S_ISREG(st[stat.ST_MODE])
开发者ID:asottile,项目名称:ancient-pythons,代码行数:6,代码来源:posixpath.py
示例16: isdir
def isdir(path):
try:
st = posix.stat(path)
except posix.error:
return 0
return stat.S_ISDIR(st[stat.ST_MODE])
开发者ID:asottile,项目名称:ancient-pythons,代码行数:6,代码来源:posixpath.py
示例17: exists
def exists(path):
try:
st = posix.stat(path)
except posix.error:
return 0
return 1
开发者ID:asottile,项目名称:ancient-pythons,代码行数:6,代码来源:posixpath.py
示例18: do_stat
def do_stat(self, path):
if not path:
path = self._work_dir
print posix.stat(path)
开发者ID:wil-langford,项目名称:misc,代码行数:4,代码来源:hshell.py
示例19:
import posix
for file in posix.listdir("."):
print file, posix.stat(file)[6]
## aifc-example-1.py 314
## anydbm-example-1.py 259
## array-example-1.py 48
开发者ID:mtslong,项目名称:demo,代码行数:8,代码来源:posix-example-1.py
示例20: copystat
def copystat(src, dst):
st = posix.stat(src)
mode = divmod(st[0], MODEBITS)[1]
posix.chmod(dst, mode)
posix.utimes(dst, st[7:9])
开发者ID:asottile,项目名称:ancient-pythons,代码行数:5,代码来源:shutil.py
注:本文中的posix.stat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论