From c3ba2ecd4edc2627969a120ebf92a25a85f87995 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 8 Mar 2010 07:43:00 +0000 Subject: [PATCH] Produce a warning message if the timestamp of the portage tree is more than 30 days old, and make it adjustable via the PORTAGE_SYNC_STALE variable. Thanks to Ned Ludd for the most of this code. svn path=/main/trunk/; revision=15756 --- cnf/make.globals | 4 ++ man/make.conf.5 | 6 ++ pym/_emerge/actions.py | 3 + pym/_emerge/sync/__init__.py | 0 pym/_emerge/sync/old_tree_timestamp.py | 99 ++++++++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 pym/_emerge/sync/__init__.py create mode 100644 pym/_emerge/sync/old_tree_timestamp.py diff --git a/cnf/make.globals b/cnf/make.globals index 76b48fbf9..b1b2cf49c 100644 --- a/cnf/make.globals +++ b/cnf/make.globals @@ -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" CONFIG_PROTECT_MASK="/etc/env.d" diff --git a/man/make.conf.5 b/man/make.conf.5 index 18d769f32..71a308139 100644 --- a/man/make.conf.5 +++ b/man/make.conf.5 @@ -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. +.br +Defaults to 30. +.TP \fBPORTAGE_TMPDIR\fR = \fI[path]\fR Defines the location of the temporary build directories. .br diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index 6cb690458..208685946 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -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 index 000000000..e69de29bb diff --git a/pym/_emerge/sync/old_tree_timestamp.py b/pym/_emerge/sync/old_tree_timestamp.py new file mode 100644 index 000000000..f96274374 --- /dev/null +++ b/pym/_emerge/sync/old_tree_timestamp.py @@ -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 -- 2.26.2