[augeas-devel] [PATCH] Split multiple baseurl's in a yum file into multiple baseurl nodes

David Lutterkort dlutter at redhat.com
Fri Apr 25 04:11:08 UTC 2008


# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1209096646 25200
# Node ID 835397197ea7242f9932e414304a207aebf64c8d
# Parent  0f201c77bec5a6faaa229f0eed59f3ed39877ca5
Split multiple baseurl's in a yum file into multiple baseurl nodes

With this, the schema for yum config files may now contain nodes like
  { "section"
     ... other key/value pairs ...
     { "baseurl" = "url1" }
     { "baseurl" = "url2" }
     ...
     { "baseurl" = "urlN" }
     ... other key/value pairs ...
  }

Note that the baseurl nodes have to be consecutive; otherwise, put will
fail.

diff -r 0f201c77bec5 -r 835397197ea7 lenses/tests/test_yum.aug
--- a/lenses/tests/test_yum.aug	Thu Apr 24 21:00:19 2008 -0700
+++ b/lenses/tests/test_yum.aug	Thu Apr 24 21:10:46 2008 -0700
@@ -26,7 +26,7 @@ installonly_limit=100
 # in /etc/yum.repos.d
 "
 
-  let cont = "[main]\nbaseurl=url1\n   url2\n"
+  let cont = "[main]\nbaseurl=url1\n   url2 , url3\n   \n"
 
   test Yum.lns get yum_simple =
     { "sec1" {} { "key" = "value" } }
@@ -57,7 +57,23 @@ installonly_limit=100
    = "[sec-two]\nkey1=newvalue\n# comment\nkey2=value2\n"
 
   test Yum.lns get cont =
-    { "main" { "baseurl" = "url1\n   url2" } }
+    { "main"
+        { "baseurl" = "url1" }
+        { "baseurl" = "url2" }
+        { "baseurl" = "url3" }
+        {}
+    }
+
+  test Yum.lns put cont after
+      set "main/gpgcheck" "1"
+  =
+    cont . "gpgcheck=1\n"
+
+  (* We are actually stricter than yum in checking syntax. The yum.conf *)
+  (* man page mentions that it is illegal to have multiple baseurl keys *)
+  (* in the same section, but yum will just carry on, usually with      *)
+  (* results that surpise the unsuspecting user                         *)
+  test Yum.lns get "[repo]\nbaseurl=url1\nbaseurl=url2\n" = *
 
 (* Local Variables: *)
 (* mode: caml       *)
diff -r 0f201c77bec5 -r 835397197ea7 lenses/yum.aug
--- a/lenses/yum.aug	Thu Apr 24 21:00:19 2008 -0700
+++ b/lenses/yum.aug	Thu Apr 24 21:10:46 2008 -0700
@@ -4,19 +4,28 @@ module Yum =
 
   let eol = Util.del_str "\n"
 
-  let key_re = /([^#;:= \t\n[\/])+/
+  (* Very painful: the regular expression is /[^#;:= \t\n[\/]/ - "baseurl" *)
+  (* Clearly, we need support for forming the setminus of regular          *)
+  (* languages.                                                            *)
+  let key_re = /([^b#;:= \t\n[\/]|b[^a#;:= \t\n[\/]|ba[^s#;:= \t\n[\/]|bas[^e#;:= \t\n[\/]|base[^u#;:= \t\n[\/]|baseu[^r#;:= \t\n[\/]|baseur[^l#;:= \t\n[\/]|baseurl[^#;:= \t\n[\/])[^#;:= \t\n[\/]*/
+
   let eq = del /[ \t]*[:=][ \t]*/ "="
   let secname = /[^]\/]+/
-  (* This sucks continuation lines into one big value. We should really      *)
-  (* split those into an array; that would require though that we sometimes  *)
-  (* make values a single entry, and at other times an array                 *)
-  let value = /[^ \t][^\n]*(\n[ \t]+[^ \t\n]+)*/
+
+  let value = /[^ \t\n][^\n]*/
 
   (* We really need to allow comments starting with REM and rem but that     *)
   (* leads to ambiguities with keys 'rem=' and 'REM=' The regular expression *)
   (* to do that cleanly is somewhat annoying to craft by hand; we'd need to  *)
   (* define KEY_RE as /[A-Za-z0-9]+/ - "REM" - "rem"                         *)
-  let comment = [ del /([;#].*)?[ \t]*\n/ "# \n" ]
+  let comment = [ del /([;#].*)?[ \t]*\n/ "\n" ]
+
+  let list_sep = del /[ \t]*(,[ \t]*|\n[ \t]+)/ "\n\t"
+  let list_value = store /[^ \t\n,]+/
+
+  let kv_list(s:string) =
+    [ key s . eq . list_value ] .
+      [ list_sep . label s . list_value ]* . eol
 
   let kv = [ key key_re . eq . store value . eol ]
 
@@ -24,7 +33,15 @@ module Yum =
       . del /[ \t]*[;#]?.*/ ""
       . eol
 
-  let section = [ sechead . ( comment | kv ) * ]
+  let entry = comment | kv
+
+  (* A section is a section head, followed by any number of key value    *)
+  (* entries, with comments and blank lines freely interspersed. The     *)
+  (* continuation lines allowed for baseurl entries make this a little   *)
+  (* more interesting: there can be at most one baseurl entry in each    *)
+  (* section (more precisely, yum will only obey one of them, but we act *)
+  (* as if yum would actually barf; such is life with yum)               *)
+  let section = [ sechead . (entry* | entry* . (kv_list "baseurl") . entry*)]
 
   let lns = (comment) * . (section) *
 




More information about the augeas-devel mailing list