Coverage report: /home/ellis/comp/core/lib/cli/tools/pacman.lisp
Kind | Covered | All | % |
expression | 0 | 227 | 0.0 |
branch | 0 | 34 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; pacman.lisp --- Arch Linux Packaging Tools
10
(in-package :cli/tools/pacman)
12
(define-cli-tool :pacman (&rest args)
13
(let ((proc (sb-ext:run-program *pacman* (or args nil) :output t)))
14
(unless (eq 0 (sb-ext:process-exit-code proc))
15
(pacman-error "Pacman command failed: ~A ~A" *pacman* (sb-ext:process-error proc)))))
17
(defun pacman-upgrade ()
18
(run-pacman "-Sy" "archlinux-keyring")
21
(defconfig pacman-config (ini-document) ())
23
(defmethod deserialize (self (format (eql :pacman-config)) &key)
24
(change-class (deserialize self :ini) 'pacman-config))
26
(defun load-pacman-config (&optional (path #p"/etc/pacman.conf"))
27
(deserialize path :pacman-config))
29
(define-cli-tool :makepkg (&rest args)
30
(let ((proc (sb-ext:run-program *makepkg* (or args nil) :output t)))
31
(unless (eq 0 (sb-ext:process-exit-code proc))
32
(makepkg-error "Pacman command failed: ~A ~A" *makepkg* (sb-ext:process-error proc)))))
34
(defconfig makepkg-config (ast) ())
36
(defun read-makepkg-string (stream &optional c)
37
(let ((c (or c (peek-char t stream nil))))
40
(let ((e (read-char stream)))
44
do (setf c (read-char stream))
48
(defun read-makepkg-array (stream)
49
(read-char stream nil) ;; (
50
(let ((c (peek-char t stream nil))
52
(loop while (and c (not (char= c #\))))
54
do (progn (read-line stream nil) (setf c (peek-char t stream nil)))
55
else if (whitespace-p c)
56
do (progn (read-char stream nil) (setf c (peek-char t stream nil)))
57
else if (or (char= c #\') (char= c #\"))
58
do (progn (push (read-makepkg-string stream) ret) (setf c (peek-char t stream nil)))
61
(loop while (and c (not (char= c #\))) (not (whitespace-p c)))
62
collect (read-char stream nil)
63
do (setf c (peek-char nil stream nil))))
65
;; and do (setf c (peek-char t stream nil))
66
(read-char stream nil)
69
(defun read-makepkg-value (stream)
70
"Read a makepkg.conf value from STREAM which should be either a bash array or string."
71
(skip-makepkg-junk stream)
72
(let ((c (peek-char t stream nil)))
74
((or #\" #\') (read-makepkg-string stream c))
75
(#\( (read-makepkg-array stream)))))
77
(defun skip-makepkg-junk (stream)
78
(when-let ((c (peek-char t stream nil)))
79
(loop until (or (not c) (not (or (char= c #\#) (whitespace-p c))))
80
do (read-line stream nil)
81
do (setf c (peek-char t stream nil)))))
83
(defun read-makepkg-pair (stream)
84
"Read a key/value pair from an makepkg.conf STREAM. Return the result as a cons."
85
(skip-makepkg-junk stream)
86
(when (peek-char t stream nil)
87
(when-let ((k (loop with n
88
do (setf n (read-char stream))
91
(cons (print (intern (substitute #\- #\_ (concatenate 'string k)))) (read-makepkg-value stream)))))
93
(defun load-makepkg-config (&optional (path #p"/etc/makepkg.conf"))
94
(let ((ast (with-open-file (f path)
95
(loop for l = (read-makepkg-pair f)
98
(make-instance 'makepkg-config :ast ast)))