# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import rsplit [as 别名]
def _base_model(self, path):
"""Build the common base of a contents model"""
info = self._pyfilesystem_instance.getinfo(path, namespaces=['details', 'access'])
try:
# size of file
size = info.size
except (errors.MissingInfoNamespace,):
self.log.warning('Unable to get size.')
size = None
# Use the Unix epoch as a fallback so we don't crash.
try:
last_modified = info.modified or EPOCH_START
except (errors.MissingInfoNamespace,):
self.log.warning('Invalid `modified` for %s', path)
last_modified = EPOCH_START
try:
created = info.created or last_modified
except (errors.MissingInfoNamespace,):
self.log.warning('Invalid `created` for %s', path)
created = EPOCH_START
# Create the base model.
model = {}
model['name'] = path.rsplit('/', 1)[-1]
model['path'] = path
model['last_modified'] = last_modified
model['created'] = created
model['content'] = None
model['format'] = None
model['mimetype'] = None
model['size'] = size
try:
model['writable'] = info.permissions.check('u_w') # TODO check
except (errors.MissingInfoNamespace,):
# if relevant namespace is missing, assume writable
# TODO: decide if this is wise
model['writable'] = True
except OSError:
self.log.error("Failed to check write permissions on %s", path)
model['writable'] = False
return model