Merged from trunk -r15750:15760
authorFabian Groffen <grobian@gentoo.org>
Tue, 9 Mar 2010 11:25:26 +0000 (11:25 -0000)
committerFabian Groffen <grobian@gentoo.org>
Tue, 9 Mar 2010 11:25:26 +0000 (11:25 -0000)
   | 15755   | Bug #308415 - Fix broken uri parameter passed to fetch ()    |
   | zmedico | for some cases when using ebuild(1).                         |

   | 15756   | Produce a warning message if the timestamp of the portage    |
   | zmedico | tree is more than 30 days old, and make it adjustable via    |
   |         | the PORTAGE_SYNC_STALE variable. Thanks to Ned Ludd          |
   |         | <solar@g.o> for the most of this code.                       |

   | 15757   | Note that PORTAGE_SYNC_STALE=0 will disable warnings.        |
   | zmedico |                                                              |

   | 15758   | Show --sync in messages, to help avoid confusion.            |
   | zmedico |                                                              |

   | 15759   | Bug #291331 - Force ascii encoding in send_mail() in order   |
   | zmedico | to avoid UnicodeEncodeError from smtplib.sendmail with       |
   |         | python3.                                                     |

svn path=/main/branches/prefix/; revision=15796

cnf/make.globals
man/make.conf.5
pym/_emerge/actions.py
pym/_emerge/sync/__init__.py [new file with mode: 0644]
pym/_emerge/sync/old_tree_timestamp.py [new file with mode: 0644]
pym/portage/mail.py
pym/portage/package/ebuild/doebuild.py

index 09910b1084be8ccddb7c22ed8538541fdf5c9fe7..e913d31b0bff8c77f5e3f0c8ef05c2393e465436 100644 (file)
@@ -83,6 +83,10 @@ PORTAGE_RSYNC_RETRIES="3"
 
 PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
 
+# The number of days after the last `emerge --sync` that a warning
+# message should be produced.
+PORTAGE_SYNC_STALE="30"
+
 # Minimal CONFIG_PROTECT
 CONFIG_PROTECT="/etc"
 
index 18d769f3239d3821c9d321071603c40efe07de35..ecf6c153e59e465c5343f677a17c126f14ecbc98 100644 (file)
@@ -643,6 +643,12 @@ giving up.
 .br
 Defaults to 3.
 .TP
+\fBPORTAGE_SYNC_STALE\fR = \fI[NUMBER]\fR
+Defines the number of days after the last `emerge \-\-sync` that a warning
+message should be produced. A value of 0 will disable warnings.
+.br
+Defaults to 30.
+.TP
 \fBPORTAGE_TMPDIR\fR = \fI[path]\fR
 Defines the location of the temporary build directories.
 .br
index 6655dea435c54fe6058eb534aa3ebdc1aaae594d..69aeb308591a354354a0b1fe69f5de85a3f5554f 100644 (file)
@@ -53,6 +53,7 @@ from _emerge.Scheduler import Scheduler
 from _emerge.search import search
 from _emerge.SetArg import SetArg
 from _emerge.show_invalid_depstring_notice import show_invalid_depstring_notice
+from _emerge.sync.old_tree_timestamp import old_tree_timestamp_warn
 from _emerge.unmerge import unmerge
 from _emerge.UnmergeDepPriority import UnmergeDepPriority
 from _emerge.UseFlagDisplay import UseFlagDisplay
@@ -64,6 +65,8 @@ if sys.hexversion >= 0x3000000:
 def action_build(settings, trees, mtimedb,
        myopts, myaction, myfiles, spinner):
 
+       old_tree_timestamp_warn(settings['PORTDIR'], settings)
+
        # validate the state of the resume data
        # so that we can make assumptions later.
        for k in ("resume", "resume_backup"):
