So I have a directory tree as follows:
pluginlist.py
plugins/
__init__.py
plugin1.py
plugin2.py
...
And want to concatenate a similarly-named dictionary from each of plugin1, plugin2, etc.
The way I’m doing this is as follows (from pluginlist.py):
import os
pluginFolderName = "plugins"
pluginFlag = "##&plugin&##"
commands = {}
os.chdir(os.path.abspath(pluginFolderName))
for file in os.listdir(os.getcwd()):
if os.path.isfile(file) and os.path.splitext(file)[1] == ".py":
fileo = open(file, 'r')
firstline = fileo.readline()
if firstline == "##&plugin&##\n":
plugin_mod = __import__("plugins.%s" % os.path.splitext(file)[0])
import_command = "plugin_commands = plugin_mod.%s" % os.path.splitext(file)[0]
exec import_command
commands = dict(commands.items() + plugin_commands.commands.items())
print commands
(The print commands there is for testing purposes)
Running that on Windows gives the proper commands dictionary, but running it on Linux (Ubuntu Server) gives an empty dictionary.
Figured out my problem! The
test wasn’t working because Linux wanted an absolute path to the plugin file. So replacing all instances of file with
Seems to fix everything.