@cryptotaxi247 / netdata-1 / commits / 198b735f3

python.d.plugin: add prefix to the module name during loading s… (#8474)

auto format python.d.plugin code and add `pythond_` prefix to the modules name

Ilya Mashchenko committed Mar 25, 2020 at 15:29 UTC 198b735f30d1bdbbb8ca87dc1f0b25f9091bfe3b
2 files changed +6 -8
collectors/python.d.plugin/python.d.plugin.in
+4 -7
@@ -42,13 +42,11 @@ except ImportError:
42
43 PY_VERSION = sys.version_info[:2] # (major=3, minor=7, micro=3, releaselevel='final', serial=0)
44
45 -
45 if PY_VERSION > (3, 1):
46 from importlib.machinery import SourceFileLoader
47 else:
48 from imp import load_source as SourceFileLoader
49
51 -
50 ENV_NETDATA_USER_CONFIG_DIR = 'NETDATA_USER_CONFIG_DIR'
51 ENV_NETDATA_STOCK_CONFIG_DIR = 'NETDATA_STOCK_CONFIG_DIR'
52 ENV_NETDATA_PLUGINS_DIR = 'NETDATA_PLUGINS_DIR'
@@ -65,7 +63,6 @@ def add_pythond_packages():
63
64 add_pythond_packages()
65
68 -
66 from bases.collection import safe_print
67 from bases.loggers import PythonDLogger
68 from bases.loaders import load_config
@@ -173,7 +170,7 @@ def multi_path_find(name, *paths):
170
171 def load_module(name):
172 abs_path = os.path.join(DIRS.modules, '{0}{1}'.format(name, MODULE_SUFFIX))
176 - module = SourceFileLoader(name, abs_path)
173 + module = SourceFileLoader('pythond_' + name, abs_path)
174 if isinstance(module, types.ModuleType):
175 return module
176 return module.load_module()
@@ -590,7 +587,7 @@ class Plugin:
587 job.init()
588 except Exception as error:
589 self.log.warning("{0}[{1}] : unhandled exception on init : {2}, skipping the job".format(
593 - job.module_name, job.real_name, repr(error)))
590 + job.module_name, job.real_name, repr(error)))
591 job.status = JOB_STATUS_DROPPED
592 continue
593
@@ -598,7 +595,7 @@ class Plugin:
595 ok = job.check()
596 except Exception as error:
597 self.log.warning("{0}[{1}] : unhandled exception on check : {2}, skipping the job".format(
601 - job.module_name, job.real_name, repr(error)))
598 + job.module_name, job.real_name, repr(error)))
599 job.status = JOB_STATUS_DROPPED
600 continue
601 if not ok:
@@ -611,7 +608,7 @@ class Plugin:
608 job.create()
609 except Exception as error:
610 self.log.warning("{0}[{1}] : unhandled exception on create : {2}, skipping the job".format(
614 - job.module_name, job.real_name, repr(error)))
611 + job.module_name, job.real_name, repr(error)))
612 job.status = JOB_STATUS_DROPPED
613 continue
614
collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py
+2 -1
@@ -60,6 +60,7 @@ class SimpleService(PythonDLimitedLogger, object):
60 Prototype of Service class.
61 Implemented basic functionality to run jobs by `python.d.plugin`
62 """
63 +
64 def __init__(self, configuration, name=''):
65 """
66 :param configuration: <dict>
@@ -70,7 +71,7 @@ class SimpleService(PythonDLimitedLogger, object):
71 self.order = list()
72 self.definitions = dict()
73
73 - self.module_name = self.__module__
74 + self.module_name = self.__module__.lstrip('pythond_')
75 self.job_name = configuration.pop('job_name')
76 self.override_name = configuration.pop('override_name')
77 self.fake_name = None