diff --git a/pym/_emerge/sync/__init__.py b/pym/_emerge/sync/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pym/_emerge/sync/old_tree_timestamp.py b/pym/_emerge/sync/old_tree_timestamp.py
new file mode 100644 (file)
index 0000000..9bd070c
--- /dev/null
@@ -0,0 +1,99 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+import locale
+import logging
+import time
+
+from portage import os
+from portage.exception import PortageException
+from portage.localization import _
+from portage.util import grabfile, writemsg_level, writemsg_stdout
+
+def have_english_locale():
+       lang, enc = locale.getdefaultlocale()
+       if lang is not None:
+               lang = lang.lower()
+               lang = lang.split('_', 1)[0]
+       return lang is None or lang in ('c', 'en')
+
+def whenago(seconds):
+       sec = int(seconds)
+       mins = 0
+       days = 0
+       hrs = 0
+       years = 0
+       out = []
+
+       if sec > 60:
+               mins = sec / 60
+               sec = sec % 60
+       if mins > 60:
+               hrs = mins / 60
+               mins = mins % 60
+       if hrs > 24:
+               days = hrs / 24
+               hrs = hrs % 24
+       if days > 365:
+               years = days / 365
+               days = days % 365
+
+       if years:
+               out.append(str(years)+"y ")
+       if days:
+               out.append(str(days)+"d ")
+       if hrs:
+               out.append(str(hrs)+"h ")
+       if mins:
+               out.append(str(mins)+"m ")
+       if sec:
+               out.append(str(sec)+"s ")
+
+       return "".join(out).strip()
+
+def old_tree_timestamp_warn(portdir, settings):
+       unixtime = time.time()
+       default_warnsync = 30
+
+       timestamp_file = os.path.join(portdir, "metadata/timestamp.x")
+       try:
+               lastsync = grabfile(timestamp_file)
+       except PortageException:
+               return False
+
+       if not lastsync:
+               return False
+
+       lastsync = lastsync[0].split()
+       if not lastsync:
+               return False
+
+       try:
+               lastsync = int(lastsync[0])
+       except ValueError:
+               return False
+
+       var_name = 'PORTAGE_SYNC_STALE'
+       try:
+               warnsync = float(settings.get(var_name, default_warnsync))
+       except ValueError:
+               writemsg_level("!!! %s contains non-numeric value: %s\n" % \
+                       (var_name, settings[var_name]),
+                       level=logging.ERROR, noiselevel=-1)
+               return False
+
+       if warnsync <= 0:
+               return False
+
+       if (unixtime - 86400 * warnsync) > lastsync:
+               if have_english_locale():
+                       writemsg_stdout(">>> Last emerge --sync was %s ago\n" % \
+                               whenago(unixtime - lastsync), noiselevel=-1)
+               else:
+                       writemsg_stdout(">>> %s\n" % \
+                               _("Last emerge --sync was %s") % \
+                               time.strftime('%c', time.localtime(lastsync)),
+                               noiselevel=-1)
+               return True
+       return False
index 0cc25008570fc13433ff764f23dbf4dbbe9a40e3..3836c187a4638cdd18b5f9cab3b7ee6c873563f1 100644 (file)
@@ -14,7 +14,7 @@ import time
 
 from portage import os
 from portage import _encodings
-from portage import _unicode_encode
+from portage import _unicode_decode, _unicode_encode
 from portage.localization import _
 import portage
 
@@ -135,7 +135,17 @@ def send_mail(mysettings, message):
                                myconn = smtplib.SMTP(mymailhost, mymailport)
                        if mymailuser != "" and mymailpasswd != "":
                                myconn.login(mymailuser, mymailpasswd)
-                       myconn.sendmail(myfrom, myrecipient, message.as_string())
+
+                       message_str = message.as_string()
+                       if sys.hexversion >= 0x3000000:
+                               # Force ascii encoding in order to avoid UnicodeEncodeError
+                               # from smtplib.sendmail with python3 (bug #291331).
+                               message_str = _unicode_encode(message_str,
+                                       encoding='ascii', errors='backslashreplace')
+                               message_str = _unicode_decode(message_str,
+                                       encoding='ascii', errors='replace')
+
+                       myconn.sendmail(myfrom, myrecipient, message_str)
                        myconn.quit()
                except smtplib.SMTPException as e:
                        raise portage.exception.PortageException(_("!!! An error occured while trying to send logmail:\n")+str(e))
index f3699bc2a574be6056468690caface79f3b7751c..7f848d76ece6a7a600b799b1bbaaa856173d4420 100644 (file)
@@ -812,7 +812,8 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
                        mydo not in ("digest", "manifest") and "noauto" not in features)
                alist = mysettings.configdict["pkg"].get("A")
                aalist = mysettings.configdict["pkg"].get("AA")
-               if alist is None or aalist is None:
+               if alist is None or aalist is None or \
+                       (not emerge_skip_distfiles and need_distfiles):
                        # Make sure we get the correct tree in case there are overlays.
                        mytree = os.path.realpath(
                                os.path.dirname(os.path.dirname(mysettings["O"])))
@@ -829,25 +830,26 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
                                return 1
                        mysettings.configdict["pkg"]["A"] = " ".join(alist)
                        mysettings.configdict["pkg"]["AA"] = " ".join(aalist)
+
+                       if not emerge_skip_distfiles and need_distfiles:
+                               if "mirror" in features or fetchall:
+                                       fetchme = aalist
+                               else:
+                                       fetchme = alist
+                               if not fetch(fetchme, mysettings, listonly=listonly,
+                                       fetchonly=fetchonly):
+                                       return 1
+
                else:
                        alist = set(alist.split())
                        aalist = set(aalist.split())
-               if ("mirror" in features) or fetchall:
-                       fetchme = aalist
-                       checkme = aalist
-               else:
-                       fetchme = alist
-                       checkme = alist
 
                if mydo == "fetch":
                        # Files are already checked inside fetch(),
                        # so do not check them again.
                        checkme = []
-
-               if not emerge_skip_distfiles and \
-                       need_distfiles and not fetch(
-                       fetchme, mysettings, listonly=listonly, fetchonly=fetchonly):
-                       return 1
+               else:
+                       checkme = alist
 
                if mydo == "fetch" and listonly:
                        return 0