[virt-tools-list] [libosinfo PATCHv2 6/9] loader: Read media language information

Christophe Fergeau cfergeau at redhat.com
Tue Dec 11 20:17:08 UTC 2012


Getting language information can either be supplied through a
series of <l10n-language> tag set on the <media> element or through
a regex that will be applied on the media volume ID.
The former should be all that is needed for most Linux distros while
the latter will be useful to get the language of Windows images.
---
 data/schemas/libosinfo.rng | 21 +++++++++++++++++++++
 osinfo/libosinfo.syms      |  2 ++
 osinfo/osinfo_loader.c     | 33 +++++++++++++++++++++++++++++----
 osinfo/osinfo_media.h      |  3 +++
 4 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
index 4094710..796d5f2 100644
--- a/data/schemas/libosinfo.rng
+++ b/data/schemas/libosinfo.rng
@@ -281,6 +281,9 @@
             <text/>
           </element>
         </optional>
+        <zeroOrMore>
+          <ref name='media-lang'/>
+        </zeroOrMore>
       </interleave>
     </element>
   </define>
@@ -328,6 +331,24 @@
     </element>
   </define>
 
+  <define name='media-lang'>
+    <element name='l10n-language'>
+      <optional>
+        <attribute name="type">
+          <choice>
+            <value>regex</value>
+          </choice>
+        </attribute>
+      </optional>
+      <optional>
+        <attribute name="l10n-language-map">
+          <ref name='url'/>
+        </attribute>
+      </optional>
+      <text/>
+    </element>
+  </define>
+
   <define name='treeinfo'>
     <element name='treeinfo'>
       <interleave>
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 8d1e27a..f1432db 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -396,6 +396,8 @@ LIBOSINFO_0.2.3 {
 	osinfo_install_config_paramlist_new;
 
 	osinfo_install_script_get_config_params;
+
+	osinfo_media_get_languages;
 } LIBOSINFO_0.2.2;
 
 /* Symbols in next release...
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 25385a0..f5df4b9 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -857,12 +857,37 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
              strcmp((const gchar *)nodes[i]->name,
                     OSINFO_MEDIA_PROP_PUBLISHER_ID) != 0 &&
              strcmp((const gchar *)nodes[i]->name,
-                    OSINFO_MEDIA_PROP_APPLICATION_ID) != 0))
+                    OSINFO_MEDIA_PROP_APPLICATION_ID) != 0 &&
+             strcmp((const gchar *)nodes[i]->name,
+                    OSINFO_MEDIA_PROP_LANG) != 0))
             continue;
 
-        osinfo_entity_set_param(OSINFO_ENTITY(media),
-                                (const gchar *)nodes[i]->name,
-                                (const gchar *)nodes[i]->children->content);
+        if (strcmp((const gchar *)nodes[i]->name,
+                   OSINFO_MEDIA_PROP_LANG) == 0) {
+            gchar *type = (gchar *)xmlGetProp(nodes[i], BAD_CAST "type");
+            gboolean is_regex;
+            is_regex = (g_strcmp0(type, "regex") == 0);
+            xmlFree(type);
+            if (is_regex) {
+                gchar *datamap;
+                osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                        OSINFO_MEDIA_PROP_LANG_REGEX,
+                                        (const gchar *)nodes[i]->children->content);
+                datamap = (gchar *)xmlGetProp(nodes[i], BAD_CAST OSINFO_MEDIA_PROP_LANG_MAP);
+                if (datamap != NULL)
+                    osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                            OSINFO_MEDIA_PROP_LANG_MAP,
+                                            datamap);
+            } else {
+                osinfo_entity_add_param(OSINFO_ENTITY(media),
+                                        OSINFO_MEDIA_PROP_LANG,
+                                        (const gchar *)nodes[i]->children->content);
+            }
+        } else {
+            osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                    (const gchar *)nodes[i]->name,
+                                    (const gchar *)nodes[i]->children->content);
+        }
     }
 
     g_free(nodes);
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index 274e11c..11af3e8 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -81,6 +81,9 @@ typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
 #define OSINFO_MEDIA_PROP_LIVE           "live"
 #define OSINFO_MEDIA_PROP_INSTALLER      "installer"
 #define OSINFO_MEDIA_PROP_INSTALLER_REBOOTS "installer-reboots"
+#define OSINFO_MEDIA_PROP_LANG           "l10n-language"
+#define OSINFO_MEDIA_PROP_LANG_REGEX     "l10n-language-regex"
+#define OSINFO_MEDIA_PROP_LANG_MAP       "l10n-language-map"
 
 /* object */
 struct _OsinfoMedia
-- 
1.8.0.1




More information about the virt-tools-list mailing list