diff options
-rw-r--r-- | check.py | 42 |
1 files changed, 36 insertions, 6 deletions
@@ -5,6 +5,9 @@ import urllib2 import time import rfc822 import re +import tempfile +import subprocess +import os class GardCheck: # Base class which provides some helper functions @@ -34,6 +37,18 @@ class GardCheck: return ret + # Gets a file over rsync and puts it in a temporary directory, + # if specified + def get_file_rsync(self, path, dir='.'): + target = '%s::%s' % (self.url, path) + + retcode = subprocess.call(['rsync', '-aqP', '--no-motd', + '--contimeout=30', target, dir]) + if retcode > 0: + logging.error('return value of rsync during \ + gentoo-portage check was ' + str(retcode)) + return None + # Takes the URL to a timestamp.{chk|x} file and returns the # corresponding time stamp in seconds def _get_timestamp_from_url(self, url): @@ -55,8 +70,8 @@ class GardCheck: return ts - def get_lag(self, path): - ts = self._get_timestamp_from_url(self.url + path) + def get_lag(self, url): + ts = self._get_timestamp_from_url(url) now = time.mktime(time.gmtime()) if ts is None or now < ts: return None @@ -97,26 +112,27 @@ class GardCheck: # Check distfiles mirrors class DistfilesCheck(GardCheck): def lag(self): + path = '/distfiles/timestamp.chk' - return self.get_lag(path) + return self.get_lag(self.url + path) # Check experimental mirrors class ExperimentalCheck(GardCheck): def lag(self): path = '/experimental/.timestamp-experimental.x' - return self.get_lag(path) + return self.get_lag(self.url + path) # Check snapshot mirrors class SnapshotsCheck(GardCheck): def lag(self): path = '/snapshots/.timestamp-snapshots.x' - return self.get_lag(path) + return self.get_lag(self.url + path) # Check releases mirrors class ReleasesCheck(GardCheck): def lag(self): path = '/releases/.test/timestamp.x' - return self.get_lag(path) + return self.get_lag(self.url + path) def check(self, maxlag): # Call the superclass first if exists @@ -132,3 +148,17 @@ class ReleasesCheck(GardCheck): return ret +class PortageCheck(GardCheck): + def lag(self): + file = 'timestamp.chk' + path = 'gentoo-portage/metadata/' + file + + self.get_file_rsync(path) + + # This is Linux-specific, but who's going to run this on + # Windows anyway? :D + url = 'file://%s/%s' % (os.path.abspath(''), file) + lag = self.get_lag(url) + + os.remove(file) + return lag |