blob: ac997d339fee446bd6f9d69d77bce0a550b7fb71 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
;;; Consfigurator -- Lisp declarative configuration management system
;;; Copyright (C) 2020-2021 Sean Whitton <spwhitton@spwhitton.name>
;;; This file is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3, or (at your option)
;;; any later version.
;;; This file is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :consfigurator.property.file)
(defprop has-content :posix (path lines)
"Ensure there is a file at PATH whose lines are the elements of LINES."
(:apply (writefile path (unlines lines))))
(defprop contains-lines :posix (path lines)
"Ensure there is a file at PATH containing each of LINES once."
(:apply
(let ((new-lines (copy-list lines))
(existing-lines (lines (readfile path))))
(dolist (existing-line existing-lines)
(deletef new-lines existing-line :test #'string=))
(writefile path (unlines (nconc existing-lines new-lines))))))
(defprop data-uploaded :posix (iden1 iden2 destination)
(:hostattrs
(declare (ignore destination))
(require-data iden1 iden2))
(:apply
(writefile destination (get-data-stream iden1 iden2))))
(defprop host-data-uploaded :posix (destination)
(:hostattrs
(require-data (get-hostname) destination))
(:apply
(data-uploaded (get-hostname) destination destination)))
(defprop regex-replace-lines :posix (regex replace file)
"Like s/REGEX/REPLACE/ on the lines of FILE.
Uses CL-PPCRE:REGEX-REPLACE, which see for the syntax of REPLACE."
(:apply
(writefile
file
(unlines
(mapcar (lambda (line)
(re:regex-replace regex line replace))
(lines (readfile file)))))))
|