示例#1
0
def main():
	args = parseCommandLine()
	jobId = args.jobId
	with base.getTableConn() as conn:
		svcId = list(
			conn.query("SELECT jobclass FROM uws.userjobs WHERE jobId=%(jobId)s",
				{"jobId": jobId}))[0][0]
	service = base.resolveCrossId(svcId)

	try:
		job = service.getUWS().getJob(jobId)
		with job.getWritable() as wjob:
			wjob.change(phase=uws.EXECUTING, startTime=datetime.datetime.utcnow())

		service = base.resolveCrossId(job.jobClass)
		inputTable = rsc.TableForDef(service.core.inputTable)
		inputTable.job = job

		for parName, value in job.parameters.iteritems():
			inputTable.setParam(parName, value)

		data = service._runWithInputTable(
			service.core, inputTable, None).original

		# Our cores either return a table, a pair of mime and data,
		# or None (in which case they added the results themselves)
		if isinstance(data, tuple):
			mime, payload = data
			with job.openResult(mime, "result") as destF:
				destF.write(payload)

		elif isinstance(data, rsc.Data):
			destFmt = inputTable.getParam("responseformat", 
				"application/x-votable+xml")
			with job.openResult(destFmt, "result") as destF:
				formats.formatData(destFmt, data, destF, False)

		elif data is None:
			pass

		else:
			raise NotImplementedError("Cannot handle a service %s result yet."%
				repr(data))
		
		with job.getWritable() as wjob:
			wjob.change(phase=uws.COMPLETED)

	except SystemExit:
		pass
	except uws.JobNotFound:
		base.ui.notifyInfo("Giving up non-existing UWS job %s."%jobId)
	except Exception, ex:
		base.ui.notifyError("UWS runner %s major failure"%jobId)
		# try to push job into the error state -- this may well fail given
		# that we're quite hosed, but it's worth the try
		service.getUWS().changeToPhase(jobId, uws.ERROR, ex)
		raise
示例#2
0
def localquery():
    """run the argument as an ADQL query.
	"""
    from gavo import rscdesc  #noflake: cache registration
    from gavo import formats

    q = sys.argv[1]
    with base.AdhocQuerier() as querier:
        table = query(querier, q, timeout=1000)
        formats.formatData("votable", table, sys.stdout)
def formatSDMData(sdmData, format, queryMeta=svcs.emptyQueryMeta):
    """returns a pair of mime-type and payload for a rendering of the SDM
	Data instance sdmData in format.

	(you'll usually use this via //datalink#sdm_format)
	"""

    destMime = str(format or base.votableType)
    if queryMeta["tdEnc"] and destMime == base.votableType:
        destMime = "application/x-votable+xml;serialization=tabledata"
    formatId = GETDATA_FORMATS.get(destMime, None)

    if formatId is None:
        # special or unknown format
        if destMime == "application/fits":
            return destMime, makeSDMFITS(sdmData)
        elif destMime == "application/x-votable+xml;content=spec2":
            # At the last moment, hack data so it becomes
            # SDM2.  We'll have to finally decide when we actually want
            # to apply the hacks.  And do the whole thing completely
            # differently.
            hackSDM1ToSDM2(sdmData)
            formatId = "votabletd"
        else:
            raise base.ValidationError("Cannot format table to %s" % destMime,
                                       "FORMAT")

    # target version is usually set by makeSDMDataForSSARow; but if
    # people made sdmData in some other way, fall back to default.
    sdmVersion = getattr(sdmData, "DACHS_SDM_VERSION",
                         base.getConfig("ivoa", "sdmVersion"))
    if sdmVersion == "1":
        sdmData.addMeta(
            "_votableRootAttributes",
            'xmlns:spec="http://www.ivoa.net/xml/SpectrumModel/v1.01"')

    resF = StringIO()
    formats.formatData(formatId, sdmData, resF, acquireSamples=False)
    return destMime, resF.getvalue()
示例#4
0
def writeResultTo(format, res, outF):
	# special-case votable formats to handle overflow conditions and such
	if format.startswith("votable"):
		# the following duplicates a mapping from votablewrite; that's
		# bad, and I should figure out a way to teach formats.format
		# whatever is needed to let it do what we're doing here.  Meanwhile:
		enc = {
			"votable": "binary",
			"votableb2": "binary2",
			"votabletd": "td",
		}.get(format, "td")

		oe = None
		if getattr(res, "setLimit", None) is not None:
			oe = votable.OverflowElement(res.setLimit,
				votable.V.INFO(name="QUERY_STATUS", value="OVERFLOW"))
		ctx = votablewrite.VOTableContext(
			tablecoding=enc,
			acquireSamples=False, 
			overflowElement=oe)
		votablewrite.writeAsVOTable(res, outF, ctx)
	else:
		formats.formatData(format, res, outF, acquireSamples=False)
示例#5
0
 def produceData(destFile):
     formats.formatData("json",
                        data.original,
                        request,
                        acquireSamples=False)
示例#6
0
 def writeStuff(outputFile):
     formats.formatData(destFormat,
                        data.original,
                        outputFile,
                        acquireSamples=False)