gavo.base.config module¶
Definition of DC config options and their management including I/O.
Importing this reads the configuration, which influences almost everything in DaCHS, including the way certain items are constructed. Hence, this must be imported as early as humanly possible, in particular before anything trying to talk to the database runs, because this is where the database access profiles (well: the DSNs) are read.
- class gavo.base.config.AuthorityConfigItem(name: str, default: Optional[str] = None, description: str = 'Undocumented')[source]¶
Bases:
StringConfigItem
an IVOA Identifers-compatible authority.
- class gavo.base.config.Configuration(*items: Section)[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.
- class gavo.base.config.DBProfile(**kwargs: Any)[source]¶
Bases:
object
A parsed form of the postgres connection string.
- database = ''¶
- getArgs() Dict[str, str] [source]¶
returns a dictionary suitable as keyword arguments to psycopg2’s connect.
- host = ''¶
- name = None¶
- password = ''¶
- port = None¶
- profileName = 'anonymous'¶
- property roleName: str¶
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: str, default: Optional[str] = None, description: str = '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: str, default: Optional[str] = None, description: str = 'Undocumented')[source]¶
Bases:
StringConfigItem
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.ProfileParseError(msg: str = '', hint: Optional[str] = None)[source]¶
Bases:
Error
- class gavo.base.config.ProfileParser(sourcePath: List[str] = ['.'])[source]¶
Bases:
object
A parser for database access 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: Optional[str], sourceName: Optional[str], stream: Optional[Union[str, IO]] = None) DBProfile [source]¶
parses a profile input and returns a new DBProfile instance.
You can pass in a stream (a file open for reading or a string containing profile material, but that’s really mainly test instrumentation. Usually, you will instead pass in sourceName, which is then searched in the sourcePath.
stream, if an open file, will be closed by the function.
The parsing itself works by state function returning the next state function; each state function is a Callable accepting a token and returning a new state function.
- profileKeys = {'database', 'host', 'password', 'port', 'sslmode', 'user'}¶
- class gavo.base.config.RelativeURL(name: str, default: Optional[str] = None, description: str = 'Undocumented')[source]¶
Bases:
StringConfigItem
A configuration item that is interpreted relative to the server’s root URL.
- typedesc = "URL fragment relative to the server's root"¶
- property value: str¶
- class gavo.base.config.RootRelativeConfigItem(name: str, default: Optional[str] = None, description: str = 'Undocumented')[source]¶
Bases:
PathRelativeConfigItem
- typedesc = 'path relative to rootDir'¶
- class gavo.base.config.WebRelativeConfigItem(name: str, default: Optional[str] = None, description: str = 'Undocumented')[source]¶
Bases:
PathRelativeConfigItem
- typedesc = 'path relative to webDir'¶
- gavo.base.config.getRSTReference(underlineChar='-') str [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() None [source]¶
reads the configuration from /etc/gavo.rc and ~/.gavorc.
This manipulates the global _config object.
Actually, you can override these locations in GAVOSETTINGS and GAVOCUSTOM. But you’ll confuse everyone if you do that in production, so only do that if it really helps somewhere else (as perhaps in containers when you want to everything writable in one place).
This also manipulates the environment such that libraries with configuration files fetch them from our configDir.