#!/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
'''
$RCSfile: printpickle.py,v $
$Revision: 834 $
$Author: markus $
$Date: 2008-04-17 19:59:49 +0200 (Do, 17. Apr 2008) $
'''
# ****************************************
# +++  BioCASE 
# +++  Pickle Printer
#
# Reads a pickled object and calls its __repr__ method
#
# ****************************************


# ***** 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' ) ) )

import cPickle as pickle


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

if __name__ ==  "__main__":

	print '''
 +++  BioCASE 
 +++  Pickle Printer
'''	
	# ASK FOR CMF
	filename = ''
	while not os.path.isfile(filename):
		filename = raw_input("Please enter the path to the pickled file: ")
	fi = file(filename, 'r')
	obj = pickle.load(fi)
	fi.close()
	dump = ''
	dump = raw_input("Dump print in file ? ")
	if len(dump) > 0 and dump.lower() <> 'no':
		dumpFilename = filename+'.dump.txt'
		fo = file(dumpFilename, 'w')
		fo.write(str(obj))
		fo.close
		print "Wrote printing dump to %s"%dumpFilename
	else:
		print "-"*40
		print obj
	