本文整理汇总了Python中gdrivefs.cache.volume.PathRelations.get_instance方法的典型用法代码示例。如果您正苦于以下问题:Python PathRelations.get_instance方法的具体用法?Python PathRelations.get_instance怎么用?Python PathRelations.get_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gdrivefs.cache.volume.PathRelations
的用法示例。
在下文中一共展示了PathRelations.get_instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __apply_change
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def __apply_change(self, change_id, change_tuple):
"""Apply changes to our filesystem reported by GD. All we do is remove
the current record components, if it's valid, and then reload it with
what we were given. Note that since we don't necessarily know
about the entries that have been changed, this also allows us to slowly
increase our knowledge of the filesystem (of, obviously, only those
things that change).
"""
(entry_id, was_deleted, entry) = change_tuple
is_visible = entry.is_visible if entry else None
_logger.info("Applying change with change-ID (%d), entry-ID [%s], "
"and is-visible of [%s]",
change_id, entry_id, is_visible)
# First, remove any current knowledge from the system.
_logger.debug("Removing all trace of entry with ID [%s] "
"(apply_change).", entry_id)
PathRelations.get_instance().remove_entry_all(entry_id)
# If it wasn't deleted, add it back.
_logger.debug("Registering changed entry with ID [%s].", entry_id)
if is_visible:
path_relations = PathRelations.get_instance()
path_relations.register_entry(entry)
示例2: rename
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def rename(self, filepath_old, filepath_new):
# Make sure the old filepath exists.
(entry, path, filename_old) = get_entry_or_raise(filepath_old)
# At this point, decorations, the is-hidden prefix, etc.. haven't been
# stripped.
(path, filename_new_raw) = split(filepath_new)
# Make sure the new filepath doesn't exist.
try:
get_entry_or_raise(filepath_new, True)
except GdNotFoundError:
pass
gd = get_gdrive()
try:
entry = gd.rename(entry, filename_new_raw)
except:
_logger.exception("Could not update entry [%s] for rename.", entry)
raise FuseOSError(EIO)
# Update our knowledge of the entry.
path_relations = PathRelations.get_instance()
try:
path_relations.register_entry(entry)
except:
_logger.exception("Could not register renamed entry: %s", entry)
raise FuseOSError(EIO)
示例3: get_by_path
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def get_by_path(raw_path):
try:
result = split_path(raw_path, path_resolver)
(parent_clause, path, filename, mime_type, is_hidden) = result
except:
print("Could not process file-path [%s]." % (raw_path))
exit()
filepath = build_filepath(path, filename)
path_relations = PathRelations.get_instance()
try:
entry_clause = path_relations.get_clause_from_path(filepath)
except GdNotFoundError:
print("Could not retrieve clause for non-existent file-path [%s]." %
(filepath))
exit()
except:
print("Could not retrieve clause for path [%s]. " % (filepath))
exit()
if not entry_clause:
print("Path [%s] does not exist for stat()." % (filepath))
exit()
return entry_clause[CLAUSE_ENTRY]
示例4: __create
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def __create(self, filepath, mode=None):
"""Create a new file.
We don't implement "mode" (permissions) because the model doesn't agree
with GD.
"""
# TODO: Fail if it already exists.
try:
result = split_path(filepath, path_resolver)
(parent_clause, path, filename, mime_type, is_hidden) = result
except GdNotFoundError:
_logger.exception("Could not process [%s] (i-create).", filepath)
raise FuseOSError(ENOENT)
except:
_logger.exception("Could not split path [%s] (i-create).",
filepath)
raise FuseOSError(EIO)
distilled_filepath = build_filepath(path, filename)
# Try to guess at a mime-type, if not otherwise given.
if mime_type is None:
(mimetype_guess, _) = guess_type(filename, True)
if mimetype_guess is not None:
mime_type = mimetype_guess
else:
mime_type = Conf.get('default_mimetype')
gd = get_gdrive()
try:
entry = gd.create_file(
filename,
[parent_clause[3]],
mime_type,
is_hidden=is_hidden)
except:
_logger.exception("Could not create empty file [%s] under "
"parent with ID [%s].",
filename, parent_clause[3])
raise FuseOSError(EIO)
path_relations = PathRelations.get_instance()
try:
path_relations.register_entry(entry)
except:
_logger.exception("Could not register created file in cache.")
raise FuseOSError(EIO)
_logger.info("Inner-create of [%s] completed.", distilled_filepath)
return (entry, path, filename, mime_type)
示例5: rmdir
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def rmdir(self, filepath):
"""Remove a directory."""
path_relations = PathRelations.get_instance()
try:
entry_clause = path_relations.get_clause_from_path(filepath)
except GdNotFoundError:
_logger.exception("Could not process [%s] (rmdir).", filepath)
raise FuseOSError(ENOENT)
except:
_logger.exception("Could not get clause from file-path [%s] "
"(rmdir).", filepath)
raise FuseOSError(EIO)
if not entry_clause:
_logger.error("Path [%s] does not exist for rmdir().", filepath)
raise FuseOSError(ENOENT)
entry_id = entry_clause[CLAUSE_ID]
normalized_entry = entry_clause[CLAUSE_ENTRY]
# Check if not a directory.
if not normalized_entry.is_directory:
_logger.error("Can not rmdir() non-directory [%s] with ID [%s].",
filepath, entry_id)
raise FuseOSError(ENOTDIR)
# Ensure the folder is empty.
gd = get_gdrive()
try:
found = gd.get_children_under_parent_id(
entry_id,
max_results=1)
except:
_logger.exception("Could not determine if directory to be removed "
"has children.", entry_id)
raise FuseOSError(EIO)
if found:
raise FuseOSError(ENOTEMPTY)
try:
gd.remove_entry(normalized_entry)
except (NameError):
raise FuseOSError(ENOENT)
except:
_logger.exception("Could not remove directory [%s] with ID [%s].",
filepath, entry_id)
raise FuseOSError(EIO)
示例6: __create
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def __create(self, filepath, mode=None):
"""Create a new file.
We don't implement "mode" (permissions) because the model doesn't agree
with GD.
"""
# TODO: Fail if it already exists.
try:
result = split_path(filepath, path_resolver)
(parent_clause, path, filename, mime_type, is_hidden) = result
except GdNotFoundError:
_logger.exception("Could not process [%s] (i-create).", filepath)
raise FuseOSError(ENOENT)
except:
_logger.exception("Could not split path [%s] (i-create).",
filepath)
raise FuseOSError(EIO)
if mime_type is None:
_, ext = os.path.splitext(filename)
if ext != '':
ext = ext[1:]
mime_type = utility.get_first_mime_type_by_extension(ext)
distilled_filepath = build_filepath(path, filename)
gd = get_gdrive()
try:
entry = gd.create_file(
filename,
[parent_clause[3]],
mime_type,
is_hidden=is_hidden)
except:
_logger.exception("Could not create empty file [%s] under "
"parent with ID [%s].",
filename, parent_clause[3])
raise FuseOSError(EIO)
path_relations = PathRelations.get_instance()
try:
path_relations.register_entry(entry)
except:
_logger.exception("Could not register created file in cache.")
raise FuseOSError(EIO)
_logger.info("Inner-create of [%s] completed.", distilled_filepath)
return (entry, path, filename, mime_type)
示例7: readdir
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def readdir(self, path, offset):
"""A generator returning one base filename at a time."""
# We expect "offset" to always be (0).
if offset != 0:
self.__log.warning("readdir() has been invoked for path [%s] and non-"
"zero offset (%d). This is not allowed." %
(path, offset))
# TODO: Once we start working on the cache, make sure we don't make this call,
# constantly.
path_relations = PathRelations.get_instance()
self.__log.debug("Listing files.")
try:
entry_clause = path_relations.get_clause_from_path(path)
except GdNotFoundError:
self.__log.exception("Could not process [%s] (readdir).")
raise FuseOSError(ENOENT)
except:
self.__log.exception("Could not get clause from path [%s] "
"(readdir)." % (path))
raise FuseOSError(EIO)
if not entry_clause:
self.__log.debug("Path [%s] does not exist for readdir()." % (path))
raise FuseOSError(ENOENT)
try:
entry_tuples = path_relations.get_children_entries_from_entry_id \
(entry_clause[CLAUSE_ID])
except:
self.__log.exception("Could not render list of filenames under path "
"[%s]." % (path))
raise FuseOSError(EIO)
yield '.'
yield '..'
for (filename, entry) in entry_tuples:
# Decorate any file that -requires- a mime-type (all files can
# merely accept a mime-type)
if entry.requires_mimetype:
filename += '#'
yield filename
示例8: readdir
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def readdir(self, path, offset):
"""A generator returning one base filename at a time."""
# We expect "offset" to always be (0).
if offset != 0:
_logger.warning(
"readdir() has been invoked for path [%s] and " "non-zero offset (%d). This is not allowed.",
path,
offset,
)
# TODO: Once we start working on the cache, make sure we don't make this call,
# constantly.
path_relations = PathRelations.get_instance()
try:
entry_clause = path_relations.get_clause_from_path(path)
except GdNotFoundError:
_logger.exception("Could not process [%s] (readdir).")
raise FuseOSError(ENOENT)
except:
_logger.exception("Could not get clause from path [%s] " "(readdir)." % (path))
raise FuseOSError(EIO)
if not entry_clause:
raise FuseOSError(ENOENT)
try:
entry_tuples = path_relations.get_children_entries_from_entry_id(entry_clause[CLAUSE_ID])
except:
_logger.exception("Could not render list of filenames under path " "[%s].", path)
raise FuseOSError(EIO)
yield utility.translate_filename_charset(".")
yield utility.translate_filename_charset("..")
for (filename, entry) in entry_tuples:
# Decorate any file that -requires- a mime-type (all files can
# merely accept a mime-type)
if entry.requires_mimetype:
filename += utility.translate_filename_charset("#")
yield (filename, self.__build_stat_from_entry(entry), 0)
示例9: __get_entry_or_raise
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def __get_entry_or_raise(self, raw_path, allow_normal_for_missing=False):
try:
result = split_path(raw_path, path_resolver)
(parent_clause, path, filename, mime_type, is_hidden) = result
except GdNotFoundError:
self.__log.exception("Could not retrieve clause for non-existent "
"file-path [%s] (parent does not exist)." %
(raw_path))
if allow_normal_for_missing is True:
raise
else:
raise FuseOSError(ENOENT)
except:
self.__log.exception("Could not process file-path [%s]." %
(raw_path))
raise FuseOSError(EIO)
filepath = build_filepath(path, filename)
path_relations = PathRelations.get_instance()
try:
entry_clause = path_relations.get_clause_from_path(filepath)
except GdNotFoundError:
self.__log.exception("Could not retrieve clause for non-existent "
"file-path [%s] (parent exists)." %
(filepath))
if allow_normal_for_missing is True:
raise
else:
raise FuseOSError(ENOENT)
except:
self.__log.exception("Could not retrieve clause for path [%s]. " %
(filepath))
raise FuseOSError(EIO)
if not entry_clause:
self.__log.debug("Path [%s] does not exist for stat()." % (filepath))
if allow_normal_for_missing is True:
raise GdNotFoundError()
else:
raise FuseOSError(ENOENT)
return (entry_clause[CLAUSE_ENTRY], path, filename)
示例10: mkdir
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def mkdir(self, filepath, mode):
"""Create the given directory."""
# TODO: Implement the "mode".
try:
result = split_path(filepath, path_resolver)
(parent_clause, path, filename, mime_type, is_hidden) = result
except GdNotFoundError:
self.__log.exception("Could not process [%s] (mkdir).")
raise FuseOSError(ENOENT)
except:
self.__log.exception("Could not split path [%s] (mkdir)." %
(filepath))
raise FuseOSError(EIO)
parent_id = parent_clause[CLAUSE_ID]
self.__log.debug("Creating directory [%s] under parent [%s] with ID "
"[%s]." % (filename, path, parent_id))
try:
entry = drive_proxy('create_directory',
filename=filename,
parents=[parent_id],
is_hidden=is_hidden)
except:
self.__log.exception("Could not create directory with name [%s] "
"and parent with ID [%s]." %
(filename, parent_clause[0].id))
raise FuseOSError(EIO)
self.__log.info("Directory [%s] created as ID [%s] under parent with "
"ID [%s]." % (filepath, entry.id, parent_id))
#parent_clause[4] = False
path_relations = PathRelations.get_instance()
try:
path_relations.register_entry(entry)
except:
self.__log.exception("Could not register new directory in cache.")
raise FuseOSError(EIO)
示例11: flush
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def flush(self):
"""The OS wants to effect any changes made to the file."""
_logger.debug("Flushing opened-file.")
entry = self.__cache.get(self.__entry_id)
if self.__is_dirty is False:
_logger.debug("Flush will be skipped for [%s] because there "
"are no changes: [%s] IS_LOADED=[%s] "
"IS_DIRTY=[%d]",
entry.id, self.file_path, self.__is_loaded,
self.__is_dirty)
return
else:
st = os.stat(self.__temp_filepath)
_logger.debug("Pushing (%d) bytes for entry with ID from [%s] to "
"GD for file-path [%s].",
st.st_size, entry.id, self.__temp_filepath)
# TODO: Make sure we sync the mtime to remote.
gd = get_gdrive()
entry = gd.update_entry(
entry,
filename=entry.title,
data_filepath=self.__temp_filepath,
mime_type=self.mime_type,
parents=entry.parents,
is_hidden=self.__is_hidden)
self.__is_dirty = False
# TODO(dustin): For now, we don't cleanup the temporary file. We need to
# schedule this using LRU-semantics.
# Immediately update our current cached entry.
_logger.debug("Update successful. Updating local cache.")
path_relations = PathRelations.get_instance()
path_relations.register_entry(entry)
_logger.info("Update complete on entry with ID [%s].", entry.id)
示例12: rename
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def rename(self, filepath_old, filepath_new):
self.__log.debug("Renaming [%s] to [%s]." %
(filepath_old, filepath_new))
# Make sure the old filepath exists.
(entry, path, filename_old) = self.__get_entry_or_raise(filepath_old)
# At this point, decorations, the is-hidden prefix, etc.. haven't been
# stripped.
(path, filename_new_raw) = split(filepath_new)
# Make sure the new filepath doesn't exist.
try:
self.__get_entry_or_raise(filepath_new, True)
except GdNotFoundError:
pass
try:
entry = drive_proxy('rename', normalized_entry=entry,
new_filename=filename_new_raw)
except:
self.__log.exception("Could not update entry [%s] for rename." %
(entry))
raise FuseOSError(EIO)
# Update our knowledge of the entry.
path_relations = PathRelations.get_instance()
try:
path_relations.register_entry(entry)
except:
self.__log.exception("Could not register renamed entry: %s" %
(entry))
raise FuseOSError(EIO)
示例13: unlink
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def unlink(self, file_path):
"""Remove a file."""
# TODO: Change to simply move to "trash". Have a FUSE option to elect this
# behavior.
path_relations = PathRelations.get_instance()
self.__log.debug("Removing file [%s]." % (file_path))
try:
entry_clause = path_relations.get_clause_from_path(file_path)
except GdNotFoundError:
self.__log.exception("Could not process [%s] (unlink).")
raise FuseOSError(ENOENT)
except:
self.__log.exception("Could not get clause from file-path [%s] "
"(unlink)." % (file_path))
raise FuseOSError(EIO)
if not entry_clause:
self.__log.error("Path [%s] does not exist for unlink()." %
(file_path))
raise FuseOSError(ENOENT)
entry_id = entry_clause[CLAUSE_ID]
normalized_entry = entry_clause[CLAUSE_ENTRY]
# Check if a directory.
self.__log.debug("Ensuring it is a file (not a directory).")
if normalized_entry.is_directory:
self.__log.error("Can not unlink() directory [%s] with ID [%s]. "
"Must be file.", file_path, entry_id)
raise FuseOSError(errno.EISDIR)
self.__log.debug("Doing remove of directory [%s] with ID [%s]." %
(file_path, entry_id))
# Remove online. Complements local removal (if not found locally, a
# follow-up request checks online).
try:
drive_proxy('remove_entry', normalized_entry=normalized_entry)
except (NameError):
raise FuseOSError(ENOENT)
except:
self.__log.exception("Could not remove file [%s] with ID [%s]." %
(file_path, entry_id))
raise FuseOSError(EIO)
# Remove from cache. Will no longer be able to be found, locally.
self.__log.debug("Removing all trace of entry [%s] from cache "
"(unlink)." % (normalized_entry))
try:
PathRelations.get_instance().remove_entry_all(entry_id)
except:
self.__log.exception("There was a problem removing entry [%s] "
"from the caches." % (normalized_entry))
raise
# Remove from among opened-files.
self.__log.debug("Removing all opened-files for [%s]." % (file_path))
try:
opened_file = OpenedManager.get_instance().\
remove_by_filepath(file_path)
except:
self.__log.exception("There was an error while removing all "
"opened-file instances for file [%s] "
"(remove)." % (file_path))
raise FuseOSError(EIO)
self.__log.debug("File removal complete.")
示例14: rmdir
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def rmdir(self, filepath):
"""Remove a directory."""
path_relations = PathRelations.get_instance()
self.__log.debug("Removing directory [%s]." % (filepath))
try:
entry_clause = path_relations.get_clause_from_path(filepath)
except GdNotFoundError:
self.__log.exception("Could not process [%s] (rmdir).")
raise FuseOSError(ENOENT)
except:
self.__log.exception("Could not get clause from file-path [%s] "
"(rmdir)." % (filepath))
raise FuseOSError(EIO)
if not entry_clause:
self.__log.error("Path [%s] does not exist for rmdir()." % (filepath))
raise FuseOSError(ENOENT)
entry_id = entry_clause[CLAUSE_ID]
normalized_entry = entry_clause[CLAUSE_ENTRY]
# Check if not a directory.
self.__log.debug("Ensuring it is a directory.")
if not normalized_entry.is_directory:
self.__log.error("Can not rmdir() non-directory [%s] with ID [%s].", filepath, entry_id)
raise FuseOSError(ENOTDIR)
# Ensure the folder is empty.
self.__log.debug("Checking if empty.")
try:
found = drive_proxy('get_children_under_parent_id',
parent_id=entry_id,
max_results=1)
except:
self.__log.exception("Could not determine if directory to be removed "
"has children." % (entry_id))
raise FuseOSError(EIO)
if found:
raise FuseOSError(ENOTEMPTY)
self.__log.debug("Doing remove of directory [%s] with ID [%s]." %
(filepath, entry_id))
try:
drive_proxy('remove_entry', normalized_entry=normalized_entry)
except (NameError):
raise FuseOSError(ENOENT)
except:
self.__log.exception("Could not remove directory [%s] with ID [%s]." %
(filepath, entry_id))
raise FuseOSError(EIO)
# TODO: Remove from cache.
self.__log.debug("Directory removal complete.")
示例15: __create
# 需要导入模块: from gdrivefs.cache.volume import PathRelations [as 别名]
# 或者: from gdrivefs.cache.volume.PathRelations import get_instance [as 别名]
def __create(self, filepath, mode=None):
"""Create a new file.
We don't implement "mode" (permissions) because the model doesn't agree
with GD.
"""
# TODO: Fail if it already exists.
self.__log.debug("Splitting file-path [%s] for inner create." %
(filepath))
try:
result = split_path(filepath, path_resolver)
(parent_clause, path, filename, mime_type, is_hidden) = result
except GdNotFoundError:
self.__log.exception("Could not process [%s] (i-create).")
raise FuseOSError(ENOENT)
except:
self.__log.exception("Could not split path [%s] (i-create)." %
(filepath))
raise FuseOSError(EIO)
distilled_filepath = build_filepath(path, filename)
self.__log.debug("Acquiring file-handle.")
# Try to guess at a mime-type, if not otherwise given.
if mime_type is None:
(mimetype_guess, _) = guess_type(filename, True)
if mimetype_guess is not None:
mime_type = mimetype_guess
else:
mime_type = Conf.get('default_mimetype')
self.__log.debug("Creating empty file [%s] under parent with ID "
"[%s]." % (filename, parent_clause[3]))
try:
entry = drive_proxy('create_file', filename=filename,
data_filepath='/dev/null',
parents=[parent_clause[3]],
mime_type=mime_type,
is_hidden=is_hidden)
except:
self.__log.exception("Could not create empty file [%s] under "
"parent with ID [%s]." % (filename,
parent_clause[3]))
raise FuseOSError(EIO)
self.__log.debug("Registering created file in cache.")
path_relations = PathRelations.get_instance()
try:
path_relations.register_entry(entry)
except:
self.__log.exception("Could not register created file in cache.")
raise FuseOSError(EIO)
self.__log.info("Inner-create of [%s] completed." %
(distilled_filepath))
return (entry, path, filename, mime_type)