[gnome-ostree/wip/builtin-rework] wip/buitin-rework
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-ostree/wip/builtin-rework] wip/buitin-rework
- Date: Fri, 18 Jan 2013 23:54:36 +0000 (UTC)
commit 47f4d1779b612870c73ac64a359b21364d329bb1
Author: Colin Walters <walters verbum org>
Date: Fri Jan 18 18:54:23 2013 -0500
wip/buitin-rework
src/ostbuild/js/builtin.js | 49 ++++++++++++++++++++++++++++
src/ostbuild/js/builtins/checkout.js | 43 ++++++++----------------
src/ostbuild/js/main.js | 59 +++++++++++++++++++++++++--------
3 files changed, 108 insertions(+), 43 deletions(-)
---
diff --git a/src/ostbuild/js/builtin.js b/src/ostbuild/js/builtin.js
new file mode 100644
index 0000000..8286007
--- /dev/null
+++ b/src/ostbuild/js/builtin.js
@@ -0,0 +1,49 @@
+// Copyright (C) 2012,2013 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 Config = imports.config;
+const Params = imports.params;
+const ArgParse = imports.argparse;
+
+const Builtin = new Lang.Class({
+ Name: 'Builtin',
+
+ DESCRIPTION: null,
+
+ _init: function() {
+ this.parser = new ArgParse.ArgumentParser(this.DESCRIPTION);
+
+ this.config = Config.get();
+ this.workdir = Gio.File.new_for_path(this.config.getGlobal('workdir'));
+ this.mirrordir = Gio.File.new_for_path(this.config.getGlobal('mirrordir'));
+ },
+
+ _initFromArgs: function(prefix) {
+ this.prefix = args.prefix || this.config.getPrefix();
+ },
+
+ execute: function(argv) {
+ throw new Error("Not implemented");
+ }
+});
diff --git a/src/ostbuild/js/builtins/checkout.js b/src/ostbuild/js/builtins/checkout.js
index 6210ee9..7a4f8fc 100644
--- a/src/ostbuild/js/builtins/checkout.js
+++ b/src/ostbuild/js/builtins/checkout.js
@@ -22,6 +22,7 @@ const Format = imports.format;
const GSystem = imports.gi.GSystem;
+const Builtin = imports.builtin;
const Task = imports.task;
const JsonDB = imports.jsondb;
const ProcUtil = imports.procutil;
@@ -33,8 +34,6 @@ const BuildUtil = imports.buildutil;
const Vcs = imports.vcs;
const ArgParse = imports.argparse;
-var loop = GLib.MainLoop.new(null, true);
-
function _checkoutOneComponent(mirrordir, patchdir, component, cancellable, params) {
params = Params.parse(params, { checkoutdir: null,
clean: false,
@@ -102,31 +101,28 @@ function _checkoutOneComponent(mirrordir, patchdir, component, cancellable, para
const Checkout = new Lang.Class({
Name: 'Checkout',
+ Extends: Builtin.Builtin,
_init: function() {
+ this.parent._init();
+ this.parser.addArgument('--overwrite', {action:'storeTrue'});
+ this.parser.addArgument('--prefix');
+ this.parser.addArgument('--patches-path');
+ this.parser.addArgument('--metadata-path');
+ this.parser.addArgument('--snapshot');
+ this.parser.addArgument('--checkoutdir');
+ this.parser.addArgument('--clean', {action: 'storeTrue'});
+ this.parser.addArgument('component');
},
- execute: function(argv) {
- let cancellable = null;
- let parser = new ArgParse.ArgumentParser('Check out specified modules');
- parser.addArgument('--overwrite', {action:'storeTrue'});
- parser.addArgument('--prefix');
- parser.addArgument('--patches-path');
- parser.addArgument('--metadata-path');
- parser.addArgument('--snapshot');
- parser.addArgument('--checkoutdir');
- parser.addArgument('--clean', {action: 'storeTrue'});
- parser.addArgument('component');
-
- let args = parser.parse(argv);
+ execute: function(argv, loop, cancellable) {
+ let args = this.parser.parse(argv);
- this.config = Config.get();
- this.workdir = Gio.File.new_for_path(this.config.getGlobal('workdir'));
- this.mirrordir = Gio.File.new_for_path(this.config.getGlobal('mirrordir'));
this.patchdir = this.workdir.get_child('patches');
if (!this.mirrordir.query_exists(cancellable))
throw new Error("Need mirrordir: "+ this.mirrordir.get_path());
- this.prefix = args.prefix || this.config.getPrefix();
+
+ this._initFromArgs(args.prefix);
this._snapshotDir = this.workdir.get_child('snapshots');
this._srcDb = new JsonDB.JsonDB(this._snapshotDir, this.prefix + '-src-snapshot');
@@ -160,12 +156,3 @@ const Checkout = new Lang.Class({
}
}
});
-
-function main(argv) {
- let ecode = 1;
- var checkout = new Checkout();
- GLib.idle_add(GLib.PRIORITY_DEFAULT,
- function() { try { checkout.execute(argv); ecode = 0; } finally { loop.quit(); }; return false; });
- loop.run();
- return ecode;
-}
diff --git a/src/ostbuild/js/main.js b/src/ostbuild/js/main.js
index 226a60a..c0733b8 100755
--- a/src/ostbuild/js/main.js
+++ b/src/ostbuild/js/main.js
@@ -17,23 +17,37 @@
const Format = imports.format;
-const 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",
- 'build': "Build multiple components and generate trees",
- 'shell': "Interactive JavaScript shell",
- 'qa-make-disk': "Generate a bare disk image",
- 'qa-build-disks': "Build disks",
- 'qa-pull-deploy': "Copy OSTree repo into virtual disk and deploy it",
- 'qa-smoketest': "Basic smoke testing via parsing serial console"};
+const BUILTINS = ['autobuilder',
+ 'checkout'
+ 'prefix',
+ 'git-mirror',
+ 'resolve',
+ 'build',
+ 'shell',
+ 'qa-make-disk',
+ 'qa-build-disks',
+ 'qa-pull-deploy',
+ 'qa-smoketest'];
+
+function getModule(unixName) {
+ return imports.builtins[unixName.replace(/-/g, '_')];
+}
+
+function getClass(unixName) {
+ let module = getModule(unixName);
+ let camelParts = unixName.split(/-/);
+ let camel = camelParts.map(function (part) {
+ return part[0].toLocaleUpperCase() + part.substr(1);
+ }).join('');
+ return module[camel];
+}
function usage(ecode) {
print("Builtins:");
- for (let builtin in BUILTINS) {
- let description = BUILTINS[builtin];
- print(Format.vprintf(" %s - %s", [builtin, description]));
+ for (let i = 0; i < BUILTINS.length; i++) {
+ let unixName = BUILTINS[i];
+ let description = getClass(unixName).DESCRIPTION;
+ print(Format.vprintf(" %s - %s", [unixName, description]));
}
return ecode;
}
@@ -49,7 +63,22 @@ if (ARGV.length < 1) {
}
let args = ARGV.concat();
args.shift();
- imports.builtins[name.replace(/-/g, '_')].main(args);
+
+ let ecode = 1;
+ let loop = GLib.MainLoop.new(null, true);
+ let instance = new getClass(name);
+ let cancellable = null;
+ GLib.idle_add(GLib.PRIORITY_DEFAULT,
+ function() {
+ try {
+ instance.execute(args, loop, cancellable); ecode = 0;
+ } finally {
+ loop.quit();
+ }
+ return false;
+ });
+ loop.run();
+ return ecode;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]