[gnome-boxes/wip/generic-gnome-cont: 4/4] installed-media: Generic mapping of image to gnome release



commit 39a9637632ed8749d2d3c4bd9e2a1fe4b511a3ed
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Oct 3 03:48:45 2013 +0300

    installed-media: Generic mapping of image to gnome release
    
    Using the date on gnome-continuous image filenames, ensure that we map
    the image to the first gnome release after the date on the image.
    Mapping for older images will still have to be hardcoded I'm afraid.

 src/installed-media.vala |   40 +++++++++++++++++++++++++++++++++-------
 1 files changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/src/installed-media.vala b/src/installed-media.vala
index 81fadd1..8ff5bef 100644
--- a/src/installed-media.vala
+++ b/src/installed-media.vala
@@ -11,6 +11,7 @@ private class Boxes.InstalledMedia : Boxes.InstallerMedia {
                                                    ".vmdk", ".vmdk.gz",
                                                    ".vpc", ".vpc.gz",
                                                    ".cloop", ".cloop.gz" };
+    private static Regex date_regex = /20[0-9]{6,6}/;
 
     public override bool need_user_input_for_vm_creation { get { return false; } }
     public override bool ready_to_create { get { return true; } }
@@ -97,15 +98,40 @@ private class Boxes.InstalledMedia : Boxes.InstallerMedia {
         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");
+        var date = get_date_from_filename ();
+        if (date == null) {
+            try {
+                // No date on filename means older gnome-continuous images and
+                // hence more close to 3.10 than anything newer.
+                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;
+                return null;
+            }
         }
+
+        var os_list = yield os_db.list_os_by_distro ("gnome", date);
+        if (os_list.length () > 0)
+            return os_list.data;
+        else
+            return null;
+    }
+
+    private GLib.Date? get_date_from_filename () {
+        GLib.MatchInfo match_info;
+
+        date_regex.match (device_file, 0, out match_info);
+        if (!match_info.matches ())
+            return null;
+
+        var date_str = match_info.fetch (0);
+        var date = GLib.Date ();
+        date.set_year ((GLib.DateYear) int.parse (date_str[0:4]));
+        date.set_month ((GLib.DateMonth) int.parse (date_str[4:6]));
+        date.set_day ((GLib.DateDay) int.parse (date_str[6:8]));
+
+        return date;
     }
 
     private async bool decompress () throws GLib.Error {


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