#!/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python

# ****************************************
# +++  BioCASE 
# +++  CMF Transfer v1.0
#
# Transfer mappings from one CMF to another.
# Transfers only equal XPath mappings and
# reports mappings that could not be tranfered.
#
# ****************************************


# ***** include the biocase.lib directory in the python sys path for importing *****
import os, sys
execfile( os.path.abspath(os.path.join(os.path.dirname( __file__ ), os.path.pardir, 'lib', 'biocase', 'adjustpath.py' ) ) )

# other imports
from biocase.wrapper.cmf_base import CMFClass
import string


############################################################################################################
#
# MAIN
#
#===========================================================================================================

if __name__ ==  "__main__":

	print '''
 +++  BioCASE 
 +++  CMF Configuration Examiner v1.0

 A tool to list all mappings, filters, etc of a CMF as a plain list.
'''	
	# ASK FOR CMF
	CMFFilePath = ''
	while not os.path.isfile(CMFFilePath):
		CMFFilePath = raw_input("Please enter the path to the CMFile to be examined: ")
	CMFObj = CMFClass()
	CMFObj.loadCMFdata(CMFFilePath, pickle=False)

	print "EXAMINING CMF '%s'" %(CMFFilePath)
	print
	print "-"*40
	print "Your CMF contains the following basic data:"
	basics = {}
	basics['Root table'] = CMFObj.tableTreeObj.rootTableAlias
	basics['Static tables'] = string.join(CMFObj.tableTreeObj.staticTables, ",  ")
	for label,val in basics.items():
		print "%s:\t%s" %(label, val)

	print
	print "-"*40
	filters = CMFObj.removeFilters()
	print "Your CMF contains the following filters (%i) :"%(len(filters))
	for label,val in filters.items():
		print "%s:\t%s" %(label, str(val) )
	
	print
	print "-"*40
	mappings = CMFObj.removeMappings()
	print "Your CMF contains the following mappings (%i) :" %(len(mappings))
	for concept,maps in mappings.items():
		print concept
		for map in maps:
			print "  %s" %( str(map) )
	