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

[virt-tools-list] [libosinfo] Media ID strings are now regular expressions



From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>

---
 data/oses/fedora.xml  |   16 ++++++++--------
 data/oses/rhel.xml    |   28 ++++++++++++++--------------
 data/oses/windows.xml |    8 ++++----
 osinfo/osinfo_db.c    |   11 +++++------
 osinfo/osinfo_media.c |   15 +++++++++------
 5 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/data/oses/fedora.xml b/data/oses/fedora.xml
index 116151f..e822eff 100644
--- a/data/oses/fedora.xml
+++ b/data/oses/fedora.xml
@@ -89,14 +89,14 @@
     <media arch="i386">
       <url>http://download.fedoraproject.org/pub/fedora/linux/releases/12/Fedora/i386/os/</url>
       <iso>
-        <volume-id>Fedora 12 i386</volume-id>
+        <volume-id>.*Fedora 12 i386.*</volume-id>
         <system-id>LINUX</system-id>
       </iso>
     </media>
     <media arch="x86_64">
       <url>http://download.fedoraproject.org/pub/fedora/linux/releases/12/Fedora/x86_64/os/</url>
       <iso>
-        <volume-id>Fedora 12 x86_64</volume-id>
+        <volume-id>.*Fedora 12 x86_64.*</volume-id>
         <system-id>LINUX</system-id>
       </iso>
     </media>
@@ -113,14 +113,14 @@
     <media arch="i386">
       <url>http://download.fedoraproject.org/pub/fedora/linux/releases/13/Fedora/i386/os/</url>
       <iso>
-        <volume-id>Fedora 13 i386</volume-id>
+        <volume-id>.*Fedora 13 i386.*</volume-id>
         <system-id>LINUX</system-id>
       </iso>
     </media>
     <media arch="x86_64">
       <url>http://download.fedoraproject.org/pub/fedora/linux/releases/13/Fedora/x86_64/os/</url>
       <iso>
-        <volume-id>Fedora 13 x86_64</volume-id>
+        <volume-id>.*Fedora 13 x86_64.*</volume-id>
         <system-id>LINUX</system-id>
       </iso>
     </media>
@@ -137,14 +137,14 @@
     <media arch="i386">
       <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/i386/os/</url>
       <iso>
-        <volume-id>Fedora 14 i386</volume-id>
+        <volume-id>.*Fedora 14 i386.*</volume-id>
         <system-id>LINUX</system-id>
       </iso>
     </media>
     <media arch="x86_64">
       <url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora/x86_64/os/</url>
       <iso>
-        <volume-id>Fedora 14 x86_64</volume-id>
+        <volume-id>.*Fedora 14 x86_64.*</volume-id>
         <system-id>LINUX</system-id>
       </iso>
     </media>
@@ -161,14 +161,14 @@
     <media arch="i386">
       <url>http://download.fedoraproject.org/pub/fedora/linux/releases/15/Fedora/i386/os/</url>
       <iso>
-        <volume-id>Fedora 15 i386</volume-id>
+        <volume-id>.*Fedora 15 i386.*</volume-id>
         <system-id>LINUX</system-id>
       </iso>
     </media>
     <media arch="x86_64">
       <url>http://download.fedoraproject.org/pub/fedora/linux/releases/15/Fedora/x86_64/os/</url>
       <iso>
-        <volume-id>Fedora 15 x86_64</volume-id>
+        <volume-id>.*Fedora 15 x86_64.*</volume-id>
         <system-id>LINUX</system-id>
       </iso>
     </media>
diff --git a/data/oses/rhel.xml b/data/oses/rhel.xml
index 8a3f834..6ad634d 100644
--- a/data/oses/rhel.xml
+++ b/data/oses/rhel.xml
@@ -26,13 +26,13 @@
     <media arch="i386">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_4.8 i386</volume-id>
+        <volume-id>.*RHEL_4.8 i386.*</volume-id>
       </iso>
     </media>
     <media arch="x86_64">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_4.8 x86_64</volume-id>
+        <volume-id>.*RHEL_4.8 x86_64.*</volume-id>
       </iso>
     </media>
   </os>
@@ -48,13 +48,13 @@
     <media arch="i386">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_4.9 i386</volume-id>
+        <volume-id>.*RHEL_4.9 i386.*</volume-id>
       </iso>
     </media>
     <media arch="x86_64">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_4.9 x86_64</volume-id>
+        <volume-id>.*RHEL_4.9 x86_64.*</volume-id>
       </iso>
     </media>
   </os>
@@ -69,13 +69,13 @@
     <media arch="i386">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_5.4 i386</volume-id>
+        <volume-id>.*RHEL_5.4 i386.*</volume-id>
       </iso>
     </media>
     <media arch="x86_64">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_5.4 x86_64</volume-id>
+        <volume-id>.*RHEL_5.4 x86_64.*</volume-id>
       </iso>
     </media>
   </os>
@@ -95,13 +95,13 @@
     <media arch="i386">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_5.6 i386</volume-id>
+        <volume-id>.*RHEL_5.6 i386.*</volume-id>
       </iso>
     </media>
     <media arch="x86_64">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_5.6 x86_64</volume-id>
+        <volume-id>.*RHEL_5.6 x86_64.*</volume-id>
       </iso>
     </media>
   </os>
@@ -117,13 +117,13 @@
     <media arch="i386">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_5.7 i386</volume-id>
