Change to using sys.path and other windows compatibility changes
This commit is contained in:
parent
14442f3f43
commit
a8ee0a4477
1 changed files with 7 additions and 6 deletions
|
@ -31,7 +31,7 @@ class RtmBot(object):
|
||||||
self.token = config.get('SLACK_TOKEN')
|
self.token = config.get('SLACK_TOKEN')
|
||||||
|
|
||||||
# set working directory for loading plugins or other files
|
# set working directory for loading plugins or other files
|
||||||
working_directory = os.path.dirname(sys.argv[0])
|
working_directory = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||||
self.directory = self.config.get('BASE_PATH', working_directory)
|
self.directory = self.config.get('BASE_PATH', working_directory)
|
||||||
if not self.directory.startswith('/'):
|
if not self.directory.startswith('/'):
|
||||||
path = '{}/{}'.format(os.getcwd(), self.directory)
|
path = '{}/{}'.format(os.getcwd(), self.directory)
|
||||||
|
@ -109,13 +109,14 @@ class RtmBot(object):
|
||||||
plugin.do_jobs()
|
plugin.do_jobs()
|
||||||
|
|
||||||
def load_plugins(self):
|
def load_plugins(self):
|
||||||
for plugin in glob.glob(self.directory + '/plugins/*'):
|
plugin_dir = os.path.join(self.directory, 'plugins')
|
||||||
|
for plugin in glob.glob(os.path.join(plugin_dir, '*')):
|
||||||
sys.path.insert(0, plugin)
|
sys.path.insert(0, plugin)
|
||||||
sys.path.insert(0, self.directory + '/plugins/')
|
sys.path.insert(0, plugin_dir)
|
||||||
for plugin in glob.glob(self.directory + '/plugins/*.py') + \
|
for plugin in glob.glob(os.path.join(plugin_dir, '*.py')) + \
|
||||||
glob.glob(self.directory + '/plugins/*/*.py'):
|
glob.glob(os.path.join(plugin_dir, '*', '*.py')):
|
||||||
logging.info(plugin)
|
logging.info(plugin)
|
||||||
name = plugin.split('/')[-1][:-3]
|
name = plugin.split(os.sep)[-1][:-3]
|
||||||
if name in self.config:
|
if name in self.config:
|
||||||
logging.info("config found for: " + name)
|
logging.info("config found for: " + name)
|
||||||
plugin_config = self.config.get(name, {})
|
plugin_config = self.config.get(name, {})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue