[gnome-ostree/wip/gjs-round2: 7/10] ostbuild-qemu-pull-deploy: Shell script extracted from privhelper-deploy-qemu
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-ostree/wip/gjs-round2: 7/10] ostbuild-qemu-pull-deploy: Shell script extracted from privhelper-deploy-qemu
- Date: Tue, 11 Dec 2012 17:11:30 +0000 (UTC)
commit 1c1a4f8929c55c76a20b3a292cf5baf242bbb4fe
Author: Colin Walters <walters verbum org>
Date: Sun Dec 9 17:46:10 2012 -0500
ostbuild-qemu-pull-deploy: Shell script extracted from privhelper-deploy-qemu
This is actually so external command heavy that using either Python or
gjs is massive overkill. Also, since it needs to be run as root, we
can't easily use the jhbuild environment.
Makefile-ostbuild.am | 4 +-
src/ostbuild/js/qemu_pull_deploy.js | 101 +++++++++++++++++++
src/ostbuild/ostbuild-qemu-pull-deploy | 52 ++++++++++
src/ostbuild/pyostbuild/builtin_deploy_qemu.py | 65 ------------
.../pyostbuild/builtin_privhelper_deploy_qemu.py | 106 --------------------
src/ostbuild/pyostbuild/main.py | 5 +-
6 files changed, 156 insertions(+), 177 deletions(-)
---
diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am
index 7556b15..7c66853 100644
--- a/Makefile-ostbuild.am
+++ b/Makefile-ostbuild.am
@@ -33,7 +33,7 @@ ostbuild-js: src/ostbuild/ostbuild-js.in Makefile
EXTRA_DIST += ostbuild/ostbuild-js.in
if BUILDSYSTEM
-bin_SCRIPTS += ostbuild ostbuild-js
+bin_SCRIPTS += ostbuild ostbuild-js $(srcdir)/src/ostbuild/ostbuild-qemu-pull-deploy
utils_SCRIPTS = \
src/ostbuild/ostree-build-compile-one \
@@ -45,8 +45,6 @@ pyostbuilddir=$(libdir)/ostbuild/pyostbuild
pyostbuild_PYTHON = \
src/ostbuild/pyostbuild/buildutil.py \
src/ostbuild/pyostbuild/builtin_build.py \
- src/ostbuild/pyostbuild/builtin_deploy_qemu.py \
- src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py \
src/ostbuild/pyostbuild/builtin_source_diff.py \
src/ostbuild/pyostbuild/builtins.py \
src/ostbuild/pyostbuild/filemonitor.py \
diff --git a/src/ostbuild/js/qemu_pull_deploy.js b/src/ostbuild/js/qemu_pull_deploy.js
new file mode 100755
index 0000000..6807629
--- /dev/null
+++ b/src/ostbuild/js/qemu_pull_deploy.js
@@ -0,0 +1,101 @@
+// Copyright (C) 2012 Colin Walters <walters verbum org>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+const Lang = imports.lang;
+const Format = imports.format;
+
+const GSystem = imports.gi.GSystem;
+
+const ProcUtil = imports.procutil;
+
+var loop = GLib.MainLoop.new(null, true);
+
+const QemuPullDeploy = new Lang.Class({
+ Name: 'QemuPullDeploy',
+
+ _umount: function(cancellable) {
+ let proc = GSystem.Subprocess.new_simple_argv(['umount', self.mountpoint],
+ GSystem.SubprocessStreamDisposition.NULL,
+ GSystem.SubprocessStreamDisposition.NULL);
+ proc.wait_sync(cancellable);
+ },
+
+ _createQemuDisk: function(cancellable) {
+ let success = false;
+ let tmpPath = this.qemuPath.get_parent().get_child(this.qemuPath.get_basename() + '.tmp');
+ GSystem.shutil_rm_rf(tmpPath, cancellable);
+ ProcUtil.runSync(['qemu-img', 'create', tmpPath.get_path(), '6G'], cancellable,
+ {cwd: this.ostreeDir});
+ ProcUtil.runSync(['mkfs.ext4', '-q', '-F', tmpPath.get_path()], cancellable,
+ {cwd: this.ostreeDir});
+
+ this._umount();
+ try {
+ ProcUtil.runSync(['mount', '-o', 'loop', tmpPath.get_path(), this.mountpoint], cancellable);
+ ProcUtil.runSync(['ostree', 'admin', 'init-fs', this.mountpoint.get_path()], cancellable);
+ success = true;
+ } finally {
+ this._umount();
+ }
+ if (success) {
+ GSystem.file_rename(tmpPath, this.qemuPath, cancellable);
+ }
+ },
+
+ execute: function(argv) {
+ let cancellable = null;
+ let parser = new ArgParse.ArgumentParser("Copy from local repository into qemu disk and deploy");
+ parser.addArgument('--rootdir', {help:"Directory containing OSTree data (default: /ostree)"});
+ parser.addArgument('srcrepo');
+ parser.addArgument('target');
+
+ let args = parser.parse(argv);
+
+ if (args.rootdir) {
+ this.ostreeDir = Gio.File.new_for_path(args.rootdir);
+ } else {
+ this.ostreeDir = Gio.File.new_for_path('/ostree');
+ }
+
+ this.qemuPath = this.ostreeDir.get_child('ostree-qemu.img');
+ this.mountpoint = this.ostreeDir.get_child('ostree-qemu-mnt');
+ GSystem.file_ensure_directory(this.mountpoint);
+
+ if (!this.qemuPath.query_exists(cancellable)) {
+ this._createQemuDisk(cancellable);
+ }
+
+ this._umount();
+ let ostreeDir = this.mountpoint.get_child('ostree');
+ let repoPath = ostreeDir.get_child('repo');
+ try {
+ ProcUtil.runSync(['mount', '-o', 'loop', this.qemuPath.get_path(), this.mountpoint], cancellable);
+ ProcUtil.runSync(['ostree', '--repo=' + repoPath.get_path(), 'pull-local', args.srcrepo, args.target], cancellable);
+ ProcUtil.runSync(['ostree', 'admin', '--ostree-dir=' + ostreeDir.get_path(), 'deploy', '--no-kernel', args.target], cancellable,
+ {cwd:ostreeDir});
+ } finally {
+ this._umount();
+ }
+ }
+});
+
+var app = new QemuPullDeploy();
+GLib.idle_add(GLib.PRIORITY_DEFAULT,
+ function() { try { app.execute(ARGV); } finally { loop.quit(); }; return false; });
+loop.run();
diff --git a/src/ostbuild/ostbuild-qemu-pull-deploy b/src/ostbuild/ostbuild-qemu-pull-deploy
new file mode 100644
index 0000000..03d41e3
--- /dev/null
+++ b/src/ostbuild/ostbuild-qemu-pull-deploy
@@ -0,0 +1,52 @@
+#!/bin/bash
+# Copyright (C) 2012 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+set -e
+set -x
+
+srcrepo=$1
+shift
+target=$1
+shift
+
+qemu_path=ostree-qemu.img
+mountpoint=ostree-qemu-mnt
+
+mkdir -p ${mountpoint}
+
+if ! test -f ${qemu_path}; then
+ tmppath=${qemu_path}.tmp
+ rm -f ${tmppath}
+ qemu-img create ${tmppath} 8G
+ mkfs.ext4 -q -F ${tmppath}
+
+ umount ${mountpoint} 2>/dev/null || true
+ mount -o loop ${tmppath} ${mountpoint}
+ ostree admin init-fs ${mountpoint} || (umount ${mountpoint} 2>/dev/null; exit 1)
+ umount ${mountpoint}
+fi
+
+ostreedir=${mountpoint}/ostree
+repopath=${ostreedir}/repo
+
+mount -o loop ${qemu_path} ${mountpoint}
+
+ostree --repo=${repopath} pull-local ${srcrepo} ${target} || (umount ${mountpoint} 2>/dev/null; exit 1)
+ostree admin --ostree-dir=${ostreedir} deploy --no-kernel ${target} || (umount ${mountpoint} 2>/dev/null; exit 1)
+
+umount ${mountpoint}
diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py
index f75f0bc..cf43f73 100755
--- a/src/ostbuild/pyostbuild/main.py
+++ b/src/ostbuild/pyostbuild/main.py
@@ -23,15 +23,14 @@ import argparse
from . import builtins
from . import builtin_build
-from . import builtin_deploy_qemu
-from . import builtin_privhelper_deploy_qemu
from . import builtin_source_diff
JS_BUILTINS = {'autobuilder': "Run resolve and build",
'checkout': "Check out source tree",
'prefix': "Display or modify \"prefix\" (build target)",
'git-mirror': "Update internal git mirror for one or more components",
- 'resolve': "Expand git revisions in source to exact targets"};
+ 'resolve': "Expand git revisions in source to exact targets",
+ 'qemu-pull-deploy': "Copy from local repository into qemu disk and deploy"};
def usage(ecode):
print "Builtins:"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]