[gnome-continuous] snapshot: Add a simple helper utility to load a snapshot from a file



commit b24943409e08f1d20ad843ed7b295c9252119b56
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Sep 30 15:07:35 2013 -0400

    snapshot: Add a simple helper utility to load a snapshot from a file

 src/js/builtin.js             |    3 +--
 src/js/builtins/git_mirror.js |    3 +--
 src/js/snapshot.js            |    6 ++++++
 src/js/tasks/task-resolve.js  |    3 +--
 4 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/src/js/builtin.js b/src/js/builtin.js
index 562bcf8..d8e52fc 100644
--- a/src/js/builtin.js
+++ b/src/js/builtin.js
@@ -57,8 +57,7 @@ const Builtin = new Lang.Class({
     _initSnapshot: function(workdir, snapshotPath, cancellable) {
        this._initWorkdir(workdir, cancellable);
        let path = Gio.File.new_for_path(snapshotPath);
-       let data = JsonUtil.loadJson(path, cancellable);
-       this._snapshot = new Snapshot.Snapshot(data, path);
+       this._snapshot = Snapshot.fromFile(path, cancellable);
     },
 
     main: function(argv, loop, cancellable) {
diff --git a/src/js/builtins/git_mirror.js b/src/js/builtins/git_mirror.js
index 11e96bc..e830eab 100644
--- a/src/js/builtins/git_mirror.js
+++ b/src/js/builtins/git_mirror.js
@@ -50,8 +50,7 @@ const GitMirror = new Lang.Class({
 
         if (args.manifest != null) {
            let manifestPath = Gio.File.new_for_path(args.manifest)
-            let manifestData = JsonUtil.loadJson(manifestPath, cancellable);
-           this._snapshot = new Snapshot.Snapshot(manifestData, manifestPath, { prepareResolve: true });
+            this._snapshot = Snapshot.fromFile(manifestPath, cancellable, { prepareResolve: true });
         } else {
            this._initSnapshot(null, args.snapshot, cancellable);
        }
diff --git a/src/js/snapshot.js b/src/js/snapshot.js
index 281ee6e..c8b1a72 100644
--- a/src/js/snapshot.js
+++ b/src/js/snapshot.js
@@ -18,6 +18,7 @@
 
 const Lang = imports.lang;
 
+const JsonUtil = imports.jsonutil;
 const Params = imports.params;
 
 function _componentDict(snapshot) {
@@ -65,6 +66,11 @@ function snapshotDiff(a, b) {
     return [added, modified, removed];
 }
 
+function fromFile(path, cancellable, args) {
+    let data = JsonUtil.loadJson(path, cancellable);
+    return new Snapshot(data, path, args);
+}
+
 const Snapshot = new Lang.Class({
     Name: 'Snapshot',
     
diff --git a/src/js/tasks/task-resolve.js b/src/js/tasks/task-resolve.js
index 94d334c..f90f620 100644
--- a/src/js/tasks/task-resolve.js
+++ b/src/js/tasks/task-resolve.js
@@ -48,8 +48,7 @@ const TaskResolve = new Lang.Class({
 
     execute: function(cancellable) {
         let manifestPath = this.workdir.get_child('manifest.json');
-       let data = JsonUtil.loadJson(manifestPath, cancellable);
-        this._snapshot = new Snapshot.Snapshot(data, manifestPath, { prepareResolve: true });
+        this._snapshot = Snapshot.fromFile(manifestPath, cancellable, { prepareResolve: true });
 
         let componentsToFetch = this.parameters.fetchComponents.slice();
         let srcUrls = this.parameters.fetchSrcUrls;


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