本文整理汇总了Python中stat.ST_MTIME属性的典型用法代码示例。如果您正苦于以下问题:Python stat.ST_MTIME属性的具体用法?Python stat.ST_MTIME怎么用?Python stat.ST_MTIME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类stat
的用法示例。
在下文中一共展示了stat.ST_MTIME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open_local_file
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def open_local_file(self, req):
host = req.get_host()
file = req.get_selector()
localfile = url2pathname(file)
stats = os.stat(localfile)
size = stats[stat.ST_SIZE]
modified = rfc822.formatdate(stats[stat.ST_MTIME])
mtype = mimetypes.guess_type(file)[0]
stats = os.stat(localfile)
headers = mimetools.Message(StringIO(
'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
(mtype or 'text/plain', size, modified)))
if host:
host, port = splitport(host)
if not host or \
(not port and socket.gethostbyname(host) in self.get_names()):
return addinfourl(open(localfile, 'rb'),
headers, 'file:'+file)
raise URLError('file not on local host')
示例2: _check
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def _check(self, uri, template):
if template.filename is None:
return template
try:
template_stat = os.stat(template.filename)
if template.module._modified_time < template_stat[stat.ST_MTIME]:
self._collection.pop(uri, None)
return self._load(template.filename, uri)
else:
return template
except OSError:
self._collection.pop(uri, None)
raise exceptions.TemplateLookupException(
"Cant locate template for uri %r" % uri
)
示例3: _check
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def _check(self, uri, template):
if template.filename is None:
return template
try:
template_stat = os.stat(template.filename)
if template.module._modified_time < \
template_stat[stat.ST_MTIME]:
self._collection.pop(uri, None)
return self._load(template.filename, uri)
else:
return template
except OSError:
self._collection.pop(uri, None)
raise exceptions.TemplateLookupException(
"Cant locate template for uri %r" % uri)
示例4: run
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def run(self):
last_time = os.stat(self.filename)[stat.ST_MTIME]
while 1:
try:
rc = win32event.WaitForSingleObject(self.handle,
win32event.INFINITE)
win32file.FindNextChangeNotification(self.handle)
except win32event.error, details:
# handle closed - thread should terminate.
if details[0] != winerror.ERROR_INVALID_HANDLE:
raise
break
this_time = os.stat(self.filename)[stat.ST_MTIME]
if this_time != last_time:
print "Detected file change - flagging for reload."
self.change_detected = True
last_time = this_time
示例5: CheckLoaderModule
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def CheckLoaderModule(dll_name):
suffix = ""
if is_debug_build: suffix = "_d"
template = os.path.join(this_dir,
"PyISAPI_loader" + suffix + ".dll")
if not os.path.isfile(template):
raise ConfigurationError(
"Template loader '%s' does not exist" % (template,))
# We can't do a simple "is newer" check, as the DLL is specific to the
# Python version. So we check the date-time and size are identical,
# and skip the copy in that case.
src_stat = os.stat(template)
try:
dest_stat = os.stat(dll_name)
except os.error:
same = 0
else:
same = src_stat[stat.ST_SIZE]==dest_stat[stat.ST_SIZE] and \
src_stat[stat.ST_MTIME]==dest_stat[stat.ST_MTIME]
if not same:
log(2, "Updating %s->%s" % (template, dll_name))
shutil.copyfile(template, dll_name)
shutil.copystat(template, dll_name)
else:
log(2, "%s is up to date." % (dll_name,))
示例6: newer
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def newer(source, target):
"""Tells if the target is newer than the source.
Return true if 'source' exists and is more recently modified than
'target', or if 'source' exists and 'target' doesn't.
Return false if both exist and 'target' is the same age or younger
than 'source'. Raise DistutilsFileError if 'source' does not exist.
Note that this test is not very accurate: files created in the same second
will have the same "age".
"""
if not os.path.exists(source):
raise DistutilsFileError("file '%s' does not exist" %
os.path.abspath(source))
if not os.path.exists(target):
return True
return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME]
示例7: __getitem__
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def __getitem__(self,key):
""" db['key'] reading """
fil = self.root / key
try:
mtime = (fil.stat()[stat.ST_MTIME])
except OSError:
raise KeyError(key)
if fil in self.cache and mtime == self.cache[fil][1]:
return self.cache[fil][0]
try:
# The cached item has expired, need to read
with fil.open("rb") as f:
obj = pickle.loads(f.read())
except:
raise KeyError(key)
self.cache[fil] = (obj,mtime)
return obj
示例8: checksum_directory
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def checksum_directory(directory, touch_first=False):
"""
Walk directory structure and return simple checksum based on
file size and modified time.
"""
file_checksums = []
fileL = glob.glob( os.path.join(directory,'*.rst') )
for source_path in fileL:
if touch_first: #
os.utime(source_path, None)
try:
stats = os.stat(source_path)
except OSError:
# ignore temp files and files we don't
# have perms to access
continue
file_checksums.append(
stats[stat.ST_SIZE] + stats[stat.ST_MTIME])
return sum(file_checksums)
示例9: newer
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def newer (source, target):
"""Return true if 'source' exists and is more recently modified than
'target', or if 'source' exists and 'target' doesn't. Return false if
both exist and 'target' is the same age or younger than 'source'.
Raise DistutilsFileError if 'source' does not exist.
"""
if not os.path.exists(source):
raise DistutilsFileError("file '%s' does not exist" %
os.path.abspath(source))
if not os.path.exists(target):
return 1
from stat import ST_MTIME
mtime1 = os.stat(source)[ST_MTIME]
mtime2 = os.stat(target)[ST_MTIME]
return mtime1 > mtime2
# newer ()
示例10: show_statistics
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def show_statistics(self):
"""Show general file and table statistics
"""
print "# File Statistics:"
file_stats = os.stat(self.frm_path)
file_info = {
'Size': file_stats[stat.ST_SIZE],
'Last Modified': time.ctime(file_stats[stat.ST_MTIME]),
'Last Accessed': time.ctime(file_stats[stat.ST_ATIME]),
'Creation Time': time.ctime(file_stats[stat.ST_CTIME]),
'Mode': file_stats[stat.ST_MODE],
}
for value, data in file_info.iteritems():
print "#%22s : %s" % (value, data)
print
# Fail if we cannot read the file
try:
self.frm_file = open(self.frm_path, "rb")
except Exception, error:
raise UtilError("The file %s cannot be read.\n%s" %
(self.frm_path, error))
# Read the file type
示例11: startViewer
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def startViewer(self, Form):
self.screen = 4
if(self.isLive):
self.isLive=False
self.tplImage = "init.png"
if not fotoboxCfg['nopi']:
self.camera.stop_preview()
self.entries = None
self.entries = (os.path.join(self.save, fn) for fn in os.listdir(self.save))
self.entries = ((os.stat(path), path) for path in self.entries)
self.entries = ((stat[ST_MTIME], path)
for stat, path in self.entries if S_ISREG(stat[ST_MODE]))
self.entries = list(self.entries)
if(len(self.entries) > 0):
self.viewerIndex = 0
self.screenViewer(Form)
else:
print("No images to show")
self.screenMain(Form)
示例12: _compile_from_file
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def _compile_from_file(self, path, filename):
if path is not None:
util.verify_directory(os.path.dirname(path))
filemtime = os.stat(filename)[stat.ST_MTIME]
if (
not os.path.exists(path)
or os.stat(path)[stat.ST_MTIME] < filemtime
):
data = util.read_file(filename)
_compile_module_file(
self, data, filename, path, self.module_writer
)
module = compat.load_module(self.module_id, path)
del sys.modules[self.module_id]
if module._magic_number != codegen.MAGIC_NUMBER:
data = util.read_file(filename)
_compile_module_file(
self, data, filename, path, self.module_writer
)
module = compat.load_module(self.module_id, path)
del sys.modules[self.module_id]
ModuleInfo(module, path, self, filename, None, None, None)
else:
# template filename and no module directory, compile code
# in memory
data = util.read_file(filename)
code, module = _compile_text(self, data, filename)
self._source = None
self._code = code
ModuleInfo(module, None, self, filename, code, None, None)
return module
示例13: get_modified_time
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def get_modified_time(self):
"""返回 ``self.absolute_path`` 的最后修改时间.
可以被子类复写. 应当返回一个 `~datetime.datetime`
对象或None.
.. versionadded:: 3.1
"""
stat_result = self._stat()
modified = datetime.datetime.utcfromtimestamp(
stat_result[stat.ST_MTIME])
return modified
示例14: _compile_from_file
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def _compile_from_file(self, path, filename):
if path is not None:
util.verify_directory(os.path.dirname(path))
filemtime = os.stat(filename)[stat.ST_MTIME]
if not os.path.exists(path) or \
os.stat(path)[stat.ST_MTIME] < filemtime:
data = util.read_file(filename)
_compile_module_file(
self,
data,
filename,
path,
self.module_writer)
module = compat.load_module(self.module_id, path)
del sys.modules[self.module_id]
if module._magic_number != codegen.MAGIC_NUMBER:
data = util.read_file(filename)
_compile_module_file(
self,
data,
filename,
path,
self.module_writer)
module = compat.load_module(self.module_id, path)
del sys.modules[self.module_id]
ModuleInfo(module, path, self, filename, None, None)
else:
# template filename and no module directory, compile code
# in memory
data = util.read_file(filename)
code, module = _compile_text(
self,
data,
filename)
self._source = None
self._code = code
ModuleInfo(module, None, self, filename, code, None)
return module
示例15: getmtime
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_MTIME [as 别名]
def getmtime(self):
st = self.stat()
if st:
return st[stat.ST_MTIME]
else:
return None