packages feed

puppetresources 0.1.2 → 0.1.3

raw patch · 2 files changed

+39/−4 lines, 2 files

Files

Main.hs view
@@ -41,8 +41,22 @@ > Pin: release a=karmic > Pin-Priority: 700 -With GHCI there are tons of things you can do. First initialize it -    +You can also just use a resource name :++> $ puppetresources samplesite test.nod 'exec[apt_update]'+> exec {+>   "apt_update": #"samplesite/modules/apt/manifests/update.pp" (line 4, column 10)+>       command     => "/usr/bin/apt-get update",+>       logoutput   => "false",+>       refreshonly => "true",+>       returns     => 0,+>       timeout     => 300,+>       tries       => 1,+>       try_sleep   => 0;+> }++With GHCI there are tons of things you can do. First initialize it+ >>> queryfunc <- initializedaemon "./samplesite/"  You can now compute catalogs for various nodes.@@ -103,6 +117,7 @@ import Control.Monad import Control.Monad.Error (runErrorT) import Puppet.DSL.Printer+import Data.Char (toLower)  usage = error "Usage: puppetresource puppetdir nodename [filename]" @@ -219,6 +234,14 @@             Just (ResolvedString c)  -> putStrLn c             Just x -> print x +-- pretty print a resource+-- if this resource has content, works like printContent+printResource :: String -> String -> FinalCatalog -> IO ()+printResource restype resname catalog =+    case (Map.lookup (restype, resname) catalog) of+        Nothing -> error $ "Resource " ++ restype ++ "[" ++ resname ++ "] does not exists."+        Just r  -> putStrLn $ showFCatalog $ Map.singleton (restype, resname) r+ r2s :: ResolvedValue -> String r2s (ResolvedString x)  = x r2s x                   = show x@@ -237,8 +260,20 @@     when (length args == 1) (doparse  (head args))     let (puppetdir, nodename) | (length args /= 2) && (length args /= 3) = usage                               | otherwise = (args !! 0, args !! 1)+        getresname :: String -> Maybe (String, String)+        getresname r =+            let isresname = ((head $ reverse r) == ']') && ('[' `elem` r)+                (rtype, rname) = break (== '[') r+            in if isresname+                then Just (map toLower rtype, tail $ reverse $ (tail $ reverse rname))+                else Nothing+        handlePrintResource resname cat+            = case (getresname resname) of+                Just (t,n) -> printResource t n cat+                Nothing    -> printContent resname cat+     queryfunc <- initializedaemon puppetdir     x <- queryfunc nodename     if length args == 3-        then printContent (args !! 2) x+        then handlePrintResource (args !! 2) x         else putStrLn $ showFCatalog x
puppetresources.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                puppetresources-version:             0.1.2+version:             0.1.3 synopsis:            A program that displays the puppet resources associated to a node given .pp files. -- description:          license:             GPL-3