Skip to content

Commit f84a243

Browse files
committed
Convert MetaPluginInterface from Protocol to base class with default implementations
1 parent 5e1e6f0 commit f84a243

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

organizer/basic_folders/organizer/metaplugin/loader.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,14 @@ def call_extend_actions_hooks(self, actions: dict) -> dict:
191191
continue
192192

193193
try:
194-
actions = plugin.extend_actions(actions)
194+
result = plugin.extend_actions(actions)
195+
if result is not None:
196+
actions = result
197+
else:
198+
self.log.warning(
199+
f"Metaplugin {plugin.PLUGIN_NAME}.extend_actions() returned None - "
200+
"plugins must return the modified actions dict"
201+
)
195202
except Exception as e:
196203
self.log.error(
197204
f"Metaplugin {plugin.PLUGIN_NAME} failed in extend_actions: {e}",
@@ -258,9 +265,16 @@ async def call_augment_folder_listing_hooks(
258265
continue
259266

260267
try:
261-
listing_items = await plugin.augment_folder_listing(
268+
result = await plugin.augment_folder_listing(
262269
listing_items, folder_context, session
263270
)
271+
if result is not None:
272+
listing_items = result
273+
else:
274+
self.log.warning(
275+
f"Metaplugin {plugin.PLUGIN_NAME}.augment_folder_listing() returned None - "
276+
"plugins must return the modified listing_items list"
277+
)
264278
except Exception as e:
265279
self.log.error(
266280
f"Metaplugin {plugin.PLUGIN_NAME} failed in augment_folder_listing: {e}",
@@ -291,9 +305,16 @@ async def call_augment_listing_data_hooks(
291305
continue
292306

293307
try:
294-
listing_data = await plugin.augment_listing_data(
308+
result = await plugin.augment_listing_data(
295309
listing_data, folder_context, session
296310
)
311+
if result is not None:
312+
listing_data = result
313+
else:
314+
self.log.warning(
315+
f"Metaplugin {plugin.PLUGIN_NAME}.augment_listing_data() returned None - "
316+
"plugins must return the modified listing_data dict"
317+
)
297318
except Exception as e:
298319
self.log.error(
299320
f"Metaplugin {plugin.PLUGIN_NAME} failed in augment_listing_data: {e}",

organizer/basic_folders/organizer/metaplugin/types.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from dataclasses import dataclass
1616
from logging import Logger, LoggerAdapter
17-
from typing import Any, Optional, Protocol, TYPE_CHECKING
17+
from typing import Any, Optional, TYPE_CHECKING
1818
from sqlalchemy import orm
1919

2020
from organizer.database.models import DbFolder
@@ -67,12 +67,16 @@ class OrganizerContext:
6767
"""Helper for constructing UI pages"""
6868

6969

70-
class MetaPluginInterface(Protocol):
70+
class MetaPluginInterface:
7171
"""
72-
Protocol defining the metaplugin interface.
72+
Base class for metaplugins.
7373
74-
Metaplugins should implement a `Plugin` class with these attributes and methods.
75-
All methods are optional - metaplugins only need to implement the hooks they use.
74+
Metaplugins should inherit from this class and override the hooks they need.
75+
All methods have sensible defaults, so you only need to implement what you use.
76+
77+
Required attributes:
78+
PLUGIN_NAME: str - Unique metaplugin identifier (e.g., "my_metaplugin")
79+
PLUGIN_VERSION: str - Metaplugin version string (e.g., "1.0.0")
7680
"""
7781

7882
PLUGIN_NAME: str
@@ -96,7 +100,7 @@ async def on_init(self, context: OrganizerContext):
96100
self.log = context.log
97101
self.log.info(f"{self.PLUGIN_NAME} initialized")
98102
"""
99-
...
103+
pass
100104

101105
async def on_shutdown(self) -> None:
102106
"""
@@ -108,7 +112,7 @@ async def on_shutdown(self) -> None:
108112
async def on_shutdown(self):
109113
self.log.info(f"{self.PLUGIN_NAME} shutting down")
110114
"""
111-
...
115+
pass
112116

113117
def extend_actions(self, actions: dict[str, clap.ActionDef]) -> dict[str, clap.ActionDef]:
114118
"""
@@ -138,7 +142,7 @@ def extend_actions(self, actions):
138142
139143
return actions
140144
"""
141-
...
145+
return actions
142146

143147
async def handle_custom_command(
144148
self, cmd: str, args: dict[str, Any], session: org.UserSessionData, organizer: "OrganizerInbound"
@@ -173,7 +177,7 @@ async def handle_custom_command(self, cmd, args, session, organizer):
173177
174178
return True
175179
"""
176-
...
180+
return False
177181

178182
async def augment_folder_listing(
179183
self, listing_items: list[clap.PageItemFolderListingItem], folder_context: "FolderContext", session: org.UserSessionData
@@ -206,7 +210,7 @@ async def augment_folder_listing(self, listing_items, folder_context, session):
206210
207211
return listing_items
208212
"""
209-
...
213+
return listing_items
210214

211215
async def augment_listing_data(
212216
self, listing_data: dict[str, str], folder_context: "FolderContext", session: org.UserSessionData
@@ -231,7 +235,7 @@ async def augment_listing_data(self, listing_data, folder_context, session):
231235
listing_data["folder_id"] = str(folder_context.folder.id)
232236
return listing_data
233237
"""
234-
...
238+
return listing_data
235239

236240
async def check_action_authorization(
237241
self,
@@ -270,4 +274,4 @@ async def check_action_authorization(self, action, folder, media_file, session):
270274
# Use default checks for everything else
271275
return None
272276
"""
273-
...
277+
return None

0 commit comments

Comments
 (0)