#!/usr/bin/env python
#
# Makes an archive viewer config file for PV passed in $1 to file in $2
# Example: makeAVcfg.py KLYS:LI22:11:KDT klys.xml
#
import sys
import os
import xmlrpclib
proxy = xmlrpclib.ServerProxy('http://lcls-archsrv/cgi-bin/ArchiveDataServer.cgi')
result = proxy.archiver.archives()
#
f=open(os.getenv('ARCHCONFIGFILES') + '/' + sys.argv[2], 'w')
f.write('<?xml version="1.0" encoding="UTF-16"?>\n')
f.write('<AVConfiguration>\n')
f.write('    <connection_parameter>pbraw://lcls-archapp.slac.stanford.edu/retrieval</connection_parameter>\n')
f.write('    <time_axis name="Main Time Axis">\n')
f.write('        <start>-1d</start>\n')
f.write('        <end>now</end>\n')
f.write('        <location>bottom</location>\n')
f.write('    </time_axis>\n')
f.write('    <range_axis name="Main Range Axis">\n')
f.write('        <min/>\n')
f.write('        <max/>\n')
f.write('        <type>normal</type>\n')
f.write('        <location>left</location>\n')
f.write('    </range_axis>\n')
f.write('    <legend_configuration show_ave_name="true" show_directory_name="false" show_range="true" show_units="true"/>\n')
f.write('    <plot_title/>\n')
f.write('    <pv directory_name="Default" name="' + sys.argv[1] + '">\n')
f.write('        <time_axis_name>Main Time Axis</time_axis_name>\n')
f.write('        <range_axis_name>Main Range Axis</range_axis_name>\n')
f.write('        <color>-65536</color>\n')
f.write('        <draw_type>steps</draw_type>\n')
f.write('        <draw_width>1.0</draw_width>\n')
f.write('        <visibility>true</visibility>\n')
f.write('    </pv>\n')
f.write('</AVConfiguration>\n')
f.close()
