unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 883c32b1418b62f6bb6bebf8926886d30166cf32 9998 bytes (raw)
name: build-aux/list-packages.scm 	 # note: path name is non-authoritative(*)

  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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
 
#!/bin/sh
exec guile -l "$0"                              \
  -c '(apply (@ (list-packages) list-packages)
             (cdr (command-line)))'
!#
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013 Alex Sassmannshausen <alex.sassmannshausen@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix 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 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (list-packages)
  #:use-module (guix utils)
  #:use-module (guix packages)
  #:use-module (guix licenses)
  #:use-module (guix gnu-maintenance)
  #:use-module (guix build utils)
  #:use-module (gnu packages)
  #:use-module (sxml simple)
  #:use-module (web uri)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:export (list-packages))

;;; Commentary:
;;;
;;; Emit an HTML representation of the packages available in GNU Guix.
;;;
;;; Code:

(define lookup-gnu-package
  (let ((gnu (official-gnu-packages)))
    (lambda (name)
      "Return the package description for GNU package NAME, or #f."
      (find (lambda (package)
              (equal? (gnu-package-name package) name))
            gnu))))

(define (package->sxml package)
  "Return HTML-as-SXML representing PACKAGE."
  (define (source-url package)
    (let ((loc (package-location package)))
      (and loc
           (string-append "http://git.savannah.gnu.org/cgit/guix.git/tree/"
                          (location-file loc) "#n"
                          (number->string (location-line loc))))))

  (define (license package)
    (define ->sxml
      (match-lambda
       ((lst ...)
        `(div ,(map ->sxml lst)))
       ((? license? license)
        (let ((uri (license-uri license)))
          (case (and=> (and uri (string->uri uri)) uri-scheme)
            ((http https)
             `(div (a (@ (href ,uri)
                         (title "Link to the full license"))
                      ,(license-name license))))
            (else
             `(div ,(license-name license) " ("
                   ,(license-comment license) ")")))))
       (#f "")))

    (->sxml (package-license package)))

  (define (status package)
    (define (url system)
      `(a (@ (href ,(string-append "http://hydra.gnu.org/job/gnu/master/"
                                   (package-full-name package) "."
                                   system))
             (title "View the status of this architecture's build at Hydra"))
          ,system))

    `(div "status: "
          ,(url "x86_64-linux") " "
          ,(url "i686-linux")))

  (define (package-logo name)
    (and=> (lookup-gnu-package name)
           gnu-package-logo))

  (let ((description-id (symbol->string
                         (gensym (package-name package)))))
   `(tr (td ,(if (gnu-package? package)
                 `(img (@ (src "/graphics/gnu-head-mini.png")
                          (alt "Part of GNU")
                          (title "Part of GNU")))
                 ""))
        (td (a (@ (href ,(source-url package))
                  (title "Link to the Guix package source code"))
               ,(package-name package) " "
               ,(package-version package)))
        (td (span (strong ,(package-synopsis package)))
            (div (@ (id ,description-id))
                 ,(match (package-logo (package-name package))
                    ((? string? url)
                     `(img (@ (src ,url)
                              (height "35em")
                              (class "package-logo")
                              (alt ("Logo of " ,(package-name package))))))
                    (_ #f))
                 (p ,(package-description package))
                 ,(license package)
                 (a (@ (href ,(package-home-page package))
                       (title "Link to the package's website"))
                    ,(package-home-page package))
                 ,(status package))
            ,(show_hide-grouper description-id)))))

(define show_hide-grouper
  (let ((lid '())
        (group-counter 15))
    (lambda (id)
      "Collect GROUP-COUNTER element IDs, then apply them to
bulk_show_hide. If ID is #f, force the application of collected IDs to
bulk_show_hide even when the number of IDs is smaller than GROUP-COUNTER."
      (define (insert-js-call)
        "Return an sxml call to bulk_show_hide."
        (define (lid->js-argl)
          "Parse a Scheme list into a JavaScript style arguments list."
          (define (helper l)
            (if (null? l)
                (begin
                  (set! lid '()) ; lid, now processed, safe to reset.
                  "")
                (string-append ", '" (car l) "'"      ; further args.
                               (helper (cdr l)))))
          (string-append "'" (car lid) "'"             ; initial arg.
                         (helper (cdr lid))))
        `(script (@ (type "text/javascript"))
                 ,(format #f "bulk_show_hide(~a)"
                          (lid->js-argl))))
      (if id
          (begin
            ;; If ID is not false, then we add ID to LID.
            (set! lid (cons id lid))
            ;; If LID is now equal to GROUP-COUNTER it is time to insert a
            ;; call to bulk_show_hide in the HTML.
            (if (= (length lid) group-counter)
                (insert-js-call)
                ""))
          ;; if ID is false then we force the insert of a call to
          ;; bulk_show_hide for (< n GROUP-COUNTER) packages in the HTML.
          (insert-js-call)))))

(define (packages->sxml packages)
  "Return an HTML page as SXML describing PACKAGES."
  `(div
    (h2 "GNU Guix Package List")
    (div (@ (id "intro"))
         (div
          (img (@ (src "graphics/guix-logo.small.png")
                  (alt "GNU Guix and the GNU System")
                  (height "83em"))))
         (p "This web page lists the packages currently provided by the "
            (a (@ (href "manual/guix.html#GNU-Distribution"))
               "GNU system distribution")
            " of "
            (a (@ (href "/software/guix/guix.html")) "GNU Guix") ".  "
            "Our " (a (@ (href "http://hydra.gnu.org/jobset/gnu/master"))
                      "continuous integration system")
            " shows their current build status."))
    (table (@ (id "packages"))
           (tr (th "GNU?")
               (th "Package version")
               (th "Package details"))
           ,@(map package->sxml packages))
    ,(show_hide-grouper #f)
    (a (@ (href "#intro")
          (title "Back to top.")
          (id "top"))
       "^")))

\f
(define %load-directory
  (string-append (dirname (current-filename)) "/"))

(define %css-file
  "package-list.css")
(define %js-file
  "package-list.js")

(define (insert-css . inline)
  "Return an sxml link to the CSS file for the list-packages page.  If
the optional inline argument is present, inline the CSS instead.
Inlining currently fail with wrong-num-args error."
  (if (null? inline)
      `(link (@ (type "text/css")
		(rel "stylesheet")
		(href ,%css-file)))
      `(style (@ (type "text/css"))
	 ,(with-input-from-file (string-append %load-directory %css-file)
	    (cute dump-port <> (current-output-port))))))

(define (insert-js . inline)
  "Return an sxml link to the CSS file for the list-packages page.  If
the optional inline argument is present, inline the CSS instead.
Inlining currently fail with wrong-num-args error."
  (if (null? inline)
      `(script (@ (type "text/javascript")
                  (src ,%js-file))
               " ")
      `(style (@ (type "text/javascript"))
	 ,(with-input-from-file (string-append %load-directory %js-file)
	    (cute dump-port <> (current-output-port))))))

\f
(define (list-packages . args)
  "Return an HTML page listing all the packages found in the GNU distribution,
with gnu.org server-side include and all that."
  ;; Don't attempt to translate descriptions.
  (setlocale LC_ALL "C")

  ;; Output the page as UTF-8 since that's what the gnu.org server-side
  ;; headers claim.
  (set-port-encoding! (current-output-port) "UTF-8")

  (let ((packages (sort (fold-packages cons '())
                        (lambda (p1 p2)
                          (string<? (package-name p1) (package-name p2))))))
   (format #t "<!--#include virtual=\"/server/html5-header.html\" -->
<!-- Parent-Version: 1.70 $ -->
<title>GNU Guix - GNU Distribution - GNU Project</title>
")
   (sxml->xml `(,(insert-css)
                ,(insert-js)))
   (format #t "<!--#include virtual=\"/server/banner.html\" -->")

   (sxml->xml (packages->sxml packages))
   (format #t "</div>
<!--#include virtual=\"/server/footer.html\" -->
<div id=\"footer\">

<p>Please send general FSF &amp; GNU inquiries to
<a href=\"mailto:gnu@gnu.org\">&lt;gnu@gnu.org&gt;</a>.
There are also <a href=\"/contact/\">other ways to contact</a>
the FSF.  Broken links and other corrections or suggestions can be sent
to <a href=\"mailto:bug-guix@gnu.org\">&lt;bug-guix@gnu.org&gt;</a>.</p>

<p>Copyright &copy; 2013 Free Software Foundation, Inc.</p>

<p>This page is licensed under a <a rel=\"license\"
href=\"http://creativecommons.org/licenses/by-nd/3.0/us/\">Creative
Commons Attribution-NoDerivs 3.0 United States License</a>.</p>

<p>Updated:
<!-- timestamp start -->
$Date$
<!-- timestamp end -->
</p>
</div>
</div>
</body>
</html>
"))
  )

;;; list-packages.scm ends here

debug log:

solving 883c32b ...
found 883c32b in https://yhetil.org/guix-devel/CAKdwf2BhW0pntTN_YO-4kNcWhcXAw120U9JQnt8xDWKtepcUnw@mail.gmail.com/
found 161116b in https://yhetil.org/guix-devel/CAKdwf2BhW0pntTN_YO-4kNcWhcXAw120U9JQnt8xDWKtepcUnw@mail.gmail.com/
found 5fbe359 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100755 5fbe3590acc9c90e0ee2e8747b991cb171412622	build-aux/list-packages.scm

applying [1/2] https://yhetil.org/guix-devel/CAKdwf2BhW0pntTN_YO-4kNcWhcXAw120U9JQnt8xDWKtepcUnw@mail.gmail.com/
diff --git a/build-aux/list-packages.scm b/build-aux/list-packages.scm
index 5fbe359..161116b 100755


applying [2/2] https://yhetil.org/guix-devel/CAKdwf2BhW0pntTN_YO-4kNcWhcXAw120U9JQnt8xDWKtepcUnw@mail.gmail.com/
diff --git a/build-aux/list-packages.scm b/build-aux/list-packages.scm
index 161116b..883c32b 100755

Checking patch build-aux/list-packages.scm...
Applied patch build-aux/list-packages.scm cleanly.
Checking patch build-aux/list-packages.scm...
Applied patch build-aux/list-packages.scm cleanly.

index at:
100755 883c32b1418b62f6bb6bebf8926886d30166cf32	build-aux/list-packages.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).