本文整理汇总了Python中posix.stat函数的典型用法代码示例。如果您正苦于以下问题:Python stat函数的具体用法?Python stat怎么用?Python stat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例2: exists
def exists(path):
"""Local re-implementation of os.path.exists."""
try:
stat(path)
except EnvironmentError:
return False
return True
示例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
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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))
示例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)
示例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
示例13: stat
def stat(path):
if cache.has_key(path):
return cache[path]
cache[path] = ret = posix.stat(path)
return ret
示例14: samefile
def samefile(f1, f2):
s1 = posix.stat(f1)
s2 = posix.stat(f2)
return samestat(s1, s2)
示例15: isfile
def isfile(path):
try:
st = posix.stat(path)
except posix.error:
return 0
return stat.S_ISREG(st[stat.ST_MODE])