summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <ford_prefect@gentoo.org>2008-12-28 00:04:38 +0530
committerArun Raghavan <ford_prefect@gentoo.org>2008-12-28 00:04:38 +0530
commitb3c784d8337857ebfabdde854cff263ac8505135 (patch)
treef82dbc3c9071960ee4cad816f41e2488ebbb0e83
parentReminder about timeouts. (diff)
downloadgard-b3c784d8337857ebfabdde854cff263ac8505135.tar.gz
gard-b3c784d8337857ebfabdde854cff263ac8505135.tar.bz2
gard-b3c784d8337857ebfabdde854cff263ac8505135.zip
Add support for gentoo-portage
Needed to change get_lag() to take a url instead of a path relative to self.url so that the rsync based checkers can just pass it a 'file://' type URL.
-rw-r--r--check.py42
1 files changed, 36 insertions, 6 deletions
diff --git a/check.py b/check.py
index df71db3..3c81eeb 100644
--- a/check.py
+++ b/check.py
@@ -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