Blame SOURCES/0014-Yum.lns-simplify-code-for-combinatory-logic-of-list_.patch

c537d4
From 50792ee989e81b52ed886be967843d85433f0ce5 Mon Sep 17 00:00:00 2001
c537d4
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphael.pinson@camptocamp.com>
c537d4
Date: Tue, 3 Dec 2013 10:11:38 +0100
c537d4
Subject: [PATCH] Yum.lns: simplify code for combinatory logic of list_entry
c537d4
 elements
c537d4
c537d4
(cherry picked from commit 9c645afbde88a2bdb5f8b139fde44968b019234c)
c537d4
c537d4
Build: Add combinatorics group
c537d4
c537d4
(cherry picked from commit 3f57641d8df3ed1edf89cd7641c4c6e84c3a3429)
c537d4
c537d4
Yum.lns: split excludes as lists (ticket #275)
c537d4
c537d4
(cherry picked from commit c16ccfd64045cb5f9c8793bc7589fc80fc027064)
c537d4
---
c537d4
 lenses/build.aug            | 57 +++++++++++++++++++++++++++++++++++
c537d4
 lenses/tests/test_build.aug | 73 +++++++++++++++++++++++++++++++++++++++++++++
c537d4
 lenses/tests/test_yum.aug   | 11 +++++++
c537d4
 lenses/yum.aug              | 16 +++++-----
c537d4
 4 files changed, 149 insertions(+), 8 deletions(-)
c537d4
c537d4
diff --git a/lenses/build.aug b/lenses/build.aug
c537d4
index 2e57356..efc8814 100644
c537d4
--- a/lenses/build.aug
c537d4
+++ b/lenses/build.aug
c537d4
@@ -298,3 +298,60 @@ let block_newlines (entry:lens) (comment:lens) =
c537d4
  ************************************************************************)
c537d4
 let named_block (kw:regexp) (entry:lens) = [ key kw . block entry . eol ]
c537d4
 
c537d4
+
c537d4
+(************************************************************************
c537d4
+ * Group:               COMBINATORICS
c537d4
+ ************************************************************************)
c537d4
+
c537d4
+(************************************************************************
c537d4
+ * View: combine_two_opt_ord
c537d4
+ *   Combine two lenses optionally, ensuring first lens is first
c537d4
+ *   (a, and optionally b)
c537d4
+ *
c537d4
+ *   Parameters:
c537d4
+ *     a:lens - the first lens
c537d4
+ *     b:lens - the second lens
c537d4
+ ************************************************************************)
c537d4
+let combine_two_opt_ord (a:lens) (b:lens) = a . b?
c537d4
+
c537d4
+(************************************************************************
c537d4
+ * View: combine_two_opt
c537d4
+ *   Combine two lenses optionally
c537d4
+ *   (either a, b, or both, in any order)
c537d4
+ *
c537d4
+ *   Parameters:
c537d4
+ *     a:lens - the first lens
c537d4
+ *     b:lens - the second lens
c537d4
+ ************************************************************************)
c537d4
+let combine_two_opt (a:lens) (b:lens) =
c537d4
+  combine_two_opt_ord a b | combine_two_opt_ord b a
c537d4
+
c537d4
+
c537d4
+(************************************************************************
c537d4
+ * View: combine_three_opt_ord
c537d4
+ *   Combine three lenses optionally, ensuring first lens is first
c537d4
+ *   (a followed by either b, c, or any of them, in any order)
c537d4
+ *
c537d4
+ *   Parameters:
c537d4
+ *     a:lens - the first lens
c537d4
+ *     b:lens - the second lens
c537d4
+ *     c:lens - the third lens
c537d4
+ ************************************************************************)
c537d4
+let combine_three_opt_ord (a:lens) (b:lens) (c:lens) =
c537d4
+  combine_two_opt_ord a (combine_two_opt b c)
c537d4
+
c537d4
+(************************************************************************
c537d4
+ * View: combine_three_opt
c537d4
+ *   Combine three lenses optionally
c537d4
+ *   (either a, b, c, or any of them, in any order)
c537d4
+ *
c537d4
+ *   Parameters:
c537d4
+ *     a:lens - the first lens
c537d4
+ *     b:lens - the second lens
c537d4
+ *     c:lens - the third lens
c537d4
+ ************************************************************************)
c537d4
+let combine_three_opt (a:lens) (b:lens) (c:lens) =
c537d4
+    combine_three_opt_ord a b c
c537d4
+  | combine_three_opt_ord b a c
c537d4
+  | combine_three_opt_ord c b a
c537d4
+
c537d4
diff --git a/lenses/tests/test_build.aug b/lenses/tests/test_build.aug
c537d4
index b9b09fa..bc565f3 100644
c537d4
--- a/lenses/tests/test_build.aug
c537d4
+++ b/lenses/tests/test_build.aug
c537d4
@@ -174,3 +174,76 @@ test logrotate_block get "/var/log/wtmp\n/var/log/wtmp2\n{
c537d4
     { "monthly" }
c537d4
   }
c537d4
 
