[gnome-ostree/wip/libostree: 4/4] Use libostree to start doing simple operations



commit 35532bfd94493b7d5e9b0c7331fb767325ea2598
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Sep 1 11:32:33 2013 -0400

    Use libostree to start doing simple operations
    
    Instead of forking out to a subprocess.

 src/js/task.js             |    2 ++
 src/js/tasks/task-build.js |   28 +++++++++++-----------------
 src/js/tasks/testbase.js   |    6 +-----
 3 files changed, 14 insertions(+), 22 deletions(-)
---
diff --git a/src/js/task.js b/src/js/task.js
index 158d0b9..b1745cd 100644
--- a/src/js/task.js
+++ b/src/js/task.js
@@ -22,6 +22,7 @@ const Lang = imports.lang;
 const Signals = imports.signals;
 
 const GSystem = imports.gi.GSystem;
+const OSTree = imports.gi.OSTree;
 const Params = imports.params;
 const JsonUtil = imports.jsonutil;
 const JsonDB = imports.jsondb;
@@ -331,6 +332,7 @@ const Task = new Lang.Class({
 
        this.libdir = Gio.File.new_for_path(GLib.getenv('OSTBUILD_LIBDIR'));
        this.repo = this.workdir.get_child('repo');
+        this.ostreeRepo = new OSTree.Repo({ path: this.repo });
     },
 
     _getResultDb: function(taskname) {
diff --git a/src/js/tasks/task-build.js b/src/js/tasks/task-build.js
index 77e3cdc..74e2e1e 100644
--- a/src/js/tasks/task-build.js
+++ b/src/js/tasks/task-build.js
@@ -54,11 +54,10 @@ const TaskBuild = new Lang.Class({
     DefaultParameters: {forceComponents: []},
 
     _resolveRefs: function(refs) {
-        if (refs.length == 0)
-            return [];
-        let args = ['ostree', '--repo=' + this.repo.get_path(), 'rev-parse']
-        args.push.apply(args, refs);
-        return ProcUtil.runSyncGetOutputLines(args, null);
+        return refs.map(Lang.bind(this, function(ref) {
+            let [success, resolved] = this.ostreeRepo.resolve_rev(ref, false);
+            return resolved;
+        }));
     },
 
     _cleanStaleBuildroots: function(buildrootCachedir, keepRoot, cancellable) {
@@ -175,8 +174,7 @@ const TaskBuild = new Lang.Class({
 
         print("Computing buildroot contents");
 
-        let archBuildrootRev = ProcUtil.runSyncGetOutputUTF8Stripped(['ostree', '--repo=' + 
this.repo.get_path(), 'rev-parse',
-                                                                     archBuildrootName], cancellable);
+        let [success, archBuildrootRev] = this.ostreeRepo.resolve_rev(archBuildrootName, false);
 
         let rootContents = [[archBuildrootName, '/']];
         for (let i = 0; i < buildDependencies.length; i++) {
@@ -296,10 +294,10 @@ const TaskBuild = new Lang.Class({
     _saveComponentBuild: function(buildRef, expandedComponent, cancellable) {
        let cachedata = {};
        Lang.copyProperties(expandedComponent, cachedata);
-        cachedata['ostree'] = ProcUtil.runSyncGetOutputUTF8Stripped(['ostree', '--repo=' + 
this.repo.get_path(),
-                                                                    'rev-parse', buildRef], cancellable);
+        let [success, ref] = this.ostreeRepo.resolve_rev(buildRef, false);
+        cachedata['ostree'] = ref;
        this._writeComponentCache(buildRef, cachedata, cancellable);
-        return cachedata['ostree'];
+        return ref;
     },
 
     _installAndUnlinkRecurse: function(buildResultDir, srcFile, srcInfo, finalResultDir, cancellable) {
@@ -758,13 +756,9 @@ const TaskBuild = new Lang.Class({
         let runtimeName = this.osname +'/bases/' + base['runtime'];
         let develName = this.osname + '/bases/' + base['devel'];
 
-        let baseRevision = ProcUtil.runSyncGetOutputUTF8Stripped(['ostree', '--repo=' + this.repo.get_path(),
-                                                                 'rev-parse', baseName], cancellable);
-
-        let runtimeRevision = ProcUtil.runSyncGetOutputUTF8Stripped(['ostree', '--repo=' + 
this.repo.get_path(),
-                                                                    'rev-parse', runtimeName], cancellable);
-        let develRevision = ProcUtil.runSyncGetOutputUTF8Stripped(['ostree', '--repo=' + 
this.repo.get_path(),
-                                                                  'rev-parse', develName], cancellable);
+        let [, baseRevision] = this.ostreeRepo.resolve_rev(baseName, false);
+        let [, runtimeRevision] = this.ostreeRepo.resolve_rev(runtimeName, false);
+        let [, develRevision] = this.ostreeRepo.resolve_rev(develName, false);
 
         let composeContents = [[baseRevision, '/']];
         for (let i = 0; i < target['contents'].length; i++) {
diff --git a/src/js/tasks/testbase.js b/src/js/tasks/testbase.js
index dd27d4d..98953a1 100644
--- a/src/js/tasks/testbase.js
+++ b/src/js/tasks/testbase.js
@@ -400,17 +400,13 @@ const TestBase = new Lang.Class({
 
         let buildData = this._buildData;
         if (buildJson != null && this.CompletedTag !== null) {
-            let refData = '';
             let snapshot = buildData['snapshot'];
             for (let targetName in buildData['targets']) {
                 let targetRev = buildData['targets'][targetName];
                 let lastSlash = targetName.lastIndexOf('/');
                 let smoketestedRef = snapshot['osname'] + '/' + this.CompletedTag + 
targetName.substr(lastSlash);
-                refData += smoketestedRef + ' ' + targetRev + '\n';
+                this.ostreeRepo.write_ref(null, smoketestedRef, targetRev);
             }
-            ProcUtil.runProcWithInputSyncGetLines(['ostree', '--repo=' + this.repo.get_path(),
-                                                   'write-refs'], cancellable, refData);
-            print("Wrote refs: " + refData);
         } else {
             print("No build json found, not tagging");
         }


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