-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.py
More file actions
71 lines (49 loc) · 1.6 KB
/
Copy pathmodule.py
File metadata and controls
71 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import json
import logging
# load modules
class module:
def __init__(self, module_path):
self.logger = logging.getLogger(__name__)
self.logger.info("Initializing")
if(os.access(module_path, os.F_OK | os.R_OK)):
self._module_path = module_path
self._module_list = []
self._module_name = []
else:
self.logger.critical("Bad path to modules")
raise ValueError('Bad path to modules')
# dynamic module loading
def load_module(self):
self.logger.info("Start")
# read module.json
active_modules = json.load(open('modules/modules.json'))['modules']
self.logger.debug(active_modules)
for filename in os.listdir(self._module_path):
mod_name = filename[:-3]
if(filename[-3:] == ".py" and filename != '__init__.py' and (mod_name in active_modules)):
self.logger.debug(filename)
self._module_name.append('modules.' + mod_name)
self.logger.debug(self._module_name)
# read about map function
self._module_list = map(lambda x: __import__(x, fromlist='*'), self._module_name)
self.logger.info("End")
return 1
## create dict for command-module mapping
def get_module_dict(self):
module_dict = {}
# populate dict with keywords
key_list = ['ALL', 'PRIVMSG', 'NOTICE', 'PART', 'JOIN', 'PING']
# initialize module_dict
for key in key_list:
module_dict[key] = []
for module in self._module_list:
obj = module.Class()
cmd_list = obj.get_irc_cmds()
for cmd in cmd_list:
if cmd in module_dict:
module_dict[cmd].append(obj)
self.logger.debug(module_dict)
return module_dict
# reload module
# todo