Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from file import PluginDirectory
from interpreter import Interpreter
from plugin_loader import PluginLoader
class Application:
def run(self):
plugin_loader = PluginLoader()
plugin_directory = PluginDirectory()
commands = plugin_loader.load(plugin_directory)
interpreter = Interpreter(commands)
while True:
print interpreter.interpret(raw_input())
import inspect
import imp
import os
import tempfile
from node import TreeNode
class File(TreeNode):
def __init__(self, path=None):
super(File, self).__init__()
self.classes = {}
def __init_classes(self, path):
# XXX: add a test for this case
if path is None or os.path.isdir(path):
with open(path, 'r') as f:
file_content =
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.py')
module = imp.load_source('',
except Exception, e:
print e
module_classes = inspect.getmembers(module, inspect.isclass)
for name, klass in module_classes:
self.classes[name.lower()] = klass
os.unlink( + 'c')
def __init_structure(self, path):
if not isinstance(path, str) or not path:
current_node = self
parts = path.split('/')
for part in reversed(parts): = part
current_node.parent = File()
current_node = current_node.parent
class PluginDirectory(File):
def __init__(self):
super(PluginDirectory, self).__init__(self.plugin_path)
def plugin_path(self):
return os.path.join(self.current_directory, 'commands')
def current_directory(self):
return os.path.dirname(os.path.realpath(__file__))
from application import Application
if __name__ == '__main__':
application = Application()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.