From 57bd8d8fc275cd4e9d5ad4864528dcf157a6700c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 20 Aug 2015 10:39:25 -0400 Subject: add lacksIniSection --- src/Propellor/Property/ConfFile.hs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index 1a2503dd..ea94bd82 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -9,6 +9,7 @@ module Propellor.Property.ConfFile ( IniSection, IniKey, containsIniSetting, + lacksIniSection, ) where import Propellor @@ -52,11 +53,11 @@ adjustSection desc start past adjust insert f = (pre, wanted ++ [l], post) | otherwise = (pre, wanted, post ++ [l]) --- | Name of a section of a Windows-style .ini file. This value is put +-- | Name of a section of an .ini file. This value is put -- in square braces to generate the section header. type IniSection = String --- | Name of a configuration setting within a Windows-style .init file. +-- | Name of a configuration setting within a .ini file. type IniKey = String iniHeader :: IniSection -> String @@ -75,7 +76,7 @@ adjustIniSection desc header = (== iniHeader header) ("[" `isPrefixOf`) --- | Ensures that a Windows-style .ini file exists and contains a section +-- | Ensures that a .ini file exists and contains a section -- with a key=value setting. containsIniSetting :: FilePath -> (IniSection, IniKey, String) -> Property NoInfo containsIniSetting f (header, key, value) = @@ -83,7 +84,7 @@ containsIniSetting f (header, key, value) = (f ++ " section [" ++ header ++ "] contains " ++ key ++ "=" ++ value) header go - (++ [confheader, confline]) + (++ [confheader, confline]) -- add missing section at end f where confheader = iniHeader header @@ -91,3 +92,13 @@ containsIniSetting f (header, key, value) = go [] = [confline] go (l:ls) = if isKeyVal l then confline : ls else l : (go ls) isKeyVal x = (filter (/= ' ') . takeWhile (/= '=')) x `elem` [key, '#':key] + +-- | Ensures that a .ini file does not contain the specified section. +lacksIniSection :: FilePath -> IniSection -> Property NoInfo +lacksIniSection f header = + adjustIniSection + (f ++ " lacks section [" ++ header ++ "]") + header + (const []) -- remove all lines of section + id -- add no lines if section is missing + f -- cgit v1.2.3 From 9d6a98a2654c6c047c4f4af2e60ee3466b18cd35 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 20 Aug 2015 10:41:09 -0400 Subject: changelog --- debian/changelog | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/debian/changelog b/debian/changelog index 1116016a..5f164e80 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +propellor (2.7.2) UNRELEASED; urgency=medium + + * Added Propellor.Property.ConfFile, with support for Windows-style .ini + files, and generic support for files containing some sort of sections. + Thanks, Sean Whitton for completing the implementation. + * Added Propellor.Property.LightDM + Thanks, Sean Whitton. + + -- Joey Hess Thu, 20 Aug 2015 10:39:32 -0400 + propellor (2.7.1) unstable; urgency=medium * Make sure that make is installed when bootstrapping propellor. -- cgit v1.2.3 From bea60fc136a70bdcea3f7f2ace9c8f0e8a5c2dce Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 20 Aug 2015 10:42:20 -0400 Subject: avoid bad haddock rendering --- src/Propellor/Property/ConfFile.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index ea94bd82..066848bb 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -23,7 +23,7 @@ type SectionStart = Line -> Bool -- (eg, a new section header) type SectionPast = Line -> Bool -- | run on all lines in the section, including the SectionStart line; --- can add/delete/modify lines, or even delete entire section +-- can add, delete, and modify lines, or even delete entire section type AdjustSection = [Line] -> [Line] -- | if SectionStart does not find the section in the file, this is used to -- insert the section somewhere within it -- cgit v1.2.3