summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-04-27 14:01:08 +0300
committerLars Wirzenius <liw@liw.fi>2018-04-27 14:35:34 +0300
commitbfa6476104848546320d1e2e9b7217f0d0312a68 (patch)
tree5461cbc6c68446f8914923ce3b2fee2833fbf4fe
parent10edd0e04571842c0991e2d9cbf83cb26b3960f6 (diff)
downloadick2-bfa6476104848546320d1e2e9b7217f0d0312a68.tar.gz
Add: rsync action
-rw-r--r--NEWS3
-rw-r--r--ick2/actions.py38
2 files changed, 41 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 9a522b7..44e83e1 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,9 @@ Version 0.47+git, not yet released
* New action to do `git clone` or `git remote update`.
+* New action to do `rsync -av` from a directory in the workspace to a
+ remote server.
+
Version 0.47, released 2018-04-25
----------------------------------
diff --git a/ick2/actions.py b/ick2/actions.py
index 96382ef..185f171 100644
--- a/ick2/actions.py
+++ b/ick2/actions.py
@@ -101,6 +101,7 @@ class ActionFactory:
'populate_systree': PopulateSystreeAction,
'create_workspace': CreateWorkspaceAction,
'git': GitAction,
+ 'rsync': RsyncAction,
}
kind = spec['action']
klass = rules2.get(kind)
@@ -332,6 +333,43 @@ class GitAction(Action): # pragma: no cover
return exit_code
+class RsyncAction(Action): # pragma: no cover
+
+ def encode_parameters(self, params):
+ pass
+
+ def execute(self, params, step):
+ env = self.get_env()
+ workspace = env.get_workspace_directory()
+
+ rsync_src = params.get('rsync_src')
+ if rsync_src is None:
+ env.report(1, 'rsync_src not provided\n')
+ if not self._is_relative(rsync_src):
+ env.report(1, 'rsync_src not acceptable\n')
+
+ rsync_target = params.get('rsync_target')
+ if rsync_target is None:
+ env.report(1, 'git_url not provided\n')
+ if not self._remote(rsync_target):
+ env.report(1, 'rsync_target not acceptable\n')
+
+ argv = ['rsync', '-av', './' + rsync_src + '/.', rsync_target + '/.']
+ exit_code = env.host_runcmd(argv, cwd=workspace)
+ env.report(exit_code, 'rsync finished (exit code %d)\n' % exit_code)
+ return exit_code
+
+ def _is_relative(self, src):
+ if src.startswith('/'):
+ return False
+ if '../' in src:
+ return False
+ return True
+
+ def _remote(self, target):
+ return ':' in target
+
+
def make_directory_empty(env, dirname):
return env.runcmd(
['sudo', 'find', dirname, '-mindepth', '1', '-delete'])