Source code for keygrabber.Lookup
from . import Version
Version.append ('$Revision: 94706 $')
del Version
import Music # provided by kroot/music/python
import os
import subprocess
try:
reldir = os.environ['RELDIR']
except KeyError:
reldir = None
if reldir == '' or reldir == None:
raise RuntimeError ('$RELDIR is not set, please use kpython')
[docs]def datahost (service):
''' Return the hostname on which the keygrabber data is stored for
*service*. This information could then be used when instantiating
a :class:`sql.Handler` instance.
'''
lookup = str (service) + '_keywordlog_host'
return readsvcfile (lookup)
readsvcfile = Music.readsvcfile
def firstrecord (row):
''' Return the first element of the supplied sequence. This trivial
function is used in :func:`services` below to quickly recover
the service names from a sequence of single-element results.
'''
return row[0]
[docs]def services (handler, dict=True):
''' Determine which services have data available on the
datahost of interest-- specified implicitly by passing
in a working sql.Handler instance as the first argument.
'''
query = "SELECT relname FROM pg_class WHERE relkind='r' AND relname NOT LIKE 'pg_%' AND relname NOT LIKE 'sql_%' ORDER BY relname"
results = handler.select (query)
if dict == False:
results = map (firstrecord, results)
else:
dictionary = {}
for row in results:
dictionary[row[0]] = True
results = dictionary
return results
# vim: set expandtab tabstop=8 softtabstop=4 shiftwidth=4 autoindent: