summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <ford_prefect@gentoo.org>2009-03-09 01:29:23 +0530
committerArun Raghavan <ford_prefect@gentoo.org>2009-03-09 01:29:23 +0530
commit18b54e6f76d45567fb6800ebc137b8299db8499f (patch)
tree99f131062a73b916f6df1530010fbae225f9f76c
parentStrip trailing '/'s from URLs (diff)
downloadgard-18b54e6f76d45567fb6800ebc137b8299db8499f.tar.gz
gard-18b54e6f76d45567fb6800ebc137b8299db8499f.tar.bz2
gard-18b54e6f76d45567fb6800ebc137b8299db8499f.zip
Add support for checking rsync writability (to be enabled)
Adds a function that checks if the given rsync mirror is writable. Needs some testing before being enabled.
-rw-r--r--check.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/check.py b/check.py
index e6b875f..810a401 100644
--- a/check.py
+++ b/check.py
@@ -45,15 +45,21 @@ class GardCheck:
return ret
- # Gets a file over rsync and puts it in a temporary directory,
- # if specified (assumes URL is the form rsync://server/module
- # and takes path relative to this)
- def get_file_rsync(self, path, dir='.'):
+ # Converts an rsync URL in the rsync://server/module form to a string
+ # that can be passed to the rsync command (server::module)
+ def _rsync_url_to_cmd(self, url, path):
urlp = urlparse.urlparse(self.url)
if len(urlp.path) > 1:
# strip leading '/' from URL path
path = urlp.path[1:] + '/' + path
target = '%s::%s' % (urlp.netloc, path)
+ return target
+
+ # Gets a file over rsync and puts it in a temporary directory,
+ # if specified (assumes URL is the form rsync://server/module
+ # and takes path relative to this)
+ def get_file_rsync(self, path, dir='.'):
+ target = self._rsync_url_to_cmd(self.url, path)
retcode = subprocess.call(['rsync', '-aqP', '--no-motd',
'--contimeout=30', target, dir])
if retcode > 0:
@@ -62,6 +68,20 @@ class GardCheck:
return True
+ def check_rsync_writable(self, path):
+ target = self._rsync_url_to_cmd(self.url, path)
+
+ # Create a test file
+ file = tempfile.NamedTemporaryFile()
+ file.write('THIS_SHOULD_NOT_WORK');
+ file.flush()
+
+ retcode = subprocess.call(['rsync', '-aqP', '--no-motd',
+ '--contimeout=30', file, target])
+
+ file.close()
+ return retcode > 0
+
# Takes the URL to a timestamp.{chk|x} file and returns the
# corresponding time stamp in seconds
def _get_timestamp_from_url(self, url):