2023-03-24 21:25:22 -04:00
|
|
|
import os
|
2023-03-29 16:51:55 -04:00
|
|
|
from importlib.machinery import SourceFileLoader
|
2023-03-24 21:25:22 -04:00
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
'PythonModuleMixin',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class PythonModuleMixin:
|
|
|
|
|
2024-01-22 13:01:53 -06:00
|
|
|
def get_jobs(self, name):
|
|
|
|
"""
|
|
|
|
Returns a list of Jobs associated with this specific script or report module
|
|
|
|
:param name: The class name of the script or report
|
|
|
|
:return: List of Jobs associated with this
|
|
|
|
"""
|
|
|
|
return self.jobs.filter(
|
|
|
|
name=name
|
|
|
|
)
|
|
|
|
|
2023-03-24 21:25:22 -04:00
|
|
|
@property
|
|
|
|
def path(self):
|
|
|
|
return os.path.splitext(self.file_path)[0]
|
|
|
|
|
2023-03-29 16:51:55 -04:00
|
|
|
@property
|
|
|
|
def python_name(self):
|
|
|
|
path, filename = os.path.split(self.full_path)
|
|
|
|
name = os.path.splitext(filename)[0]
|
|
|
|
if name == '__init__':
|
|
|
|
# File is a package
|
|
|
|
return os.path.basename(path)
|
|
|
|
else:
|
|
|
|
return name
|
2023-03-24 21:25:22 -04:00
|
|
|
|
|
|
|
def get_module(self):
|
2023-03-29 16:51:55 -04:00
|
|
|
loader = SourceFileLoader(self.python_name, self.full_path)
|
|
|
|
module = loader.load_module()
|
2023-03-24 21:25:22 -04:00
|
|
|
return module
|