summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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):