本文整理匯總了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))