gavo.base.osinter module

Basic OS interface/utility functions that depend on our configuration.

(everything that doesn’t need getConfig is somewhere in gavo.utils)

gavo.base.osinter.formatMail(mailText)[source]

returns a mail with headers and content properly formatted as a bytestring and MIME.

gavo.base.osinter.getBinaryName(baseName)[source]

returns the name of a binary it thinks is appropriate for the platform.

To do this, it asks config for the platform name, sees if there’s a binary <bin>-<platname> if platform is nonempty. If it exists, it returns that name, in all other cases, it returns baseName unchanged.

gavo.base.osinter.getCurrentServerURL()[source]

returns the server URL pertinent for the current request.

This looks upstack for a renderer object having an isSecure attribute. If it finds one, it will assume it’s a twisted request, call isSecure and return HTTPBase() or HTTPSBase() as appropriate. If not, it will return [web]serverurl

gavo.base.osinter.getGroupId()[source]
gavo.base.osinter.getHTTPBase()[source]

returns the server’s base URL for the http protocol.

This is just serverURL from the configuration, unless serverURL is https; in that case, we replace https with http. serverPort is ignored here under the assumption that there’s a reverse proxy. If that bites you, we could introduce an alternativeServerURL config item.

gavo.base.osinter.getHTTPSBase()[source]

return the server’s base URL for the https protocol.

If serverURL already is https, that’s what’s returned. If not, the URL is parsed, any port specification is removed (i.e., we only support https on port 443), the protocol is changed to https, and the result is returned.

gavo.base.osinter.getPathForDistFile(name)[source]

returns a path for a “dist resource”, i.e., a file distributed with DaCHS.

name is the file relative to resources.

This is essentially pkg_resources.resource_filename with a dash of built-in configuration.

gavo.base.osinter.getVersion()[source]

returns (as a string) the DaCHS version running.

The information is obtained from setuptools.

gavo.base.osinter.makeAbsoluteURL(path, canonical=False)[source]

returns a fully qualified URL for a rooted local part.

This will reflect the http/https access mode unless you pass canonical=True, in which case [web]serverURL will be used unconditionally.

gavo.base.osinter.makeSharedDir(path, writable=True)[source]

creates a directory with group ownership [general]group.

There’s much that can to wrong; we try to raise useful error messages.

gavo.base.osinter.makeSitePath(path)[source]

returns a rooted local part for a server-internal URL.

uri itself needs to be server-absolute; a leading slash is recommended for clarity but not mandatory.

gavo.base.osinter.openDistFile(name, mode='r', encoding=None)[source]

returns an open file for a “dist resource”, i.e., a file distributed with DaCHS.

see getPathForDistFile

gavo.base.osinter.sendMail(mailText, rateLimitKey=None)[source]

sends mailText (which has to have all the headers) via sendmail.

(which is configured in [general]sendmail).

This will return True when sendmail has accepted the mail, False otherwise.

gavo.base.osinter.switchProtocol(url)[source]

tries to make an https URL from an http one and vice versa.

This function will raise a ValueError if url doesn’t start with either HTTPBase or HTTPSBase. Otherwise, it will replace one by the other.

gavo.base.osinter.tryRemoteReload(rdId)[source]

tries to reload the rdId on a running service

This only works if there’s [web]adminpasswd and[web]serverURL set, and both match what the actual server uses.