From: Marius Mauch <genone@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: [gentoo-portage-dev] [PATCH] elog-modules
Date: Sat, 22 Oct 2005 17:34:01 +0200 [thread overview]
Message-ID: <20051022173401.3d1eb9dc@sven.genone.homeip.net> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 540 bytes --]
This "patch" depends on elog_base (although it doesn't break anything
without it) and adds the actual logging modules. I've just atatched the
files completely, as a) svn diff doesn't play nice with generating
new-file diffs and b) they are just new files to be dropped in
pym/elog_modules (together with an empty __init__.py).
Marius
--
Public Key at http://www.genone.de/info/gpg-key.pub
In the beginning, there was nothing. And God said, 'Let there be
Light.' And there was still nothing, but you could see a bit better.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: mod_custom.py --]
[-- Type: text/x-python; name=mod_custom.py, Size: 742 bytes --]
import elog_modules.mod_save, portage_exec, portage_exception
def process(mysettings, cpv, logentries, fulltext):
elog_modules.mod_save.process(mysettings, cpv, logentries, fulltext)
if (not "PORTAGE_ELOG_COMMAND" in mysettings.keys()) \
or len(mysettings["PORTAGE_ELOG_COMMAND"]) == 0:
raise portage_exception.MissingParameter("!!! Custom logging requested but PORTAGE_ELOG_COMMAND is not defined")
else:
mylogcmd = mysettings["PORTAGE_ELOG_COMMAND"]
mylogcmd.replace("${LOGFILE}", elogfilename)
mylogcmd.replace("${PACKAGE}", cpv)
retval = portage_exec.spawn_bash(mylogcmd)
if retval != 0:
raise portage_exception.PortageException("!!! PORTAGE_ELOG_COMMAND failed with exitcode %d" % retval)
return
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.3: mod_mail.py --]
[-- Type: text/x-python; name=mod_mail.py, Size: 2418 bytes --]
import smtplib, email.Message, socket, portage_exception
def process(mysettings, cpv, logentries, fulltext):
mymailhost = "localhost"
mymailport = 25
mymailuser = ""
mymailpasswd = ""
myrecipient = "root@localhost"
mysubject = "[portage] Ebuild log for %s"
# Syntax for PORTAGE_LOG_MAILURI (if defined):
# adress [[user:passwd@]mailserver[:port]]
# where adress: recipient adress
# user: username for smtp auth (defaults to none)
# passwd: password for smtp auth (defaults to none)
# mailserver: smtp server that should be used to deliver the mail (defaults to localhost)
# port: port to use on the given smtp server (defaults to 25, values > 100000 indicate that starttls should be used on (port-100000))
if "PORTAGE_ELOG_MAILURI" in mysettings.keys():
if " " in mysettings["PORTAGE_ELOG_MAILURI"]:
myrecipient, mymailuri = mysettings["PORTAGE_ELOG_MAILURI"].split()
if "@" in mymailuri:
myauthdata, myconndata = mymailuri.split("@")
try:
mymailuser,mymailpasswd = myauthdata.split(":")
except ValueError:
print "!!! invalid SMTP AUTH configuration, trying unauthenticated ..."
else:
myconndata = mymailuri
if ":" in myconndata:
mymailhost,mymailport = myconndata.split(":")
else:
mymailhost = myconndata
else:
myrecipient = mysettings["PORTAGE_ELOG_MAILURI"]
if "PORTAGE_ELOG_MAILSUBJECT" in mysettings.keys():
mysubject = mysettings["PORTAGE_ELOG_MAILSUBJECT"]
try:
mymessage = email.Message.Message()
mymessage.set_unixfrom("portage")
mymessage.set_payload(fulltext)
mymessage["To"] = myrecipient
mymessage["Subject"] = mysubject % cpv
if int(mymailport) > 100000:
myconn = smtplib.SMTP(mymailhost, int(mymailport) - 100000)
myconn.starttls()
else:
myconn = smtplib.SMTP(mymailhost, mymailport)
if mymailuser != "" and mymailpasswd != "":
myconn.login(mymailuser, mymailpasswd)
myconn.sendmail("portage", myrecipient, mymessage.as_string())
myconn.quit()
except smtplib.SMTPException, e:
raise portage_exception.PortageException("!!! An error occured while trying to send logmail:\n"+str(e))
except socket.error, e:
raise portage_exception.PortageException("!!! A network error occured while trying to send logmail:\n"+str(e)+"\nSure you configured PORTAGE_ELOG_MAILURI correctly?")
return
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.4: mod_save.py --]
[-- Type: text/x-python; name=mod_save.py, Size: 648 bytes --]
import os, time
from portage_data import portage_uid, portage_gid
def process(mysettings, cpv, logentries, fulltext):
cpv_path = cpv.replace("/", ":")
if mysettings.has_key["PORTAGE_ELOG_SAVEDIR"]:
elogdir = mysettings["PORTAGE_ELOG_SAVEDIR"]
else:
elogdir = mysettings["PORTAGE_TMPDIR"]+"/elogs"
if not os.path.exists(elogdir):
os.makedirs(elogdir)
os.chown(elogdir, portage_uid, portage_gid)
os.chmod(elogdir, 0770)
elogfilename = elogdir+"/"+cpv_path+":"+time.strftime("%Y%m%d-%H%M%S", time.gmtime(time.time()))+".log"
elogfile = open(elogfilename, "w")
elogfile.write(fulltext)
elogfile.close()
return
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.5: mod_syslog.py --]
[-- Type: text/x-python; name=mod_syslog.py, Size: 602 bytes --]
import syslog
from portage_const import EBUILD_PHASES
def process(mysettings, cpv, logentries, fulltext):
syslog.openlog("portage", syslog.LOG_ERR | syslog.LOG_WARNING | syslog.LOG_INFO | syslog.LOG_NOTICE, syslog.LOG_LOCAL5)
for phase in EBUILD_PHASES.split():
if not phase in logentries:
continue
for msgtype,msgcontent in logentries[phase]:
pri = {"INFO": syslog.LOG_INFO, "WARN": syslog.LOG_WARNING, "ERROR": syslog.LOG_ERR, "LOG": syslog.LOG_NOTICE}
msgtext = "".join(msgcontent)
syslog.syslog(pri[msgtype], "%s: %s: %s" % (cpv, phase, msgtext))
syslog.closelog()
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next reply other threads:[~2005-10-22 15:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-22 15:34 Marius Mauch [this message]
2005-10-23 3:06 ` [gentoo-portage-dev] [PATCH] elog-modules Jason Stubbs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051022173401.3d1eb9dc@sven.genone.homeip.net \
--to=genone@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox