[gnome-boxes/wip/generic-gnome-cont: 1/4] installed-media: Refactor constructor a bit



commit 1d52b271c1f03cf090190dddbb1d9b41df69386c
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Sep 27 07:01:19 2013 +0300

    installed-media: Refactor constructor a bit
    
    Put OS guessing/detection from filename into a separate method.

 src/installed-media.vala |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/src/installed-media.vala b/src/installed-media.vala
index aeb209d..81fadd1 100644
--- a/src/installed-media.vala
+++ b/src/installed-media.vala
@@ -50,16 +50,7 @@ private class Boxes.InstalledMedia : Boxes.InstallerMedia {
         device_file = path;
         from_image = true;
 
-        if (path.contains ("gnome-continuous") || path.contains ("gnome-ostree")) {
-            try {
-                os = yield media_manager.os_db.get_os_by_id ("http://gnome.org/continuous/3.10";);
-            } catch (OSDatabaseError.UNKNOWN_OS_ID error) {
-                debug ("gnome-continuous definition not found in libosinfo db");
-            } catch (OSDatabaseError error) {
-                throw error;
-            }
-        }
-
+        os = yield guess_os_from_filename (media_manager.os_db);
         resources = (os != null)? media_manager.os_db.get_resources_for_os (os, architecture) :
                                   OSDatabase.get_default_resources ();
 
@@ -102,6 +93,21 @@ private class Boxes.InstalledMedia : Boxes.InstallerMedia {
         return new VMImporter (this);
     }
 
+    private async Osinfo.Os? guess_os_from_filename (OSDatabase os_db) throws OSDatabaseError {
+        if (!device_file.contains ("gnome-continuous") && !device_file.contains ("gnome-ostree"))
+            return null;
+
+        try {
+            return yield os_db.get_os_by_id ("http://gnome.org/continuous/3.10";);
+        } catch (OSDatabaseError.UNKNOWN_OS_ID error) {
+            debug ("gnome-continuous definition not found in libosinfo db");
+
+            return null;
+        } catch (OSDatabaseError error) {
+            throw error;
+        }
+    }
+
     private async bool decompress () throws GLib.Error {
         if (!device_file.has_suffix (".gz"))
             return false;


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