Package gavo :: Package base :: Module osinter
[frames] | no frames]

Module osinter

source code

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

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

Functions
 
getGroupId() source code
 
makeSharedDir(path, writable=True)
creates a directory with group ownership [general]group.
source code
 
getHTTPBase(*args)
returns the server's base URL for the http protocol.
source code
 
getHTTPSBase(*args)
return the server's base URL for the https protocol.
source code
 
switchProtocol(url)
tries to make an https URL from an http one and vice versa.
source code
 
getCurrentServerURL()
returns the server URL pertinent for the current request.
source code
 
makeSitePath(path)
returns a rooted local part for a server-internal URL.
source code
 
makeAbsoluteURL(path, canonical=False)
returns a fully qualified URL for a rooted local part.
source code
 
getBinaryName(baseName)
returns the name of a binary it thinks is appropriate for the platform.
source code
 
getPathForDistFile(name)
returns a path for a "dist resource", i.e., a file distributed with DaCHS.
source code
 
openDistFile(name)
returns an open file for a "dist resource", i.e., a file distributed with DaCHS.
source code
 
getVersion()
returns (as a string) the DaCHS version running.
source code
 
formatMail(mailText)
returns a mail with headers and content properly formatted as a bytestring and MIME.
source code
 
tryRemoteReload(rdId)
tries to reload the rdId on a running service
source code
Variables
  __package__ = 'gavo.base'
Function Details

makeSharedDir(path, writable=True)

source code 

creates a directory with group ownership [general]group.

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

getHTTPBase(*args)

source code 

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.

Decorators:
  • @utils.memoized

getHTTPSBase(*args)

source code 

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.

Decorators:
  • @utils.memoized

switchProtocol(url)

source code 

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.

getCurrentServerURL()

source code 

returns the server URL pertinent for the current request.

This looks upstack for a renderer object having a HANDLING_HTTPS attribute. If it finds one, it will return HTTPBase() or HTTPSBase() as appropriate. If not, it will return [web]serverurl

makeSitePath(path)

source code 

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.

Decorators:
  • @utils.document

makeAbsoluteURL(path, canonical=False)

source code 

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.

Decorators:
  • @utils.document

getBinaryName(baseName)

source code 

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.

getPathForDistFile(name)

source code 

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.

openDistFile(name)

source code 

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

see getPathForDistFile

getVersion()

source code 

returns (as a string) the DaCHS version running.

The information is obtained from setuptools.

formatMail(mailText)

source code 

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

mailText must be a unicode instance or pure ASCII

tryRemoteReload(rdId)

source code 

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.