Skip to content

Commit f33e9da

Browse files
authored
Merge pull request #1707 from volatilityfoundation/1471-registry-plugins-spread-across-directories-needs-standardization
1471 registry plugins spread across directories needs standardization
2 parents 8de4603 + 70e101f commit f33e9da

File tree

11 files changed

+3280
-3130
lines changed

11 files changed

+3280
-3130
lines changed

volatility3/framework/deprecation.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,52 @@ def wrapper(*args, **kwargs):
8888
return wrapper
8989

9090
return decorator
91+
92+
93+
def renamed_class(deprecated_class_name: str, message: str, removal_date: str):
94+
"""A decorator for marking classes as being renamed and removed in the future.
95+
Callers to this function should explicitly update to use the other plugins instead.
96+
97+
Args:
98+
deprecated_class_name: The name of the class being deprecated
99+
message: A message added to the standard deprecation warning. Should include the replacement API paths
100+
removal_date: A YYYY-MM-DD formatted date of when the function will be removed from the framework
101+
"""
102+
103+
def decorator(replacement_func):
104+
@functools.wraps(replacement_func)
105+
def wrapper(*args, **kwargs):
106+
warnings.warn(
107+
f"This plugin ({deprecated_class_name}) has been renamed and will be removed in the first release after {removal_date}. {message}",
108+
FutureWarning,
109+
)
110+
return replacement_func(*args, **kwargs)
111+
112+
return wrapper
113+
114+
return decorator
115+
116+
117+
class PluginRenameClass:
118+
"""Class to move all classmethod invocations (for when a plugin has been moved)"""
119+
120+
def __init_subclass__(cls, replacement_class, removal_date, **kwargs):
121+
deprecated_class_name = f"{cls.__module__}.{cls.__qualname__}"
122+
super().__init_subclass__(**kwargs)
123+
for attr, value in replacement_class.__dict__.items():
124+
if isinstance(value, classmethod) and attr != "get_requirements":
125+
setattr(
126+
cls,
127+
attr,
128+
classmethod(
129+
renamed_class(
130+
deprecated_class_name=deprecated_class_name,
131+
removal_date=removal_date,
132+
message=f"Please ensure all method calls to this plugin are replaced with calls to {replacement_class.__module__}.{replacement_class.__qualname__}",
133+
)(value.__func__)
134+
),
135+
)
136+
else:
137+
if not attr.startswith("__"):
138+
setattr(cls, attr, value)
139+
return super(PluginRenameClass).__init_subclass__(**kwargs)

0 commit comments

Comments
 (0)