summaryrefslogtreecommitdiffstats
path: root/src/debputy/plugin/api/plugin_parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/debputy/plugin/api/plugin_parser.py')
-rw-r--r--src/debputy/plugin/api/plugin_parser.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/debputy/plugin/api/plugin_parser.py b/src/debputy/plugin/api/plugin_parser.py
new file mode 100644
index 0000000..ad2489f
--- /dev/null
+++ b/src/debputy/plugin/api/plugin_parser.py
@@ -0,0 +1,66 @@
+from typing import NotRequired, List, Any, TypedDict
+
+from debputy.manifest_parser.base_types import (
+ DebputyParsedContent,
+ OctalMode,
+ TypeMapping,
+)
+from debputy.manifest_parser.declarative_parser import ParserGenerator
+from debputy.plugin.api.impl_types import KnownPackagingFileInfo
+
+
+class PPFReferenceDocumentation(TypedDict):
+ description: NotRequired[str]
+ format_documentation_uris: NotRequired[List[str]]
+
+
+class PackagerProvidedFileJsonDescription(DebputyParsedContent):
+ stem: str
+ installed_path: str
+ default_mode: NotRequired[OctalMode]
+ default_priority: NotRequired[int]
+ allow_name_segment: NotRequired[bool]
+ allow_architecture_segment: NotRequired[bool]
+ reference_documentation: NotRequired[PPFReferenceDocumentation]
+
+
+class ManifestVariableJsonDescription(DebputyParsedContent):
+ name: str
+ value: str
+ reference_documentation: NotRequired[str]
+
+
+class PluginJsonMetadata(DebputyParsedContent):
+ api_compat_version: int
+ module: NotRequired[str]
+ plugin_initializer: NotRequired[str]
+ packager_provided_files: NotRequired[List[Any]]
+ manifest_variables: NotRequired[List[Any]]
+ known_packaging_files: NotRequired[List[Any]]
+
+
+def _initialize_plugin_metadata_parser_generator() -> ParserGenerator:
+ pc = ParserGenerator()
+ pc.register_mapped_type(
+ TypeMapping(
+ OctalMode,
+ str,
+ lambda v, ap, _: OctalMode.parse_filesystem_mode(v, ap),
+ )
+ )
+ return pc
+
+
+PLUGIN_METADATA_PARSER_GENERATOR = _initialize_plugin_metadata_parser_generator()
+PLUGIN_METADATA_PARSER = PLUGIN_METADATA_PARSER_GENERATOR.parser_from_typed_dict(
+ PluginJsonMetadata
+)
+PLUGIN_PPF_PARSER = PLUGIN_METADATA_PARSER_GENERATOR.parser_from_typed_dict(
+ PackagerProvidedFileJsonDescription
+)
+PLUGIN_MANIFEST_VARS_PARSER = PLUGIN_METADATA_PARSER_GENERATOR.parser_from_typed_dict(
+ ManifestVariableJsonDescription
+)
+PLUGIN_KNOWN_PACKAGING_FILES_PARSER = (
+ PLUGIN_METADATA_PARSER_GENERATOR.parser_from_typed_dict(KnownPackagingFileInfo)
+)