summaryrefslogtreecommitdiff
path: root/ick2/actions.py
diff options
context:
space:
mode:
Diffstat (limited to 'ick2/actions.py')
-rw-r--r--ick2/actions.py66
1 files changed, 54 insertions, 12 deletions
diff --git a/ick2/actions.py b/ick2/actions.py
index 37ebd32..96382ef 100644
--- a/ick2/actions.py
+++ b/ick2/actions.py
@@ -85,18 +85,28 @@ class ActionFactory:
return action
def _create_action_object(self, env, spec):
- if 'shell' in spec:
- return ShellAction(env)
- if 'python' in spec:
- return PythonAction(env)
- if 'debootstrap' in spec:
- return DebootstrapAction(env)
- if 'archive' in spec:
- return ArchiveWorkspaceAction(env)
- if spec.get('action') == 'populate_systree':
- return PopulateSystreeAction(env)
- if spec.get('action') == 'create_workspace':
- return CreateWorkspaceAction(env)
+ rules = [
+ ('shell', ShellAction),
+ ('python', PythonAction),
+ ('debootstrap', DebootstrapAction),
+ ('archive', ArchiveWorkspaceAction),
+ ]
+
+ for key, klass in rules:
+ if key in spec:
+ return klass(env)
+
+ if 'action' in spec:
+ rules2 = {
+ 'populate_systree': PopulateSystreeAction,
+ 'create_workspace': CreateWorkspaceAction,
+ 'git': GitAction,
+ }
+ kind = spec['action']
+ klass = rules2.get(kind)
+ if klass:
+ return klass(env)
+
raise UnknownStepError('Unknown action %r' % spec)
@@ -290,6 +300,38 @@ class PopulateSystreeAction(Action): # pragma: no cover
return exit_code
+class GitAction(Action): # pragma: no cover
+
+ def encode_parameters(self, params):
+ pass
+
+ def execute(self, params, step):
+ env = self.get_env()
+ workspace = env.get_workspace_directory()
+
+ git_dir = params.get('git_dir')
+ if git_dir is None:
+ env.report(1, 'git_dir not provided\n')
+ if git_dir.startswith('/') or '..' in git_dir:
+ env.report(1, 'git_dir not acceptable\n')
+
+ git_url = params.get('git_url')
+ if git_url is None:
+ env.report(1, 'git_url not provided\n')
+
+ pathname = os.path.join(workspace, git_dir)
+ if os.path.exists(pathname):
+ argv = ['git', 'remote', '-v', 'update', '--prune']
+ cwd = pathname
+ else:
+ argv = ['git', 'clone', '-v', git_url, git_dir]
+ cwd = workspace
+
+ exit_code = env.host_runcmd(argv, cwd=cwd)
+ env.report(exit_code, 'git finished (exit code %d)\n' % exit_code)
+ return exit_code
+
+
def make_directory_empty(env, dirname):
return env.runcmd(
['sudo', 'find', dirname, '-mindepth', '1', '-delete'])