From 18b54e6f76d45567fb6800ebc137b8299db8499f Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Mon, 9 Mar 2009 01:29:23 +0530 Subject: 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. --- check.py | 28 ++++++++++++++++++++++++---- 1 file 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): -- cgit v1.2.3-65-gdbad