Exemple #1
0
    def _doRender(self, ctx):
        jobId = tap.WORKER_SYSTEM.getNewIdFromRequest(inevow.IRequest(ctx),
                                                      self.service)

        try:
            with tap.WORKER_SYSTEM.changeableJob(jobId) as job:
                job.change(executionDuration=base.getConfig(
                    "async", "defaultExecTimeSync"))
            taprunner.runTAPJob(jobId)

            job = tap.WORKER_SYSTEM.getJob(jobId)
            if job.phase == uws.COMPLETED:
                # This is TAP, so there's exactly one result
                res = job.getResults()[0]
                name, type = res["resultName"], res["resultType"]
                # hold on to the result fd so its inode is not lost when we delete
                # the job.
                f = open(os.path.join(job.getWD(), name))
                return (f, type)
            elif job.phase == uws.ERROR:
                exc = job.error
                raise base.Error(exc["msg"], hint=exc["hint"])
            elif job.phase == uws.ABORTED:
                raise uws.UWSError(
                    "Job was manually aborted.  For synchronous"
                    " jobs, this probably means the operators killed it.",
                    jobId)
            else:
                raise uws.UWSError("Internal error.  Invalid UWS phase.",
                                   jobId)
        finally:
            tap.WORKER_SYSTEM.destroy(jobId)
Exemple #2
0
def structToETree(aStruct):
    """returns an ElementTree for the copyable content of aStruct.

	Note that due to manipulations at parse time and non-copyable content,
	this will, in general, not reproduce the original XML trees.
	"""
    nodeStack = [ElementTree.Element(aStruct.name_)]
    for evType, elName, value in aStruct.iterEvents():
        try:
            if evType == "start":
                nodeStack.append(ElementTree.SubElement(nodeStack[-1], elName))
            elif evType == "end":
                nodeStack.pop()
            elif evType == "value":
                if value is None or value is base.NotGiven:
                    continue
                if elName == "content_":
                    nodeStack[-1].text = value
                else:
                    if not isinstance(value, basestring):
                        # TODO: figure out if something is a reference by inspecting
                        # the attribute definition; meanwhile, just assume it is:
                        value = value.id
                    nodeStack[-1].set(elName, value)
            else:
                raise base.Error("Invalid struct event: %s" % evType)
        except:
            base.ui.notifyError("Badness occurred in element %s, event %s,"
                                " value %s\n" % (elName, evType, value))
            raise
    return nodeStack[-1]
 def getQName(self):
     if self.temporary:
         return self.id
     else:
         if self.rd is None:
             raise base.Error("TableDefs without resource descriptor"
                              " have no qualified names")
         return "%s.%s" % (self.rd.schema, self.id)
Exemple #4
0
def bailOut():
    """A fake cli operation just raising exceptions.

	This is mainly for testing and development.
	"""
    if len(sys.argv) < 2:
        raise ValueError("Too short")
    arg = sys.argv[0]
    if arg == "--help":
        raise base.Error("Hands off this.  For Developers only")
