from mocha.web.WebServer import WebServer

from mocha.oms import Oms
from mocha.oms.memory import MemoryOms

import sys
from getopt import getopt

if __name__ == "__main__":

	port = 8081
	libraries = [ ]

	(opts, remaining) = getopt(sys.argv[1:], "p", [ "port=", "library=" ])
	for opt in opts:
		if opt[0] == "--port":
			port = int(opt[1])
	
	print("Mocha User Interface Service v2.1")

	from mocha.web.manager import ServerManager
	svrmgr = ServerManager()

	if len(remaining) == 0:
		print("error: no server configurations specified")

	for library in remaining:
		svrmgr.add_server_config(library)

	svrmgr.start()

	# from mocha.lib.LibraryManager import MochaLibraryManager
	# manager = MochaLibraryManager()

	# from mocha.lib.parser.YAMLLibraryParser import YAMLLibraryParser
	# yamlmgr = YAMLLibraryParser(manager)
	
	# print("loading entity definitions...")
	# for library in remaining:
	# 	print("\t" + library)
	# 	yamlmgr.load_entity_definitions_from_file(library)

	# print("loading instances...")
	# for library in remaining:
	# 	print("\t" + library)
	# 	yamlmgr.load_instances_from_file(library)

	# oms = MemoryOms()

