Add FEATURES=clean-logs support.
authorZac Medico <zmedico@gentoo.org>
Wed, 31 Aug 2011 17:54:52 +0000 (10:54 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 31 Aug 2011 17:54:52 +0000 (10:54 -0700)
Enable automatic execution of the command specified by the
PORT_LOGDIR_CLEAN variable. The default PORT_LOGDIR_CLEAN setting will
remove all files from PORT_LOGDIR that were last modified at least 7
days ago.

cnf/make.globals
man/make.conf.5
pym/_emerge/main.py
pym/portage/const.py
pym/portage/package/ebuild/_config/special_env_vars.py

index 2892d50896e8ccbd089b15c77a63d9dcecaa19bc..fcd0b41da034f921fd59b78f39c774d79e9c64e1 100644 (file)
@@ -101,6 +101,9 @@ PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress
 # message should be produced.
 PORTAGE_SYNC_STALE="30"
 
+# Executed before emerge exit if FEATURES=clean-logs is enabled.
+PORT_LOGDIR_CLEAN="find \"\${PORT_LOGDIR}\" -type f ! -name \"summary.log*\" -mtime +7 -delete"
+
 # Minimal CONFIG_PROTECT
 CONFIG_PROTECT="/etc"
 CONFIG_PROTECT_MASK="/etc/env.d"
index 76f32f71892770c1357610fcf83ab1b35c27799c..ac49c886e1b82036381b1b3582cb5ac0c3b2b886 100644 (file)
@@ -247,6 +247,12 @@ like "File not recognized: File truncated"), try recompiling the application
 with ccache disabled before reporting a bug. Unless you are doing development
 work, do not enable ccache.
 .TP
+.B clean\-logs
+Enable automatic execution of the command specified by the
+PORT_LOGDIR_CLEAN variable. The default PORT_LOGDIR_CLEAN setting will
+remove all files from PORT_LOGDIR that were last modified at least 7
+days ago.
+.TP
 .B collision\-protect
 A QA\-feature to ensure that a package doesn't overwrite files it doesn't own.
 The \fICOLLISION_IGNORE\fR variable can be used to selectively disable this
@@ -609,6 +615,13 @@ directory does not exist, it will be created automatically and group permissions
 will be applied to it.  If the directory already exists, portage will not
 modify it's permissions.
 .TP
+.B PORT_LOGDIR_CLEAN
+This variable should contain a command for portage to call in order
+to clean PORT_LOGDIR. The command string should contain a
+\\${PORT_LOGDIR} place\-holder that will be substituted
+with the value of that variable. This variable will have no effect
+unless \fBclean\-logs\fR is enabled in \fBFEATURES\fR.
+.TP
 \fBPORTAGE_BINHOST\fR = \fI[space delimited URI list]\fR
 This is a list of hosts from which portage will grab prebuilt\-binary packages.
 Each entry in the list must specify the full address of a directory
index 343fd58127c41a2d383dd8a2a5885ed200ad5594..b3e047c9dc76ae19a59d8499bcf0f88abbffa46a 100644 (file)
@@ -28,7 +28,8 @@ import portage.exception
 from portage.data import secpass
 from portage.dbapi.dep_expand import dep_expand
 from portage.util import normalize_path as normpath
-from portage.util import shlex_split, writemsg_level, writemsg_stdout
+from portage.util import (shlex_split, varexpand,
+       writemsg_level, writemsg_stdout)
 from portage._sets import SETPREFIX
 from portage._global_updates import _global_updates
 
@@ -388,6 +389,8 @@ def post_emerge(myaction, myopts, myfiles,
                                " %s spawn failed of %s\n" % (bad("*"), postemerge,),
                                level=logging.ERROR, noiselevel=-1)
 
+       clean_logs(settings)
+
        if "--quiet" not in myopts and \
                myaction is None and "@world" in myfiles:
                show_depclean_suggestion()
@@ -1222,7 +1225,6 @@ def ionice(settings):
        if not ionice_cmd:
                return
 
-       from portage.util import varexpand
        variables = {"PID" : str(os.getpid())}
        cmd = [varexpand(x, mydict=variables) for x in ionice_cmd]
 
@@ -1238,6 +1240,35 @@ def ionice(settings):
                out.eerror("PORTAGE_IONICE_COMMAND returned %d" % (rval,))
                out.eerror("See the make.conf(5) man page for PORTAGE_IONICE_COMMAND usage instructions.")
 
+def clean_logs(settings):
+
+       if "clean-logs" not in settings.features:
+               return
+
+       clean_cmd = settings.get("PORT_LOGDIR_CLEAN")
+       if clean_cmd:
+               clean_cmd = shlex_split(clean_cmd)
+       if not clean_cmd:
+               return
+
+       logdir = settings.get("PORT_LOGDIR")
+       if logdir is None or not os.path.isdir(logdir):
+               return
+
+       variables = {"PORT_LOGDIR" : logdir}
+       cmd = [varexpand(x, mydict=variables) for x in clean_cmd]
+
+       try:
+               rval = portage.process.spawn(cmd, env=os.environ)
+       except portage.exception.CommandNotFound:
+               rval = 127
+
+       if rval != os.EX_OK:
+               out = portage.output.EOutput()
+               out.eerror("PORT_LOGDIR_CLEAN returned %d" % (rval,))
+               out.eerror("See the make.conf(5) man page for "
+                       "PORT_LOGDIR_CLEAN usage instructions.")
+
 def setconfig_fallback(root_config):
        from portage._sets.base import DummyPackageSet
        from portage._sets.files import WorldSelectedSet
index ecaa8f1d301f4b1c5c9e8f784fcc2f7cff3e17af..f24a1a912dfcfaaca39d544aeb9a4d41b19c2430 100644 (file)
@@ -88,7 +88,8 @@ EBUILD_PHASES            = ("pretend", "setup", "unpack", "prepare", "configure"
 SUPPORTED_FEATURES       = frozenset([
                            "allow-missing-manifests",
                            "assume-digests", "binpkg-logs", "buildpkg", "buildsyspkg", "candy",
-                           "ccache", "chflags", "collision-protect", "compress-build-logs",
+                           "ccache", "chflags", "clean-logs",
+                           "collision-protect", "compress-build-logs",
                            "digest", "distcc", "distcc-pump", "distlocks", "ebuild-locks", "fakeroot",
                            "fail-clean", "fixpackages", "force-mirror", "getbinpkg",
                            "installsources", "keeptemp", "keepwork", "fixlafiles", "lmirror",
index 1b54867be8bf27b2e485aa0f028978693bcafeba..99321e26e5466cf047560af3099630a6fda3e1f7 100644 (file)
@@ -156,7 +156,7 @@ environ_filter += [
        "PORTAGE_RO_DISTDIRS",
        "PORTAGE_RSYNC_EXTRA_OPTS", "PORTAGE_RSYNC_OPTS",
        "PORTAGE_RSYNC_RETRIES", "PORTAGE_SYNC_STALE",
-       "PORTAGE_USE", "PORT_LOGDIR",
+       "PORTAGE_USE", "PORT_LOGDIR", "PORT_LOGDIR_CLEAN",
        "QUICKPKG_DEFAULT_OPTS",
        "RESUMECOMMAND", "RESUMECOMMAND_FTP",
        "RESUMECOMMAND_HTTP", "RESUMECOMMAND_HTTPS",