本文整理汇总了Python中entry.Entry.addChild方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.addChild方法的具体用法?Python Entry.addChild怎么用?Python Entry.addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entry.Entry
的用法示例。
在下文中一共展示了Entry.addChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VirtualFileSystem
# 需要导入模块: from entry import Entry [as 别名]
# 或者: from entry.Entry import addChild [as 别名]
#.........这里部分代码省略.........
# If it is given the path to a file, it will return a list with one entry which is that file.
# If any subdirectories are listed, their path will be prefixed with a d such as "d/path/to/dir".
#
# @param path The path to list
#
# @return A list of strings in the directory
#
# @throws EntryNotFoundError If the given path does not exist
def list(self, path):
self.checkPath(path)
#Handle the special case of list('/')
if path == '/':
retVal = []
for source in self.dataSources.keys():
retVal.append("d/{0}".format(source))
return retVal
#Get the source to call
source = path.split('/')[1]
return self.dataSources[source].list(path)
##
# This function takes an Entry and adds it to the given data source.
#
# @param entry The Entry to add
# @param source The source to add it to
#
# @return A new entry
#
# @throws UploadNotSupportedError If uploading to the given source is not supported
def put(self, entry, source):
if source not in self.dataSources.keys():
raise ValueError("Given source does not exist")
return self.dataSources[source].put(entry)
##
# This function searches through all sources to find matching entries
#
# @param metadata A dict of metadata which consists of keys such as "artist" or "genre". As many as possible will be matches, and each additional value will be considered an AND
#
# @return A list of paths to matching files
def search(self, metadata):
if metadata is None or len(metadata) == 0:
raise ValueError("Invalid metadata given")
matches = []
for source in self.dataSources:
matches.extend(self.dataSources[source].search(metadata))
return matches
##
# Loads the given data source into the VirtualFileSystem
#
# @param source The source to add, must extend IStoragePlugin
#
# @throw ValueError if the sources does not extend IStoragePlugin
def loadDataSource(self, source):
if not isinstance(source, IStoragePlugin):
raise ValueError("source did not extend IStoragePlugin")
self.dataSources[source.name] = source
source.tree.parent = self.vfsRoot
self.vfsRoot.addChild(source.tree)
##
# Unloads the given data source from the VirtualFileSystem
#
# @param name The name of the source to unload
def unloadDataSource(self, name):
if name == None or name not in self.dataSources.keys():
raise ValueError("Invalid name")
self.vfsRoot.removeChild(self.dataSources[name].tree)
del self.dataSources[name]
##
# This function check to see if a path is valid.
# A valid path is a string that is not empty and starts with / or d/
#
# @param path The path to check
#
# @return Returns FILE if it is a file path and DIR if it is a directory
@staticmethod
def checkPath(path):
if path is None:
raise ValueError("Path must not be None")
if path == "":
raise ValueError("Path must not be empty")
if path[0] == "/":
return VirtualFileSystem.FILE
elif path[0:2] == "d/":
return VirtualFileSystem.DIR
else:
raise ValueError("Not a valid path " + path)