[gnome-ostree/wip/gjs-round2] Port "prefix" command to gjs



commit 1bfa3c7727c5f333482824da6e375b6f177fcb40
Author: Colin Walters <walters verbum org>
Date:   Sat Dec 8 14:10:43 2012 -0500

    Port "prefix" command to gjs
    
    Doing the smaller ones first.

 Makefile-ostbuild.am                      |    2 +-
 src/ostbuild/js/argparse.js               |    4 +-
 src/ostbuild/js/checkout.js               |    2 +-
 src/ostbuild/js/prefix.js                 |   56 ++++++++++++++++++++++
 src/ostbuild/pyostbuild/builtin_prefix.py |   73 -----------------------------
 src/ostbuild/pyostbuild/main.py           |    6 +-
 6 files changed, 63 insertions(+), 80 deletions(-)
---
diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am
index 3ee047c..6a41458 100644
--- a/Makefile-ostbuild.am
+++ b/Makefile-ostbuild.am
@@ -50,7 +50,6 @@ pyostbuild_PYTHON =					\
 	src/ostbuild/pyostbuild/builtin_import_tree.py	\
 	src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py	\
 	src/ostbuild/pyostbuild/builtin_git_mirror.py	\
-	src/ostbuild/pyostbuild/builtin_prefix.py	\
 	src/ostbuild/pyostbuild/builtin_resolve.py	\
 	src/ostbuild/pyostbuild/builtin_source_diff.py	\
 	src/ostbuild/pyostbuild/builtins.py		\
@@ -82,6 +81,7 @@ jsostbuild_DATA= \
 	src/ostbuild/js/jsondb.js \
 	src/ostbuild/js/jsonutil.js \
 	src/ostbuild/js/params.js \
+	src/ostbuild/js/prefix.js \
 	src/ostbuild/js/procutil.js \
 	src/ostbuild/js/snapshot.js \
 	src/ostbuild/js/task.js \
diff --git a/src/ostbuild/js/argparse.js b/src/ostbuild/js/argparse.js
index 92ef802..c6e6ef1 100644
--- a/src/ostbuild/js/argparse.js
+++ b/src/ostbuild/js/argparse.js
@@ -16,7 +16,7 @@ const ArgumentParser = new Lang.Class({
 	let buf = 'Usage: ' + this.description + '\n';
 	for (let i = 0; i < this._opts.length; i++) {
 	    let opt = this._opts[i];
-	    let names = this._opts._names;
+	    let names = opt._names;
 	    for (let j = 0; j < names.length; j++) {
 		let name = names[j];
 		buf += name;
@@ -29,7 +29,7 @@ const ArgumentParser = new Lang.Class({
 	}
 	for (let i = 0; i < this._namedArgs.length; i++) {
 	    let arg = this._namedArgs[i];
-	    buf += arg + "\n";
+	    buf += arg._varName + "\n";
 	}
 	return buf;
     },
diff --git a/src/ostbuild/js/checkout.js b/src/ostbuild/js/checkout.js
index e24072b..e192f8d 100644
--- a/src/ostbuild/js/checkout.js
+++ b/src/ostbuild/js/checkout.js
@@ -17,7 +17,7 @@ const BuildUtil = imports.buildutil;
 const Vcs = imports.vcs;
 const ArgParse = imports.argparse;
 
-const loop = GLib.MainLoop.new(null, true);
+var loop = GLib.MainLoop.new(null, true);
 
 const Checkout = new Lang.Class({
     Name: 'Checkout',
diff --git a/src/ostbuild/js/prefix.js b/src/ostbuild/js/prefix.js
new file mode 100644
index 0000000..e4eaf7f
--- /dev/null
+++ b/src/ostbuild/js/prefix.js
@@ -0,0 +1,56 @@
+// Copyright (C) 2011,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 Config = imports.config;
+const ArgParse = imports.argparse;
+
+var loop = GLib.MainLoop.new(null, true);
+
+const Prefix = new Lang.Class({
+    Name: 'Prefix',
+
+    _init: function() {
+    },
+
+    execute: function(argv) {
+	let cancellable = null;
+        let parser = new ArgParse.ArgumentParser("Display or modify \"prefix\" (build target)");
+        parser.addArgument(['-a', '--active'], {action: 'storeTrue'});
+        parser.addArgument('prefix');
+
+        let args = parser.parse(argv);
+
+	let filepath = GLib.build_filenamev([GLib.get_user_config_dir(), "ostbuild-prefix"]);
+        this.path = Gio.File.new_for_path(filepath);
+        this._setPrefix(args.prefix, cancellable);
+    },
+
+    _setPrefix: function(prefix, cancellable) {
+	this.path.replace_contents(prefix, null, false, 0, cancellable);
+        print("Prefix is now " + prefix);
+    },
+});
+
+var prefix = new Prefix();
+GLib.idle_add(GLib.PRIORITY_DEFAULT,
+	      function() { try { prefix.execute(ARGV); } finally { loop.quit(); }; return false; });
+loop.run();
diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py
index 0c7939c..4c65fe1 100755
--- a/src/ostbuild/pyostbuild/main.py
+++ b/src/ostbuild/pyostbuild/main.py
@@ -27,13 +27,13 @@ from . import builtin_deploy_root
 from . import builtin_deploy_qemu
 from . import builtin_git_mirror
 from . import builtin_import_tree
-from . import builtin_prefix
 from . import builtin_privhelper_deploy_qemu
 from . import builtin_resolve
 from . import builtin_source_diff
 
-JS_BUILTINS = {'autobuilder': 'Run resolve and build',
-               'checkout': 'Check out source tree'}
+JS_BUILTINS = {'autobuilder': "Run resolve and build",
+               'checkout': "Check out source tree",
+               'prefix': "Display or modify \"prefix\" (build target)"};
 
 def usage(ecode):
     print "Builtins:"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]