本文整理汇总了Python中os.path.getmtime方法的典型用法代码示例。如果您正苦于以下问题:Python path.getmtime方法的具体用法?Python path.getmtime怎么用?Python path.getmtime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.path
的用法示例。
在下文中一共展示了path.getmtime方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def list(self):
dirs = []
# TODO: error management
for d in listdir(self.datapath):
dp = path.join(self.datapath, d)
if path.isdir(dp):
dirs.append({
"name": d,
"path": dp,
"mtime": datetime.datetime.fromtimestamp(path.getmtime(dp)).strftime('%d.%m.%Y %H:%M:%S')
# "size": path.getsize(dp),
# "hsize": self.human_size(self.get_size(dp))
})
dirs.sort(key=lambda dir: dir['name'], reverse=True)
return {'status': 'success', 'data': dirs}
示例2: get_source
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def get_source(self, environment, template):
pieces = split_template_path(template)
for searchpath in self.searchpath:
filename = path.join(searchpath, *pieces)
f = open_if_exists(filename)
if f is None:
continue
try:
contents = f.read().decode(self.encoding)
finally:
f.close()
mtime = path.getmtime(filename)
def uptodate():
try:
return path.getmtime(filename) == mtime
except OSError:
return False
return contents, filename, uptodate
raise TemplateNotFound(template)
示例3: __init__
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def __init__(self, callback, files):
"""
:files: files to be monidtored with full path
"""
self._callback = callback
self._files = files
self.file_mtimes = {
file_name: None for file_name in self._files
}
for k in self.file_mtimes:
if not op.exists(k):
continue
try:
if not op.exists(k):
continue
self.file_mtimes[k] = op.getmtime(k)
except OSError:
log.logger.error("Getmtime for %s, failed: %s",
k, traceback.format_exc())
示例4: get_outdated_docs
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def get_outdated_docs(self):
for docname in self.env.found_docs:
if docname not in self.env.all_docs:
yield docname
continue
targetname = path.join(self.outdir, docname + self.out_suffix)
try:
targetmtime = path.getmtime(targetname)
except Exception:
targetmtime = 0
try:
srcmtime = path.getmtime(self.env.doc2path(docname))
if srcmtime > targetmtime:
yield docname
except EnvironmentError:
pass
示例5: deploy_go
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def deploy_go(app, deltas={}):
"""Deploy a Go application"""
go_path = join(ENV_ROOT, app)
deps = join(APP_ROOT, app, 'Godeps')
first_time = False
if not exists(go_path):
echo("-----> Creating GOPATH for '{}'".format(app), fg='green')
makedirs(go_path)
# copy across a pre-built GOPATH to save provisioning time
call('cp -a $HOME/gopath {}'.format(app), cwd=ENV_ROOT, shell=True)
first_time = True
if exists(deps):
if first_time or getmtime(deps) > getmtime(go_path):
echo("-----> Running godep for '{}'".format(app), fg='green')
env = {
'GOPATH': '$HOME/gopath',
'GOROOT': '$HOME/go',
'PATH': '$PATH:$HOME/go/bin',
'GO15VENDOREXPERIMENT': '1'
}
call('godep update ...', cwd=join(APP_ROOT, app), env=env, shell=True)
return spawn_app(app, deltas)
示例6: get_source
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def get_source(self, environment, template):
pieces = split_template_path(template)
for searchpath in self.searchpath:
filename = path.join(searchpath, *pieces)
f = open_if_exists(filename)
if f is None:
continue
try:
contents = f.read().decode(self.encoding)
finally:
f.close()
mtime = path.getmtime(filename)
def uptodate():
try:
return path.getmtime(filename) == mtime
except OSError:
return False
return contents, filename, uptodate
raise TemplateNotFound(template)
示例7: test_is_cached_without_cachefile
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def test_is_cached_without_cachefile(proc_factory, tmp_path):
infile = tmp_path / 'test_is_cached_without_cachefile.txt'
infile.write_text('')
outfile = tmp_path / 'test_is_cached_without_cachefile_out.txt'
outfile.write_text('')
proc = proc_factory(
'pIsCachedWithoutCacheFile',
input={'infile:file': [infile]},
output=
'outfile:file:{{i.infile | __import__("pathlib").Path | .stem}}.txt')
job = Job(0, proc)
job.rc = 0
job.input
Path(job.output['outfile'][1]).write_text('')
assert job._is_cached_without_cachefile()
#print(job.signature)
job.signature = ''
utime(infile, (path.getmtime(infile) + 100, ) * 2)
#print(job.signature)
assert not job._is_cached_without_cachefile()
示例8: try_download
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def try_download(_path, _file, _url, _stale,):
now = time()
url = URLopener()
file_exists = isfile(_path+_file) == True
if file_exists:
file_old = (getmtime(_path+_file) + _stale) < now
if not file_exists or (file_exists and file_old):
try:
url.retrieve(_url, _path+_file)
result = 'ID ALIAS MAPPER: \'{}\' successfully downloaded'.format(_file)
except IOError:
result = 'ID ALIAS MAPPER: \'{}\' could not be downloaded'.format(_file)
else:
result = 'ID ALIAS MAPPER: \'{}\' is current, not downloaded'.format(_file)
url.close()
return result
# SHORT VERSION - MAKES A SIMPLE {INTEGER ID: 'CALLSIGN'} DICTIONARY
示例9: __init__
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def __init__(self, filename, target_dir):
self.filename = filename
self.target_dir = target_dir
self.thumbloc = .5, .5
self.extract_docstring()
with open(filename, "r") as fid:
self.filetext = fid.read()
outfilename = op.join(target_dir, self.rstfilename)
# Only actually run it if the output RST file doesn't
# exist or it was modified less recently than the example
if (not op.exists(outfilename)
or (op.getmtime(outfilename) < op.getmtime(filename))):
self.exec_file()
else:
print("skipping {0}".format(self.filename))
示例10: __init__
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import getmtime [as 别名]
def __init__(self, filename, target_dir):
self.filename = filename
self.target_dir = target_dir
self.thumbloc = .5, .5
self.extract_docstring()
with open(filename, "r") as fid:
self.filetext = fid.read()
outfilename = op.join(target_dir, self.rstfilename)
# Only actually run it if the output RST file doesn't
# exist or it was modified less recently than the example
if (not op.exists(outfilename) \
or (op.getmtime(outfilename) < op.getmtime(filename))):
self.exec_file()
else:
print("skipping {0}".format(self.filename))