How to develop
When you want to create a new resource plugin, you need to add a new class in the module resources_plugin.
The resource plugin class needs to inherit the abstract class ResourcePlugin and implement its abstract method read_file function.
The parameter of the __init__ function of ResourcePlugin is the prefix of STR type. You can override this function when necessary.
The read_file function parameter of ResourcePlugin is the file suffix of STR type, and its return value is the file content, if it exists and is readable.
Example
Method __init__: Initiation method with param:prefix
def __init__(self, prefix: str, *args, **kwargs):
super().__init__(prefix, *args, **kwargs)
Method read_file: Get content from the given URI, The function parameter is the suffix of the file path.
The file prefix has been initialized in init of the resource plugin.
The prefix plus suffix is the absolute path of the file in this resource.
def read_file(self, suf: str):
"""Get the content of the file.
The address of the file is the prefix of the resource plugin plus the parameter suf.
"""
path = Path(self.prefix).joinpath(suf)
if not path.exists():
raise PyResPluginException(f"{str(path)} is not found")
if not os.access(str(path), os.R_OK):
raise PyResPluginException(
f"You don't have permission to access {self.prefix + suf}"
)
with open(path) as f:
content = f.read()
return content