import logging
from livereload import Server, shell

'''This script runs a webserver that monitors files for changes and sends
update notification to the browser. To run, cd to the directory the script
is located and:

  python serve.py

'''

logging.basicConfig(level=logging.DEBUG)

params = {'xsl' : 'xsl/onedcx/onedcx.xsl',
          'xml' : 'examples/test2.xml',
          'pid'  : 'cmd_line_PID_value',
          'docid': 'metacat_doc_id',
          'qformat': 'view_type',
          'contextURL': 'http://localhost:5500',
          }
cmd = """xsltproc --xincludestyle --stringparam pid "{pid}" \
  --stringparam qformat "{qformat}" \
  --stringparam docid "{docid}" \
  --stringparam contextURL "{contextURL}" \
  {xsl} {xml}""".format(**params)

server = Server()
print "Running with command: {0}".format(cmd)
server.watch(params['xsl'], shell(cmd, output='test2.html', cwd='.'))
server.watch(params['xml'], shell(cmd, output='test2.html', cwd='.'))
server.serve(root=".", open_url=False)

