def dds(args): rd = api.getReferencedElement(args.rdId, forceType=api.RD) for dd in rd.dds: outLine = dd.id if dd.auto: outLine += "*" print outLine
def process(opts, args): """imports the data set described by args governed by opts. The first item of args is an RD id, any remaining ones are interpreted as DD ids within the selected RD. If no DD ids are given, all DDs within the RD are processed except those for which auto has been set to False. opts is either a ParseOption instance or the object returned by main's parseOption function below. """ # process manages its dependencies itself retvalWatcher = RetvalWatcher(api.ui) opts.buildDependencies = False rdId, selectedIds = args[0], args[1:] rd = api.getReferencedElement(rdId, forceType=api.RD) dds = common.getPertainingDDs(rd, selectedIds) connection = api.getDBConnection("admin") tap.unpublishFromTAP(rd, connection) tap.publishToTAP(rd, connection) for dd in dds: if opts.metaOnly: api.ui.notifyInfo("Updating meta for %s" % dd.id) res = api.Data.create(dd, parseOptions=opts, connection=connection).updateMeta( opts.metaPlusIndex) # Hack: if there's an obscore mixin active, redo the obscore # Is there a less special-cased way to do this? for make in dd.makes: for script in make.scripts: if script.id == 'addTableToObscoreSources': scripting.PythonScriptRunner(script).run( res.tables[make.table.id]) else: api.ui.notifyInfo("Making data %s" % dd.id) res = api.makeData(dd, parseOptions=opts, connection=connection) if hasattr(res, "nAffected"): api.ui.notifyInfo("Rows affected: %s" % res.nAffected) # We're committing here so that we don't lose all importing # work just because some dependent messes up. connection.commit() api.makeDependentsFor(dds, opts, connection) connection.commit() rd.touchTimestamp() return retvalWatcher.retval
def main(): from gavo import api args = parseCmdLine() item = api.getReferencedElement(args.itemId) if isinstance(item, api.TableDef): changes = iterLimitsForTable(item) rd = item.rd elif isinstance(item, api.RD): changes = iterLimitsForRD(item) rd = item else: raise base.ReportableError( "%s references neither an RD nor a table definition" % args.itemId) newText = getChangedRD(rd.sourceId, changes) destFName = os.path.join(api.getConfig("inputsDir"), rd.sourceId + ".rd") with utils.safeReplaced(destFName) as f: f.write(newText)
def suggestucds(querier, args): import SOAPpy import urllib from gavo import api wsdlURL = "http://dc.zah.uni-heidelberg.de/ucds/ui/ui/soap/go/go?wsdl" proxy = SOAPpy.WSDL.Proxy(urllib.urlopen(wsdlURL).read()) td = api.getReferencedElement(args.tableId, forceType=api.TableDef) for col in td: if (not col.ucd or col.ucd == "XXX") and col.description: try: res = [(row["score"], row["ucd"]) for row in proxy.useService(col.description)] res.sort() res.reverse() print col.name for score, ucd in res: print " ", ucd except SOAPpy.Types.faultType: # remote failure, guess it's "no matches" (TODO: distinguish) pass
def _do_dropRD(opts, rdId, selectedIds=()): """drops the data and services defined in the RD selected by rdId. """ try: rd = api.getReferencedElement(rdId, forceType=api.RD) except api.NotFoundError: if opts.force: rd = None else: raise with base.AdhocQuerier(base.getWritableAdminConn) as querier: if rd is not None: if opts.dropAll: dds = rd.dds else: dds = common.getPertainingDDs(rd, selectedIds) parseOptions = api.getParseOptions(systemImport=opts.systemImport) for dd in dds: api.Data.drop(dd, connection=querier.connection, parseOptions=parseOptions) if not selectedIds or opts.dropAll: from gavo.registry import servicelist servicelist.cleanServiceTablesFor(rd, querier.connection) tap.unpublishFromTAP(rd, querier.connection) try: with querier.connection.savepoint(): querier.query("drop schema %s" % rd.schema) except Exception, msg: api.ui.notifyWarning( "Cannot drop RD %s's schema %s because:" " %s." % (rd.sourceId, rd.schema, utils.safe_str(msg))) else:
def loadRD(rdId): """returns the RD identified by rdId. If that fails, diagnostics are printed and None is returned. """ try: rd = api.getReferencedElement(rdId, doQueries=False) # This is so we can validate userconfig.rd if hasattr(rd, "getRealRD"): rd = rd.getRealRD() except api.RDNotFound: outputError(rdId, "Could not be located") except api.LiteralParseError: outputError(rdId, "Bad literal in RD, message follows", True) except api.StructureError: outputError(rdId, "Malformed RD input, message follows", True) except api.Error: outputError(rdId, "Syntax or internal error, message follows", True) else: return rd # Fallthrough: RD could not be loaded return None
def main(): args = parseCmdline() td = api.getReferencedElement(args.tableId, api.TableDef) printTableInfo(td)