#!/usr/bin/python
###################################################################
#
#             Reset the Properties 
#
###################################################################
#
# Command Line Arguments:
#   1. The name of the TeX file whose .dfs file needs to be reset.
#      (without the .tex extension)
#   2. (Optional) Name of the properties file.
#       The default is "properties" (+.tex)
#
###################################################################
import sys, pickle, os
from getpath import getpath
#
import synt, pattern
#
tex_path = os.getenv('TEXPATH') or ''
#
#
if len(sys.argv)< 2:
	print 'Usage: resetprops <file> [<properties-file>]'
	sys.exit(1)

filename = tex_path + sys.argv[1] + '.dfs'
try:
	f = open(filename,"r")
	syntdb = pickle.load(f)
	synt.mathdb = syntdb
	f.close()
except:
	print filename + ' not found.'
	sys.exit(1)

############################################################
#
#  Get properties File
#
############################################################

if len(sys.argv) > 2:
	propfilename = tex_path + sys.argv[2] + '.tex'
else:
	propfilename = tex_path + "properties.tex"

proppathname = getpath(propfilename)

if not proppathname:
	print propfilename, " not found."
	raise SystemExit

synt.mathdb = synt.readprops(propfilename, syntdb)

f = open(filename,"w")
pickle.dump(syntdb,f)
f.close()
