summaryrefslogtreecommitdiffstats
path: root/pym/_emerge/sync
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-03-08 07:43:00 +0000
committerZac Medico <zmedico@gentoo.org>2010-03-08 07:43:00 +0000
commitc3ba2ecd4edc2627969a120ebf92a25a85f87995 (patch)
tree61c83a488d7597d145ea4aba3fc8c008dd8ac8f2 /pym/_emerge/sync
parent0f666446f855aae626307dcdf34a3a3b2bda6c98 (diff)
downloadportage-c3ba2ecd4edc2627969a120ebf92a25a85f87995.tar.gz
portage-c3ba2ecd4edc2627969a120ebf92a25a85f87995.tar.bz2
portage-c3ba2ecd4edc2627969a120ebf92a25a85f87995.zip
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 <solar@g.o> for the most of this code. svn path=/main/trunk/; revision=15756
Diffstat (limited to 'pym/_emerge/sync')
-rw-r--r--pym/_emerge/sync/__init__.py0
-rw-r--r--pym/_emerge/sync/old_tree_timestamp.py99
2 files changed, 99 insertions, 0 deletions
diff --git a/pym/_emerge/sync/__init__.py b/pym/_emerge/sync/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/pym/_emerge/sync/__init__.py
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