#! /usr/bin/env python

from __future__ import print_function
import sys, os, re

## Get output filename
OUTFILE = "analyses.dat"
if len(sys.argv) >= 2:
    OUTFILE = sys.argv[1]
if not OUTFILE.endswith(".dat"):
    OUTFILE += ".dat"
print("Using output file name '%s'" % OUTFILE)

# ## Add the rivet Python module build dir(s) to the Python module path, then import
# pybuild = os.path.abspath(os.path.join(os.getcwd(), "..", "..", "pyext", "build"))
# pydirs = [os.path.join(pybuild, d) for d in os.listdir(pybuild)
#           if re.match(r"lib\..*-.*-%d\.%d" % (sys.version_info[0], sys.version_info[1]), d)]
# sys.path = pydirs + sys.path
import rivet

## Add info file locations
from glob import glob
dirpatt = os.path.join(os.getcwd(), "..", "..", "analyses", "plugin*")
for d in glob(dirpatt):
    rivet.addAnalysisDataPath(os.path.abspath(d))

outstr = '\n'.join(list(rivet.analysisNames()))

## Write out
if OUTFILE == "-":
    sys.stdout.write(outstr)
else:
    f = open(OUTFILE, "w")
    f.write(outstr)
    f.close()
