diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2008-12-21 19:56:41 -0800 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2008-12-21 19:56:41 -0800 |
commit | 2226dba4a9011b89fb8054ec3d220e1221e83de5 (patch) | |
tree | 4c21963b3f2d4efdfaa5f99abcd989305eee7e70 /check.py | |
parent | Make GARD uses the GardCheck classes for checking. (diff) | |
download | gard-2226dba4a9011b89fb8054ec3d220e1221e83de5.tar.gz gard-2226dba4a9011b89fb8054ec3d220e1221e83de5.tar.bz2 gard-2226dba4a9011b89fb8054ec3d220e1221e83de5.zip |
Factor out duplicate code.
Diffstat (limited to 'check.py')
-rw-r--r-- | check.py | 48 |
1 files changed, 21 insertions, 27 deletions
@@ -4,6 +4,7 @@ import logging import urllib2 import time import rfc822 +import re class GardCheck: # Base class which provides some helper functions @@ -69,35 +70,35 @@ class GardCheck: def timestamp_to_secs(self, ts): return rfc822.mktime_tz(rfc822.parsedate_tz(ts)) - # Override these in child classes - - def check(self): - return True - - def lag(self): - return None - -# Check distfiles mirrors -class DistfilesCheck(GardCheck): - def lag(self): - path = '/distfiles/timestamp.chk' - return self.get_lag(path) + # OPTIONAL: Override or supplement these in child classes if desired. + def check_name(self): + return re.sub('.*\.|(Check$)', '', str(self.__class__)) def check(self, maxlag): lag = self.lag() if lag is None: - self.log_error('Could not get distfiles timestamp for ' + self.url) + self.log_error('Could not get %s timestamp for %s' % (self.check_name(), self.url)) ret = False elif lag > maxlag: - self.log_error('Distfiles at %s is lagging (delta is %s)' \ - % (self.url, self.humanize_time(lag))) + self.log_error('%s at %s is lagging (delta is %s)' \ + % (self.check_name(), self.url, self.humanize_time(lag))) ret = False else: ret = True return ret + # REQUIRED: You must override these in child classes + def lag(self): + return None + +# Check distfiles mirrors +class DistfilesCheck(GardCheck): + def lag(self): + path = '/distfiles/timestamp.chk' + return self.get_lag(path) + # Check releases mirrors class ReleasesCheck(GardCheck): def lag(self): @@ -105,17 +106,10 @@ class ReleasesCheck(GardCheck): return self.get_lag(path) def check(self, maxlag): - lag = self.lag() - - if lag is None: - self.log_error('Could not get releases timestamp for ' + self.url) - ret = False - elif lag > maxlag: - self.log_error('Releases at %s is lagging (delta is %s)' \ - % (self.url, self.humanize_time(lag))) - ret = False - else: - ret = True + # Call the superclass first if exists + try: fun = getattr(GardCheck, 'check') + except AttributeError: pass + else: ret = fun(self, maxlag) # Verify that releases/.test/THIS-FILE-SHOULD-NOT-BE-PUBLIC.txt # is not world readable |