#!/usr/bin/python
# In DR3, there are COMB files for many V500 files.  They are in
# general preferable when deriving things.  Therefore q3#import_spectra
# and friends ignore the V500 files for which there are COMB.
# This script generates the "kill file" used for that.

from gavo import api
from gavo import utils

if __name__=="__main__":
	rd = api.getRD("califa/q3")
	inputsDir = api.getConfig("inputsDir")
	bySetup = dict((s, {}) for s in "V500 V1200 COMB".split())

	for path in rd.getById("allsources"):
		path = utils.getRelativePath(path, inputsDir)
		setup = path.split(".")[-4]
		object = ".".join(path.split("/")[-1].split(".")[:-4])
		bySetup[setup][object] = path

	with open(rd.getAbsPath("res/v500withcomb.txt"), "w") as dest:
		dest.write("# Generated by bin/collectobsoletev500.py\n")
		for v500WithCombObject in set(bySetup["V500"].keys()
				) & set(bySetup["COMB"].keys()):
			dest.write(bySetup["V500"][v500WithCombObject]+"\n")

