Coverage report: /home/ellis/comp/core/lib/cli/tools/pacman.lisp

KindCoveredAll%
expression0227 0.0
branch034 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
2
 
3
 ;;
4
 
5
 ;;; Commentary:
6
 
7
 ;; 
8
 
9
 ;;; Code:
10
 (in-package :cli/tools/pacman)
11
 
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)))))
16
 
17
 (defun pacman-upgrade ()
18
   (run-pacman "-Sy" "archlinux-keyring")
19
   (run-pacman "-Su"))
20
 
21
 (defconfig pacman-config (ini-document) ())
22
 
23
 (defmethod deserialize (self (format (eql :pacman-config)) &key)
24
   (change-class (deserialize self :ini) 'pacman-config))
25
 
26
 (defun load-pacman-config (&optional (path #p"/etc/pacman.conf"))
27
   (deserialize path :pacman-config))
28
 
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)))))
33
 
34
 (defconfig makepkg-config (ast) ())
35
 
36
 (defun read-makepkg-string (stream &optional c)
37
   (let ((c (or c (peek-char t stream nil))))
38
     (if (char= c #\") 
39
         (read stream)
40
         (let ((e (read-char stream)))
41
           (concatenate
42
            'string
43
            (loop with c 
44
                  do (setf c (read-char stream))
45
                  until (char= c e)
46
                  collect c))))))
47
 
48
 (defun read-makepkg-array (stream)
49
   (read-char stream nil) ;; (
50
   (let ((c (peek-char t stream nil))
51
         ret)
52
     (loop while (and c (not (char= c #\))))
53
           if (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)))
59
           else do (push
60
                    (concatenate 'string
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))))
64
                    ret))
65
     ;; and do (setf c (peek-char t stream nil))
66
     (read-char stream nil)
67
     (nreverse ret)))
68
 
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)))
73
     (case c
74
       ((or #\" #\') (read-makepkg-string stream c))
75
       (#\( (read-makepkg-array stream)))))
76
 
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)))))
82
 
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))
89
                         until (char= n #\=)
90
                         collect n)))
91
       (cons (print (intern (substitute #\- #\_ (concatenate 'string k)))) (read-makepkg-value stream)))))
92
 
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)
96
                      while l 
97
                      collect l))))
98
     (make-instance 'makepkg-config :ast ast)))
99
     
100