Basic OS interface/utility functions that depend on our configuration.
(everything that doesn’t need getConfig is somewhere in gavo.utils)
returns a mail with headers and content properly formatted as a bytestring and MIME.
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.
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
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.
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.
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.
returns (as a string) the DaCHS version running.
The information is obtained from setuptools.
- gavo.base.osinter.makeAbsoluteURL(path, canonical=False)¶
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.
creates a directory with group ownership [general]group.
There’s much that can to wrong; we try to raise useful error messages.
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)¶
returns an open file for a “dist resource”, i.e., a file distributed with DaCHS.
- gavo.base.osinter.sendMail(mailText, rateLimitKey=None)¶
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.
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.
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.