c537d4
+
c537d4
+(************************************************************************
c537d4
+ * Group:               COMBINATORICS
c537d4
+ ************************************************************************)
c537d4
+
c537d4
+(* View: combine_two_opt
c537d4
+    A minimalistic optional combination lens *)
c537d4
+let combine_two_opt =
c537d4
+     let entry (k:string) = [ key k ]
c537d4
+  in Build.combine_two_opt (entry "a") (entry "b")
c537d4
+
c537d4
+(* Test: combine_two_opt 
c537d4
+     Should parse ab *)
c537d4
+test combine_two_opt get "ab" = { "a" } { "b" }
c537d4
+
c537d4
+(* Test: combine_two_opt 
c537d4
+     Should parse ba *)
c537d4
+test combine_two_opt get "ba" = { "b" } { "a" }
c537d4
+
c537d4
+(* Test: combine_two_opt 
c537d4
+     Should parse a *)
c537d4
+test combine_two_opt get "a" = { "a" }
c537d4
+
c537d4
+(* Test: combine_two_opt 
c537d4
+     Should parse b *)
c537d4
+test combine_two_opt get "b" = { "b" }
c537d4
+
c537d4
+(* Test: combine_two_opt 
c537d4
+     Should not parse aa *)
c537d4
+test combine_two_opt get "aa" = *
c537d4
+
c537d4
+(* Test: combine_two_opt 
c537d4
+     Should not parse bb *)
c537d4
+test combine_two_opt get "bb" = *
c537d4
+
c537d4
+
c537d4
+(* View: combine_three_opt
c537d4
+    A minimalistic optional combination lens *)
c537d4
+let combine_three_opt =
c537d4
+     let entry (k:string) = [ key k ]
c537d4
+  in Build.combine_three_opt (entry "a") (entry "b") (entry "c")
c537d4
+
c537d4
+(* Test: combine_three_opt 
c537d4
+     Should parse ab *)
c537d4
+test combine_three_opt get "ab" = { "a" } { "b" }
c537d4
+
c537d4
+(* Test: combine_three_opt 
c537d4
+     Should parse ba *)
c537d4
+test combine_three_opt get "ba" = { "b" } { "a" }
c537d4
+
c537d4
+(* Test: combine_three_opt 
c537d4
+     Should parse a *)
c537d4
+test combine_three_opt get "a" = { "a" }
c537d4
+
c537d4
+(* Test: combine_three_opt 
c537d4
+     Should parse b *)
c537d4
+test combine_three_opt get "b" = { "b" }
c537d4
+
c537d4
+(* Test: combine_three_opt 
c537d4
+     Should not parse aa *)
c537d4
+test combine_three_opt get "aa" = *
c537d4
+
c537d4
+(* Test: combine_three_opt 
c537d4
+     Should not parse bbc *)
c537d4
+test combine_three_opt get "bbc" = *
c537d4
+
c537d4
+(* Test: combine_three_opt 
c537d4
+     Should parse abc *)
c537d4
+test combine_three_opt get "abc" = { "a" } { "b" } { "c" }
c537d4
+
c537d4
+(* Test: combine_three_opt 
c537d4
+     Should parse cab *)
c537d4
+test combine_three_opt get "cab" = { "c" } { "a" } { "b" }
c537d4
diff --git a/lenses/tests/test_yum.aug b/lenses/tests/test_yum.aug
c537d4
index 17d4ea2..2688182 100644
c537d4
--- a/lenses/tests/test_yum.aug
c537d4
+++ b/lenses/tests/test_yum.aug
c537d4
@@ -211,6 +211,17 @@ baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge\n" =
c537d4
       { "baseurl" = "http://apt.sw.be/redhat/el6/en/$basearch/rpmforge" }
c537d4
     }
c537d4
 
c537d4
+  (* Test: Yum.lns
c537d4
+       Issue #275: parse excludes as a list *)
c537d4
+  test Yum.lns get "[epel]
c537d4
+name=Extra Packages for Enterprise Linux 6 - $basearch
c537d4
+exclude=ocs* clamav*
c537d4
+" =
c537d4
+    { "epel"
c537d4
+      { "name" = "Extra Packages for Enterprise Linux 6 - $basearch" }
c537d4
+      { "exclude" = "ocs*" }
c537d4
+      { "exclude" = "clamav*" } }
c537d4
+
c537d4
 (* Local Variables: *)
c537d4
 (* mode: caml       *)
c537d4
 (* End:             *)
c537d4
diff --git a/lenses/yum.aug b/lenses/yum.aug
c537d4
index 1b13833..030d944 100644
c537d4
--- a/lenses/yum.aug
c537d4
+++ b/lenses/yum.aug
c537d4
@@ -11,7 +11,6 @@ let sep      = IniFile.sep "=" "="
c537d4
 let empty    = Util.empty
c537d4
 let eol      = IniFile.eol
c537d4
 
c537d4
-
c537d4
 (************************************************************************
c537d4
  *                        ENTRY
c537d4
  *************************************************************************)
c537d4
@@ -23,17 +22,18 @@ let list_entry (list_key:string)  =
c537d4
   . (list_sep . Build.opt_list [ label list_key . list_value ] list_sep)?
c537d4
   . eol
c537d4
 
c537d4
-let entry_re = IniFile.entry_re - ("baseurl" | "gpgkey")
c537d4
+let entry_re = IniFile.entry_re - ("baseurl" | "gpgkey" | "exclude")
c537d4
 
c537d4
 let entry       = IniFile.entry entry_re sep comment
c537d4
                 | empty
c537d4
 
c537d4
-let entries = entry*
c537d4
-            | entry* . list_entry "baseurl" . entry*
c537d4
-            | entry* . list_entry "gpgkey" . entry*
c537d4
-            | entry* . list_entry "baseurl" . entry* . list_entry "gpgkey" . entry*
c537d4
-            | entry* . list_entry "gpgkey" . entry* . list_entry "baseurl" . entry*
c537d4
-
c537d4
+let entries =
c537d4
+     let list_entry_elem (k:string) = list_entry k . entry*
c537d4
+  in entry*
c537d4
+   | entry* . Build.combine_three_opt
c537d4
+                (list_entry_elem "baseurl")
c537d4
+                (list_entry_elem "gpgkey")
c537d4
+                (list_entry_elem "exclude")
c537d4
 
c537d4
 
c537d4
 (***********************************************************************a
c537d4
-- 
c537d4
1.8.5.3
c537d4