def main():
	"""handles the user interaction for gavo publish.
	"""
	from gavo import rscdesc #noflake: register cache
	opts, args = parseCommandLine()
	common.getServicesRD().touchTimestamp()
	if opts.all:
		args = findPublishedRDs()
	updateServiceList(getRDs(args), metaToo=opts.meta, 
		keepTimestamp=opts.keepTimestamp)
	base.tryRemoteReload("__system__/services")
def updateRegistryTimestamp():
	"""edits the dateupdated field for the registry service in servicelist.
	"""
	with base.AdhocQuerier(base.getAdminConn) as q:
		regSrv = common.getRegistryService()
		q.query("UPDATE services SET dateupdated=%(now)s"
			" WHERE sourcerd=%(rdId)s AND resId=%(sId)s", {
			"rdId": regSrv.rd.sourceId,
			"sId": regSrv.id,
			"now": datetime.datetime.utcnow(),
		})
	common.getServicesRD().touchTimestamp()
Example #3
0
def getMatchingRestups(pars):
    """returns a list of res tuples matching the OAI query arguments pars.

	See getMatchingRows for details on pars.
	"""
    td = common.getServicesRD().getById("resources")
    return getMatchingRows(pars, td, _getSetCondition)
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 cleanServiceTablesFor(rd, connection):
	"""removes/invalidates all entries originating from rd from the service
	tables.
	"""
# this is a bit of a hack: We're running services#tables' newSource
#	skript without then importing anything new.
	tables = rsc.Data.create(
		common.getServicesRD().getById("tables"),
		connection=connection)
	tables.runScripts("newSource", sourceToken=rd)
def getSetsForResource(restup):
	"""returns the list of set names the resource described by restup belongs to.
	"""
	tableDef = common.getServicesRD().getById("sets")
	table = rsc.TableForDef(tableDef)
	destTableDef = base.makeStruct(rscdef.TableDef,
		columns=[tableDef.getColumnByName("setName")])
	return set(str(r["setName"])
		for r in table.iterQuery(destTableDef, 
			"sourceRD=%(sourceRD)s AND resId=%(resId)s", restup))
def queryServicesList(whereClause="", pars={}, tableName="resources_join"):
	"""returns a list of services based on selection criteria in
	whereClause.

	The table queried is the resources_join view, and you'll get back all
	fields defined there.
	"""
	td = common.getServicesRD().getById(tableName)
	otd = svcs.OutputTableDef.fromTableDef(td, None)
	table = rsc.TableForDef(td)
	return [r for r in table.iterQuery(otd, whereClause, pars)]
def getSets():
	"""returns a sequence of dicts giving setName and and a list of
	services belonging to that set.
	"""
	tableDef = common.getServicesRD().getById("sets")
	table = rsc.TableForDef(tableDef)
	setMembers = {}
	for rec in table:
		setMembers.setdefault(rec["setName"], []).append(
			(rec["sourceRD"], rec["resId"]))
	return [{"setName": key, "services": value} 
		for key, value in setMembers.iteritems()]
def querySubjectsList(setName=None):
	"""returns a list of local services chunked by subjects.

	This is mainly for the root page (see web.root).  Query the
	cache using the __system__/services key to clear the cache on services
	"""
	setName = setName or 'local'
	svcsForSubjs = {}
	td = common.getServicesRD().getById("subjects_join")
	otd = svcs.OutputTableDef.fromTableDef(td, None)
	with base.getTableConn() as conn:
		for row in rsc.TableForDef(td, connection=conn).iterQuery(otd, 
				"setName=%(setName)s AND subject IS NOT NULL", {"setName": setName}):
			svcsForSubjs.setdefault(row["subject"], []).append(row)
	for s in svcsForSubjs.values():
		s.sort(key=lambda a: a["title"])
	res = [{"subject": subject, "chunk": s}
		for subject, s in svcsForSubjs.iteritems()]
	res.sort(lambda a,b: cmp(a["subject"], b["subject"]))
	return res