本文整理汇总了Python中twisted.python.filepath.FilePath.getModificationTime方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.getModificationTime方法的具体用法?Python FilePath.getModificationTime怎么用?Python FilePath.getModificationTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.getModificationTime方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_revokations
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getModificationTime [as 别名]
def load_revokations(self):
"""
Load PEM formatted certificates that are no longer trustworthy
and store the suject and issuer.
`cert_list` is the path to a file that contains glob-like patterns
to PEM-formatted certificates.
"""
revoke_file = self.revoke_file
revoke_state = self.revoke_state
if revoke_file is not None:
last_mod_time = revoke_state['last_mod_time']
fp = FilePath(revoke_file)
if not fp.exists():
return
mod_time = fp.getModificationTime()
if last_mod_time is None or mod_time > last_mod_time:
log.msg("[INFO] Loading revoked certificate files specified in '{0}'.".format(
revoke_file))
revoke_state['last_mod_time'] = mod_time
revoked = set([])
with open(revoke_file) as f:
for line in f:
pattern = line.rstrip('\r\n')
if pattern == '' or pattern.startswith('#'):
continue
for path in glob.glob(pattern):
certs = [pem_cert_to_x509(cert)
for cert in pem.parse_file(path)]
for certificate in certs:
revoked.add((
tuple(certificate.get_subject().get_components()),
tuple(certificate.get_issuer().get_components())))
revoke_state['revoked'] = revoked
示例2: _reload
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getModificationTime [as 别名]
def _reload(self):
"""
"""
path = self._path
filepath = FilePath(path)
modtime = filepath.getModificationTime()
if modtime != self._modtime:
log.msg("[INFO][JSONServiceRegistry] Reloading service registry '%s' ..." % self._path)
self._modtime = modtime
with open(path, 'r') as f:
self._registry = json.load(f)
self._apply_defaults()
self._cache = {}
reactor.callLater(self.poll_interval, self._reload)
示例3: get_index
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getModificationTime [as 别名]
def get_index(self, path):
index = {}
for root, dirs, files in os.walk(path):
index[root] = {}
for f in files:
path = os.path.join(root, f)
filepath = FilePath(path)
try:
index[path] = {
'mtime': filepath.getModificationTime(),
'size': filepath.getsize(),
}
except OSError:
# file could be a broken symlink, or deleted mid-scan
continue
return index
示例4: test_addMtime
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getModificationTime [as 别名]
def test_addMtime(self):
"""
L{tree.addMtime} inserts a text node giving the last modification time
of the specified file wherever it encounters an element with the
I{mtime} class.
"""
path = FilePath(self.mktemp())
path.setContent("")
when = time.ctime(path.getModificationTime())
parent = dom.Element("div")
mtime = dom.Element("span")
mtime.setAttribute("class", "mtime")
parent.appendChild(mtime)
tree.addMtime(parent, path.path)
self.assertEqual(mtime.toxml(), '<span class="mtime">' + when + "</span>")
示例5: getDirectory
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import getModificationTime [as 别名]
def getDirectory(self, path='/'):
self.fs = yield FilePath(path)
if not self.fs.getPermissions():
defer.returnValue(False)
files = []
for f in self.fs.listdir():
if f == '/':
continue
fp = path+f
fs = FilePath(fp)
# dont follow symlinks
if fs.realpath().path != fp:
continue
perm = None
isdir = fs.isdir()
size = fs.getsize()
modified = datetime.utcfromtimestamp(fs.getModificationTime())
df = DiscoveredFile(
resource_id=self.data['resource_id'],
file_path=path,
file_name=f,
file_isdir=isdir,
file_size=size,
file_modified=modified,
file_perm=perm
)
print '[%s] LIST %s.' % (self.data['resource_name'], fp if not fp.endswith('.') else fp)
files.append(df)
defer.returnValue(files)