gavo.base.config module

Definition of DC config options and their management including I/O.

class gavo.base.config.AuthorityConfigItem(name, default=None, description='Undocumented')[source]

Bases: StringConfigItem

an IVOA Identifers-compatible authority.

class gavo.base.config.Configuration(*items)[source]

Bases: Configuration

A container for settings.

It is a fancyconfig.Configuration with the addition of making the attributes shared at the class level to ward against multiple imports (which may happen if config is imported in a weird way).

In addition, this class handles the access to database profiles.

getDBProfile(profileName)[source]
class gavo.base.config.DBProfile(**kwargs)[source]

Bases: object

A parsed form of the postgres connection string.

database = ''
getArgs()[source]

returns a dictionary suitable as keyword arguments to psycopg2’s connect.

host = ''
name = None
password = ''
port = None
profileName = 'anonymous'
property roleName

returns the database role used by this profile.

This normally is user, but in the special case of the empty user, we return the logged users’ name.

sslmode = 'allow'
user = ''
class gavo.base.config.EatTrailingSlashesItem(name, default=None, description='Undocumented')[source]

Bases: StringConfigItem

is a config item that must not end with a slash. A trailing slash on input is removed.

typedesc = 'path fragment'
class gavo.base.config.EnsureTrailingSlashesItem(name, default=None, description='Undocumented')[source]

Bases: StringConfigItem

is a config item that must end with a slash. If no slash is present on input, it is added.

typedesc = 'path fragment'
exception gavo.base.config.Error(msg: str = '', hint: Optional[str] = None)[source]

Bases: Error

exception gavo.base.config.ProfileParseError(msg: str = '', hint: Optional[str] = None)[source]

Bases: Error

class gavo.base.config.ProfileParser(sourcePath=['.'])[source]

Bases: object

is a parser for DB profiles.

The profiles are specified in simple text files that have a shell-like syntax. Each line either contains an assignment (x=y) or is of the form command arg*. Recognized commands include:

  • include f – read instructions from file f, searched along profilePath

>>> p = ProfileParser()
>>> p.parse(None, "x", "host=foo.bar\n").host
'foo.bar'
>>> p.parse(None, "x", "") is not None
True
>>> p.parse(None, "x", "host=\n").host
''
>>> p.parse(None, "x", "=bla\n")
Traceback (most recent call last):
gavo.base.config.ProfileParseError: "x", line 1: invalid identifier '='
>>> p.parse(None, "x", "host=bla")
Traceback (most recent call last):
gavo.base.config.ProfileParseError: "x", line 1: unexpected end of file (missing line feed?)
parse(profileName, sourceName, stream=None)[source]
profileKeys = {'database', 'host', 'password', 'port', 'sslmode', 'user'}
class gavo.base.config.RelativeURL(name, default=None, description='Undocumented')[source]

Bases: StringConfigItem

is a configuration item that is interpreted relative to the server’s root URL.

typedesc = "URL fragment relative to the server's root"
property value
class gavo.base.config.RootRelativeConfigItem(name, default=None, description='Undocumented')[source]

Bases: PathRelativeConfigItem

baseKey = 'rootDir'
typedesc = 'path relative to rootDir'
class gavo.base.config.WebRelativeConfigItem(name, default=None, description='Undocumented')[source]

Bases: PathRelativeConfigItem

baseKey = 'webDir'
typedesc = 'path relative to webDir'
gavo.base.config.getDBProfile(profileName)
gavo.base.config.getRSTReference(underlineChar='-')[source]

returns a ReStructuredText reference of configuration items.

This will have one RST section per configuration section; to let you adapt that to an embedding document, you can pass the character to use for headline underlines in underlineChar.

gavo.base.config.loadConfig()[source]
gavo.base.config.main()[source]