Exemple #5
0
def getMatchingRows(pars, rscTableDef, getSetFilter):
    """returns rows in rscTableDef matching the OAI parameters pars.

	The last element of the list could be an OAI.resumptionToken element.
	pars is a dictionary mapping any of the following keys to values:

		- from
		- until -- these give a range for which changed records are being returned
		- set -- maps to a sequence of set names to be matched.
		- resumptionToken -- some magic value (see OAI.resumptionToken)
		- maxRecords -- an integer literal that specifies the maximum number
		  of records returned, defaulting to [ivoa]oaipmhPageSize
	
	maxRecords is not part of OAI-PMH; it is used internally to
	turn paging on when we think it's a good idea, and for testing.

	rscTableDef has to be a table with a column recTimestamp giving the
	resource record's updated time.

	getSetFilter(pars, fillers) is a function receiving the PMH parameters
	dictionary and a dictionary of query fillers and returning, as appropriate,
	a condition that implements any conditions on sets within pars
	"""
    maxRecords = int(
        pars.get("maxRecords", base.getConfig("ivoa", "oaipmhPagesize")))
    offset = pars.get("resumptionToken", 0)
    frag, fillers = _parseOAIPars(pars)
    frag = " AND ".join(f for f in [getSetFilter(pars, fillers), frag] if f)

    try:
        with base.getTableConn() as conn:
            srvTable = rsc.TableForDef(rscTableDef, connection=conn)
            res = list(
                srvTable.iterQuery(
                    rscTableDef,
                    frag,
                    fillers,
                    limits=("LIMIT %(maxRecords)s OFFSET %(offset)s",
                            locals())))

        if len(res) == maxRecords:
            # there's probably more data, request a resumption token
            res.append(OAI.resumptionToken[makeResumptionToken(
                pars, offset + len(res))])
            res[-1].addChild = lambda: 0

    except base.DBError:
        raise base.ui.logOldExc(
            common.BadArgument("Bad syntax in some parameter value"))
    except KeyError, msg:
        raise base.ui.logOldExc(
            base.Error("Internal error, missing key: %s" % msg))
def updateServiceList(rds, metaToo=False, connection=None, onlyWarn=True,
		keepTimestamp=False):
	"""updates the services defined in rds in the services table in the database.
	"""
	recordsWritten = 0
	parseOptions = rsc.getParseOptions(validateRows=True, batchSize=20)
	if connection is None:
		connection = base.getDBConnection("admin")
	dd = common.getServicesRD().getById("tables")
	dd.grammar = _rdRscRecGrammar
	dd.grammar.keepTimestamp = keepTimestamp
	depDD = common.getServicesRD().getById("deptable")
	msg = None
	for rd in rds:
		if rd.sourceId.startswith("/"):
			raise base.Error("Resource descriptor ID must not be absolute, but"
				" '%s' seems to be."%rd.sourceId)

		deletedUpdater = getDeletedIdentifiersUpdater(connection, rd)

		try:
			data = rsc.makeData(dd, forceSource=rd, parseOptions=parseOptions,
				connection=connection)
			recordsWritten += data.nAffected
			rsc.makeData(depDD, forceSource=rd, connection=connection)

			if metaToo:
				from gavo.protocols import tap
				tap.unpublishFromTAP(rd, connection)
				for dependentDD in rd:
					rsc.Data.create(dependentDD, connection=connection).updateMeta()
				tap.publishToTAP(rd, connection)

			deletedUpdater()

		except base.MetaValidationError, ex:
			msg = ("Aborting publication of rd '%s' since meta structure of"
				" %s (id='%s') is invalid:\n * %s")%(
				rd.sourceId, repr(ex.carrier), ex.carrier.id, "\n * ".join(ex.failures))
		except base.NoMetaKey, ex:
			msg = ("Aborting publication of '%s' at service '%s': Resource"
				" record generation failed: %s"%(
				rd.sourceId, ex.carrier.id, str(ex)))
def parseAngle(literal, format, sepChar=None):
    """converts the various forms angles might be encountered to degrees.

	format is one of hms, dms, fracHour.  For sexagesimal/time angles, 
	you can pass a sepChar (default: split at blanks) that lets you
	specify what separates hours/degrees, minutes, and seconds.

	>>> str(parseAngle("23 59 59.95", "hms"))
	'359.999791667'
	>>> "%10.5f"%parseAngle("-20:31:05.12", "dms", sepChar=":")
	' -20.51809'
	>>> "%010.6f"%parseAngle("21.0209556", "fracHour")
	'315.314334'
	"""
    if format == "dms":
        return utils.dmsToDeg(literal, sepChar=sepChar)
    elif format == "hms":
        return utils.hmsToDeg(literal, sepChar=sepChar)
    elif format == "fracHour":
        return utils.fracHoursToDeg(literal)
    else:
        raise base.Error("Invalid format: %s" % format)