+        <volume-id>.*RHEL_5.7 i386.*</volume-id>
       </iso>
     </media>
     <media arch="x86_64">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_5.7 x86_64</volume-id>
+        <volume-id>.*RHEL_5.7 x86_64.*</volume-id>
       </iso>
     </media>
   </os>
@@ -144,13 +144,13 @@
     <media arch="i386">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_6.0 i386</volume-id>
+        <volume-id>.*RHEL_6.0 i386.*</volume-id>
       </iso>
     </media>
     <media arch="x86_64">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_6.0 x86_64</volume-id>
+        <volume-id>.*RHEL_6.0 x86_64.*</volume-id>
       </iso>
     </media>
   </os>
@@ -166,13 +166,13 @@
     <media arch="i386">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_6.1 i386</volume-id>
+        <volume-id>.*RHEL_6.1 i386.*</volume-id>
       </iso>
     </media>
     <media arch="x86_64">
       <iso>
         <system-id>LINUX</system-id>
-        <volume-id>RHEL_6.1 x86_64</volume-id>
+        <volume-id>.*RHEL_6.1 x86_64.*</volume-id>
       </iso>
     </media>
   </os>
diff --git a/data/oses/windows.xml b/data/oses/windows.xml
index 6d7e9ab..944ed20 100644
--- a/data/oses/windows.xml
+++ b/data/oses/windows.xml
@@ -71,7 +71,7 @@
 
     <media arch="i386">
       <iso>
-        <volume-id>CRMS</volume-id>
+        <volume-id>.*CRMS.*</volume-id>
         <publisher-id>MICROSOFT CORPORATION</publisher-id>
       </iso>
     </media>
@@ -116,7 +116,7 @@
 
     <media arch="x86_64">
       <iso>
-        <volume-id>GRMSX</volume-id>
+        <volume-id>.*GRMSX.*</volume-id>
         <publisher-id>MICROSOFT CORPORATION</publisher-id>
       </iso>
     </media>
@@ -191,13 +191,13 @@
 
     <media arch="i386">
       <iso>
-        <volume-id>GSP1RMCEN</volume-id>
+        <volume-id>.*GSP1RMC.*</volume-id>
         <publisher-id>MICROSOFT CORPORATION</publisher-id>
       </iso>
     </media>
     <media arch="x86_64">
       <iso>
-        <volume-id>GSP1RMCENX</volume-id>
+        <volume-id>.*GSP1RMC.*X.*</volume-id>
         <publisher-id>MICROSOFT CORPORATION</publisher-id>
       </iso>
     </media>
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index a766a3c..0cf8584 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -30,9 +30,8 @@ G_DEFINE_TYPE (OsinfoDb, osinfo_db, G_TYPE_OBJECT);
 
 #define OSINFO_DB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_DB, OsinfoDbPrivate))
 
-#define str_contains(str, substr) ((str) && \
-                                   (substr) && \
-                                   strstr((str), (substr)) != NULL)
+#define match_regex(pattern, str) ((pattern) && (str) && \
+                                   g_regex_match_simple((pattern), (str), 0, 0))
 
 /**
  * SECTION:osinfo_db
@@ -359,9 +358,9 @@ OsinfoOs *osinfo_db_guess_os_from_media(OsinfoDb *db, OsinfoMedia *media)
             const gchar *os_system = osinfo_media_get_system_id(os_media);
             const gchar *os_publisher = osinfo_media_get_publisher_id(os_media);
 
-            if (str_contains(media_volume, os_volume) &&
-                (str_contains(media_system, os_system) ||
-                 str_contains(media_publisher, os_publisher))) {
+            if (match_regex (os_volume, media_volume) &&
+                (match_regex (os_system, media_system) ||
+                 match_regex (os_publisher, media_publisher))) {
                 ret = os;
                 break;
             }
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 96aef89..641c351 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -495,8 +495,9 @@ const gchar *osinfo_media_get_url(OsinfoMedia *media)
  * If @media is an ISO9660 image/device, this function retrieves the expected
  * volume ID.
  *
- * Note: In practice, this will usually not be an exact match to the volume ID
- * on the ISO image/device but rather a substring of it.
+ * Note: In practice, this will usually not be the exact copy of the volume ID
+ * string on the ISO image/device but rather a regular expression that matches
+ * it.
  *
  * Returns: (transfer none): the volume id, or NULL
  */
@@ -513,8 +514,9 @@ const gchar *osinfo_media_get_volume_id(OsinfoMedia *media)
  * If @media is an ISO9660 image/device, this function retrieves the expected
  * system ID.
  *
- * Note: In practice, this will usually not be an exact match to the system ID
- * on the ISO image/device but rather a substring of it.
+ * Note: In practice, this will usually not be the exact copy of the system ID
+ * string on the ISO image/device but rather a regular expression that matches
+ * it.
  *
  * Returns: (transfer none): the system id, or NULL
  */
@@ -531,8 +533,9 @@ const gchar *osinfo_media_get_system_id(OsinfoMedia *media)
  * If @media is an ISO9660 image/device, this function retrieves the expected
  * publisher ID.
  *
- * Note: In practice, this will usually not be an exact match to the system ID
- * on the ISO image/device but rather a substring of it.
+ * Note: In practice, this will usually not be the exact copy of the publisher
+ * ID string on the ISO image/device but rather a regular expression that
+ * matches it.
  *
  * Returns: (transfer none): the publisher id, or NULL
  */
-- 
1.7.6


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