#!/usr/bin/python
'''
$RCSfile: printpickle.py,v $
$Revision: 1194 $
$Author: markus $
$Date: 2012-07-09 12:44:23 +0200 (Mo, 09. Jul 2012) $
'''
# ****************************************
# +++  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
	