#!/usr/bin/python

import sys
import os
#from optparse import *
#import ConfigParser
from glue.ligolw import utils
from glue.ligolw import table
from glue.ligolw import lsctables



#######################################################################
usage = """
%prog [options] 

Script for recreating a command to create a certain XML file

Example:
  extractCommand [xmlfile]
"""

# get the only argument
argument = sys.argv[1]

if 'help' in argument:
  print usage
  sys.exit(0)

# get the filename
filename=argument

# read the xml structure
doc = utils.load_filename(filename)

# get the tables
procTable=table.get_table(doc, lsctables.ProcessTable.tableName)
procParamsTable=table.get_table(doc, lsctables.ProcessParamsTable.tableName)

# extract the executable name
executable=procTable[0].domain+'_'+procTable[0].program

print executable+' \\'
for param in procParamsTable:
  if procParamsTable.index(param)<len(procParamsTable)-1:
    print '  '+param.param+' '+ param.value +' \\'
  else:
    print '  '+param.param+' '+ param.value
