# -*- coding: utf-8 -*-
from os import listdir
from os.path import abspath, splitext
from Plugins.Bp.geminimain.gTools import gPluginPath

NetcastPlugins = []

def addNetcastPlugin(NetcastPlugin):
	NetcastPlugins.append(NetcastPlugin)


def importExternalModules():
	file= gPluginPath + "gemininetcastwebif/web-data/plugins.js"
	with open(file, "w") as f:
    		f.write("//autogenerated file do not edit!\n")
		
	dir = abspath(gPluginPath + "gemininetcastwebif/plugins/")
	for file in listdir(dir):
		module_name, ext = splitext(file) # Handles no-extension files, etc.

		if ext == '.py' and module_name != "__init__":
			try:
				exec "import " + module_name
				print '[plugin.importExternalModules] Imported external module: %s' % (module_name)
		
			except ImportError, e:
				print '[plugin.importExternalModules] Could NOT import external module: %s' % (module_name)
				print '[plugin.importExternalModules] Exception Caught\n%s' %e
