1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: downloads.lisp
6 ;;;; Purpose: Generate downloads page
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Aug 2002
10 ;;;; $Id: downloads.lisp,v 1.11 2003/06/15 13:49:42 kevin Exp $
12 ;;;; This file, part of LML, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; LML users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the GNU General Public License v2
16 ;;;; (http://www.gnu.org/licenses/gpl.html)
17 ;;;; *************************************************************************
25 (defvar *section-indent* 0)
28 (defun list-files (files)
29 "List files in a directory for downloading"
31 (mapcar #'print-file files))
33 (defun strip-dl-base (file)
34 (let ((fdir (pathname-directory file))
35 (bdir (pathname-directory *dl-base*)))
37 :name (pathname-name file)
38 :type (pathname-type file)
40 (when (> (length fdir) (length bdir))
42 (subseq fdir (length bdir) (length fdir)))))))
44 (defun print-file (file)
46 (modtime (date-string (file-write-date file)))
48 (make-pathname :name (pathname-name file)
49 :type (pathname-type file))))
50 (dl-name (strip-dl-base file))
51 (sig-path (concatenate 'string (namestring file) ".asc")))
52 (when (plusp (length basename))
53 (with-open-file (strm file :direction :input)
54 (setq size (round (/ (file-length strm) 1024))))
55 (lml-format "<a href=\"~A~A\">~A</a>" *dl-url* dl-name basename)
56 (lml-princ "<span class=\"modtime\">")
57 (lml-format " (~A, <b>~:D <span style=\"font-size:90%;\">KB</span></b>)</span>" modtime size)
58 (when (probe-file sig-path)
60 (lml-format " [<a href=\"~A~A.asc\">Signature</a>]" *dl-url* dl-name))
63 (defun display-header (name url)
64 (lml-princ "<h1>Download</h1>")
65 (lml-princ "<div class=\"mainbody\">")
66 (lml-format "<h3>Browse ~A Download Site</h3>" name)
67 (lml-format "<a style=\"padding-left:20pt;\" href=\"~A\">~A</a>" url url))
69 (defun display-footer ()
71 (lml-princ "<h3>GPG Public Key</h3>")
72 (lml-princ "Use this <a href=\"https://www.b9.com/kevin.gpg.asc\">key</a> to verify file signtatures"))
75 (defun print-sect-title (title)
76 (lml-format "<h~D>~A</h~D>" *section-indent* title *section-indent*))
78 (defun match-base-name? (name)
79 (let ((len-base-name (length *base-name*)))
80 (when (>= (length name) len-base-name)
81 (string= name *base-name* :end1 len-base-name :end2 len-base-name))))
83 (defun match-base-name-latest? (name)
84 (let* ((latest (concatenate 'string *base-name* "-latest"))
85 (len-latest (length latest)))
86 (when (>= (length name) len-latest)
87 (string= name latest :end1 len-latest :end2 len-latest))))
89 (defun filter-against-base (files)
90 (delete-if-not #'(lambda (f) (match-base-name? (pathname-name f))) files))
92 (defun filter-latest (files)
93 (delete-if #'(lambda (f) (match-base-name-latest? (pathname-name f))) files))
95 (defun sort-pathnames (list)
96 (sort list #'(lambda (a b) (string< (namestring a) (namestring b)))))
98 (defun display-one-section (title pat)
99 (let ((files (sort-pathnames (filter-latest
100 (filter-against-base (directory pat))))))
102 (print-sect-title title)
103 (lml-princ "<div style=\"padding-left: 20pt;\">")
105 (lml-princ "</div>"))))
107 (defun display-sections (sects)
109 (let ((title (car sects))
110 (value (cadr sects)))
112 (dolist (sect sects) (display-sections sect))
115 (print-sect-title title)
116 (incf *section-indent*)
117 (display-sections value)
118 (decf *section-indent*))
119 (display-one-section title value))))))
121 (defun display-page (pkg-name pkg-base dl-base dl-url sects)
122 (let ((*section-indent* 3)
125 (*base-name* pkg-base)
127 (display-header pkg-name dl-url)
128 (map nil #'display-sections sects)
131 (defun std-dl-page (pkg-name pkg-base dl-base dl-url)
132 (let ((base (parse-namestring dl-base)))
133 (let ((tgz-path (make-pathname :defaults base :type "gz" :name :wild))
134 (zip-path (make-pathname :defaults base :type "zip" :name :wild))
135 (doc-path (make-pathname :defaults base :type "pdf" :name :wild)))
136 (display-page pkg-name pkg-base dl-base dl-url
137 `(("Manual" ,doc-path)
139 (("Unix (.tar.gz)" ,tgz-path)
140 ("Windows (.zip)" ,zip-path))))))))
142 (defun full-dl-page (pkg-name pkg-base dl-base dl-url)
143 (let ((base (parse-namestring dl-base)))
144 (let ((tgz-path (make-pathname :defaults base :type "gz" :name :wild))
145 (zip-path (make-pathname :defaults base :type "zip" :name :wild))
146 (doc-path (make-pathname :defaults base :type "pdf" :name :wild))
147 (deb-path (merge-pathnames
148 (make-pathname :directory '(:relative "linux-debian")
149 :type :wild :name :wild)
151 (rpm-path (merge-pathnames
152 (make-pathname :directory '(:relative "linux-rpm")
153 :type :wild :name :wild)
155 (w32-path (merge-pathnames
156 (make-pathname :directory '(:relative "win32")
157 :type :wild :name :wild)
159 (display-page pkg-name pkg-base dl-base dl-url
160 `(("Manual" ,doc-path)
162 (("Unix (.tar.gz)" ,tgz-path)
163 ("Windows (.zip)" ,zip-path)))
166 (("Debian Linux" ,deb-path)
167 ("RedHat Linux" ,rpm-path)))
168 ("Windows Binaries" ,w32-path))))))))