def addQ3CIndex(tableDef): """if td as unique main positions (by UCD), add an index to the table definition. """ try: raField = tableDef.getColumnByUCDs("pos.eq.ra;meta.main", "POS_EQ_RA_MAIN") decField = tableDef.getColumnByUCDs("pos.eq.dec;meta.main", "POS_EQ_RA_MAIN") if (raField.type not in ["real", "double precision"] or decField.type not in ["real", "double precision"]): raise ValueError("Don't index non-floats") except ValueError: # No unique positions return base.resolveId(None, "//scs#q3cindex").applyToFinished(tableDef)
def makeAttributeAnnotation(container, attName, attValue): """returns a typed annotation for attValue within container. When attValue is a literal, this is largely trivial. If it's a reference, this figures out what it points to and creates an annotation of the appropriate type (e.g., ColumnAnnotation, ParamAnnotation, etc). container in current DaCHS should be a TableDef or something similar; this function expects at least a getByName function and an rd attribute. This is usually used as a callback from within sil.getAnnotation and expects Atom and Reference instances as used there. """ if isinstance(attValue, sil.Atom): return common.AtomicAnnotation(attName, attValue) elif isinstance(attValue, sil.Reference): # try name-resolving first (resolveId only does id resolving on # unadorned strings) try: res = container.getByName(attValue) except base.NotFoundError: res = base.resolveId(container.rd, attValue, instance=container) if not hasattr(res, "getAnnotation"): raise base.StructureError("Element %s cannot be referenced" " within a data model." % repr(res)) return res.getAnnotation(attName, container) else: assert False
def cacheprev(querier, args): from gavo import api from gavo.web.productrender import PreviewCacheManager from twisted.internet import reactor basePath = base.getConfig("inputsDir") td = base.resolveId(None, args.tableId) table = api.TableForDef(td, connection=querier.connection) select = [td.getColumnByName("accref"), td.getColumnByName("mime")] rows = table.iterQuery(select, "") def runNext(token): try: row = rows.next() res = PreviewCacheManager.getPreviewFor( row["mime"], [str(os.path.join(basePath, row["accref"])), str(args.width)]) if getattr(res, "result", None): # don't add a callback on a # fired deferred or you'll exhaust the stack reactor.callLater(0.1, runNext, "continue") else: res.addCallback(runNext) return res except StopIteration: pass except: import traceback traceback.print_exc() reactor.stop() return "" reactor.callLater(0, runNext, "startup") reactor.run()
def makeDataById(ddId, parseOptions=common.parseNonValidating, connection=None, inRD=None): """returns the data set built from the DD with ddId (which must be fully qualified). """ dd = base.resolveId(inRD, ddId) return makeData(dd, parseOptions=parseOptions, connection=connection)
def gatherDependents(dd): for dependentId in dd.dependents: try: dependentDD = base.resolveId(dd.rd, dependentId) edges.add((dd, dependentDD)) if dependentDD not in seen: seen.add(dependentDD) gatherDependents(dependentDD) except (base.StructureError, base.NotFoundError), msg: base.ui.notifyWarning("Ignoring dependent %s of %s (%s)" % (dependentId, dd.id, unicode(msg)))
def getMixinDocs(docStructure, mixinIds): content = RSTFragment() for name in sorted(mixinIds): mixin = base.resolveId(None, name) content.addHead1("The %s Mixin" % name) if mixin.doc is None: content.addNormalizedPara("NOT DOCUMENTED") else: content.addNormalizedPara(mixin.doc) if mixin.pars: content.addNormalizedPara( "This mixin has the following parameters:\n") _documentParameters(content, mixin.pars) return content.content
def getStreamsDoc(idList): content = RSTFragment() for id in idList: stream = base.resolveId(None, id) content.addHead2(id) if stream.doc is None: raise base.ReportableError( "Stream %s has no doc -- don't include in" " reference documentation." % id) content.addNormalizedPara(stream.doc) content.makeSpace() if stream.DEFAULTS and stream.DEFAULTS.defaults: content.addNormalizedPara( "*Defaults* for macros used in this stream:") content.makeSpace() for key, value in sorted(stream.DEFAULTS.defaults.iteritems()): content.addULItem("%s: '%s'" % (key, value)) content.makeSpace() return content.content
def buildDocs(docStructure): return _getProcdefDocs([(id, base.resolveId(None, id)) for id in sorted(idList)])
def execute(querier, args): from gavo.user import logui logui.LoggingUI(base.ui) execEl = base.resolveId(None, args.execId) execEl.callable().join()
def indexStatements(querier, args): import re td = base.resolveId(None, args.tableId) for ind in td.indices: print "\n".join(re.sub(r"\s+", " ", s) for s in ind.iterCode())