Exemplo n.º 1
0
def makeSitePath(path):
    """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.
	"""
    return str(config.get("web", "nevowRoot") + path.lstrip("/"))
Exemplo n.º 2
0
def tryRemoteReload(rdId):
    """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.
	"""
    pw = config.get("web", "adminpasswd")
    # don't bother if admin passwd has not been set or when running unit tests.
    if pw == "" or pw == "this_is_the_unittest_suite":
        return

    try:
        f = utils.urlopenRemote(makeAbsoluteURL("/seffe/%s" % rdId),
                                urllib.urlencode({
                                    "__nevow_form__": "adminOps",
                                    "submit": "Reload RD"
                                }),
                                creds=("gavoadmin", pw))
        f.read()
    except IOError, ex:
        utils.sendUIEvent(
            "Warning", "Could not reload %s RD (%s).  This means"
            " that the server may still use stale metadata.  You may want"
            " to reload %s manually (or restart the server)." %
            (rdId, ex, rdId))
Exemplo n.º 3
0
def sendMail(mailText):
    """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.
	"""
    mailText = formatMail(mailText)

    pipe = subprocess.Popen(config.get("sendmail"),
                            shell=True,
                            stdin=subprocess.PIPE)
    pipe.stdin.write(mailText)
    pipe.stdin.close()

    if pipe.wait():
        utils.sendUIEvent(
            "Error", "Wanted to send mail starting with"
            " '%s', but sendmail returned an error message"
            " (check the [general]sendmail setting)." %
            utils.makeEllipsis(mailText, 300))
        return False

    return True
Exemplo n.º 4
0
def sendMailToAdmin(subject, message):
    """tries to send a mail to the configured administrator.

	This relies on a functional mail infrastructure on the local host.
	"""
    if not config.get("maintainerAddress"):
        utils.sendUIEvent(
            "Error", "Wanted to send mail with subject '%s', but no"
            " maintainerAddress is given" % subject)
        return

    osinter.sendMail("\n".join([
        "To: " + config.get("maintainerAddress"), "Subject: " + subject,
        "From: DaCHS server <%s>" % config.get("maintainerAddress"),
        "Content-Type: text/plain", "",
        utils.safe_str(message)
    ]))
Exemplo n.º 5
0
 def _makeADSLink(self, matOb):
     # local import of config to avoid circular import.
     # (move special metas to separate module?)
     from gavo.base import config
     adsMirror = config.get("web", "adsMirror")
     return '<a href="%s">%s</a>' % (
         adsMirror + "/abs/%s" % urllib.quote(matOb.group(0)),
         matOb.group(0))
Exemplo n.º 6
0
    def macro_getConfig(self, section, name=None):
        """the current value of configuration item {section}{name}.

		You can also only give one argument to access settings from the
		general section.
		"""
        if name is None:
            section, name = "general", section
        return str(config.get(section, name))
Exemplo n.º 7
0
 def _makeADSLink(self, matOb):
     # local import of config to avoid circular import.
     # (move special metas to separate module?)
     from gavo.base import config
     adsMirror = config.get("web", "adsMirror")
     return '<a href="%s">%s</a>' % (
         adsMirror + "/cgi-bin/nph-data_query?bibcode=%s&"
         "link_type=ABSTRACT" % urllib.quote(matOb.group(0)),
         matOb.group(0))
Exemplo n.º 8
0
def getGroupId():
    gavoGroup = config.get("group")
    try:
        return grp.getgrnam(gavoGroup)[2]
    except KeyError, ex:
        raise utils.ReportableError(
            "Group %s does not exist" % str(ex),
            hint="You should have created this (unix) group when you"
            " created the server user (usually, 'gavo').  Just do it"
            " now and re-run this program.")
Exemplo n.º 9
0
def getBinaryName(baseName):
    """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.
	"""
    platform = config.get("platform")
    if platform:
        platName = baseName + "-" + platform
        if os.path.exists(platName):
            return platName
    return baseName
Exemplo n.º 10
0
def getPathForDistFile(name):
    """returns a path for a "dist resource", i.e., a file distributed
	with DaCHS.

	This is like pkg_resources, except it also checks in 
	$GAVO_DIR/override/<name> and returns that file if present.  Thus, you
	can usually override DaCHS built-in files (but there's not too many
	places in which that's used so far).

	TODO: this overrides stuff stinks a bit because for many classes 
	of files (RDs, templates, ...) there already are override locations.
	It think we should compute the override path based on name prefixes.
	"""
    userPath = os.path.join(config.get("rootDir"), "overrides/" + name)
    if os.path.exists(userPath):
        return userPath
    else:
        return pkg_resources.resource_filename('gavo', "resources/" + name)
Exemplo n.º 11
0
def makeAbsoluteURL(path):
    """returns a fully qualified URL for a rooted local part.
	"""
    #return str(config.get("web", "serverURL")+makeSitePath(path))
    return str(config.get("web", "serverURL") + makeSitePath(path))
Exemplo n.º 12
0
        try:
            os.chown(path, -1, gavoGroup)
            if writable:
                os.chmod(path, stats.st_mode | 0060)
        except Exception, msg:
            raise utils.ReportableError(
                "Cannot set %s to group ownership %s, group writable" %
                (path, gavoGroup),
                hint="Certain directories must be writable by multiple user ids."
                "  They must therefore belong to the group %s and be group"
                " writeable.  The attempt to make sure that's so just failed"
                " with the error message %s."
                "  Either grant the directory in question to yourself, or"
                " fix permissions manually.  If you own the directory and"
                " sill see permission errors, try 'newgrp %s'" %
                (config.get("group"), msg, config.get("group")))


@utils.document
def makeSitePath(path):
    """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.
	"""
    return str(config.get("web", "nevowRoot") + path.lstrip("/"))


@utils.document
def makeAbsoluteURL(path):
    """returns a fully qualified URL for a rooted local part.