def __init__(self,
root_path,
create=False,
create_mode=0o777):
"""Create an OSFS instance.
"""
super(OSFS, self).__init__()
root_path = fsdecode(fspath(root_path))
_root_path = os.path.expanduser(os.path.expandvars(root_path))
_root_path = os.path.normpath(os.path.abspath(_root_path))
self.root_path = _root_path
if create:
try:
if not os.path.isdir(_root_path):
os.makedirs(_root_path, mode=create_mode)
except OSError as error:
raise errors.CreateFailed(
'unable to create {} ({})'.format(root_path, error)
)
else:
if not os.path.isdir(_root_path):
raise errors.CreateFailed(
'root path does not exist'
)
_meta = self._meta = {
'case_insensitive': os.path.normcase('Aa') != 'aa',
'network': False,
'read_only': False,
'supports_rename': True,
'thread_safe': True,
'unicode_paths': os.path.supports_unicode_filenames,
'virtual': False,
}
if _WINDOWS_PLATFORM: # pragma: nocover
_meta["invalid_path_chars"] =\
''.join(six.unichr(n) for n in range(31)) + '\\:*?"<>|'
else:
_meta["invalid_path_chars"] = '\0'
if 'PC_PATH_MAX' in os.pathconf_names:
_meta['max_sys_path_length'] = (
os.pathconf(
fsencode(_root_path),
os.pathconf_names['PC_PATH_MAX']
)
)
评论列表
文章目录