|
5 | 5 | """
|
6 | 6 | Base class for all agent modules
|
7 | 7 | """
|
8 |
| -from __future__ import absolute_import |
9 |
| -from __future__ import division |
10 |
| -from __future__ import print_function |
11 |
| - |
12 |
| -__RCSID__ = "$Id$" |
13 |
| - |
14 | 8 | import os
|
15 | 9 | import threading
|
16 | 10 | import time
|
17 | 11 | import signal
|
| 12 | +import importlib |
| 13 | +import inspect |
18 | 14 |
|
19 | 15 | import DIRAC
|
20 | 16 | from DIRAC import S_OK, S_ERROR, gConfig, gLogger, rootPath
|
|
29 | 25 | from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
|
30 | 26 |
|
31 | 27 |
|
32 |
| -class AgentModule(object): |
| 28 | +class AgentModule: |
33 | 29 | """Base class for all agent modules
|
34 | 30 |
|
35 | 31 | This class is used by the AgentReactor Class to steer the execution of
|
@@ -71,9 +67,8 @@ class AgentModule(object):
|
71 | 67 | def __init__(self, agentName, loadName, baseAgentName=False, properties={}):
|
72 | 68 | """
|
73 | 69 | Common __init__ method for all Agents.
|
74 |
| - All Agent modules must define: |
75 |
| - __doc__ |
76 |
| - __RCSID__ |
| 70 | + All Agent modules must define: __doc__ |
| 71 | +
|
77 | 72 | They are used to populate __codeProperties
|
78 | 73 |
|
79 | 74 | The following Options are used from the Configuration:
|
@@ -154,18 +149,23 @@ def __init__(self, agentName, loadName, baseAgentName=False, properties={}):
|
154 | 149 | self.__initialized = False
|
155 | 150 |
|
156 | 151 | def __getCodeInfo(self):
|
157 |
| - versionVar = "__RCSID__" |
158 |
| - docVar = "__doc__" |
| 152 | + |
159 | 153 | try:
|
160 |
| - self.__agentModule = __import__(self.__class__.__module__, globals(), locals(), versionVar) |
| 154 | + self.__codeProperties["version"] = importlib.metadata.version( |
| 155 | + inspect.getmodule(self).__package__.split(".")[0] |
| 156 | + ) |
| 157 | + except Exception: |
| 158 | + self.log.exception(f"Failed to find version for {self!r}") |
| 159 | + self.__codeProperties["version"] = "unset" |
| 160 | + try: |
| 161 | + self.__agentModule = __import__(self.__class__.__module__, globals(), locals(), "__doc__") |
161 | 162 | except Exception as excp:
|
162 | 163 | self.log.exception("Cannot load agent module", lException=excp)
|
163 |
| - for prop in ((versionVar, "version"), (docVar, "description")): |
164 |
| - try: |
165 |
| - self.__codeProperties[prop[1]] = getattr(self.__agentModule, prop[0]) |
166 |
| - except Exception: |
167 |
| - self.log.error("Missing property", prop[0]) |
168 |
| - self.__codeProperties[prop[1]] = "unset" |
| 164 | + try: |
| 165 | + self.__codeProperties["description"] = getattr(self.__agentModule, "__doc__") |
| 166 | + except Exception: |
| 167 | + self.log.error("Missing property __doc__") |
| 168 | + self.__codeProperties["description"] = "unset" |
169 | 169 | self.__codeProperties["DIRACVersion"] = DIRAC.version
|
170 | 170 | self.__codeProperties["platform"] = DIRAC.getPlatform()
|
171 | 171 |
|
@@ -198,7 +198,6 @@ def am_initialize(self, *initArgs):
|
198 | 198 | self.log.notice("Loaded agent module %s" % self.__moduleProperties["fullName"])
|
199 | 199 | self.log.notice(" Site: %s" % DIRAC.siteName())
|
200 | 200 | self.log.notice(" Setup: %s" % gConfig.getValue("/DIRAC/Setup"))
|
201 |
| - self.log.notice(" Base Module version: %s " % __RCSID__) |
202 | 201 | self.log.notice(" Agent version: %s" % self.__codeProperties["version"])
|
203 | 202 | self.log.notice(" DIRAC version: %s" % DIRAC.version)
|
204 | 203 | self.log.notice(" DIRAC platform: %s" % DIRAC.getPlatform())
|
|
0 commit comments