1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: downloads.cl
6 ;;;; Purpose: Generate downloads page
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Aug 2002
10 ;;;; $Id: downloads.lisp,v 1.2 2002/10/14 03:25:05 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 ;;;; *************************************************************************
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
26 (defvar *section-indent* 0)
27 (declaim (type (fixnum *section-indent*)))
30 (defun list-files (files)
31 "List files in a directory for downloading"
33 (mapcar #'print-file files))
35 (defun strip-ftp-base (file)
36 (let ((fdir (pathname-directory file))
37 (bdir (pathname-directory *ftp-base*)))
39 :name (pathname-name file)
40 :type (pathname-type file)
42 (when (> (length bdir) (length fdir))
44 (subseq fdir (length bdir) (length fdir)))))))
46 (defun print-file (file)
48 (modtime (date-string (file-write-date file)))
50 (make-pathname :name (pathname-name file)
51 :type (pathname-type file))))
52 (ftp-name (strip-ftp-base file))
53 (sig-path (concatenate 'string (namestring file) ".asc")))
54 (when (plusp (length basename))
55 (with-open-file (strm file :direction :input)
56 (setq size (round (/ (file-length strm) 1024))))
57 (lml-print "<a href=\"~A~A\">~A</a>" *ftp-url* ftp-name basename)
58 (lml-print "<span class=\"modtime\">")
59 (lml-print " (~A, <b>~:D <span style=\"font-size:90%;\">KB</span></b>)</span>" modtime size)
60 (when (probe-file sig-path)
62 (lml-print " [<a href=\"~A~A.asc\">Signature</a>]" *ftp-url* ftp-name))
65 (defun display-header (name url)
66 (lml-print "<h1>Download</h1>")
67 (lml-print "<div class=\"mainbody\">")
68 (lml-print "<h3>Browse ~A FTP Site</h3>" name)
69 (lml-print "<a style=\"padding-left:20pt;\" href=\"~A\">~A</a>" url url))
71 (defun display-footer ()
73 (lml-print "<h3>GPG Public Key</h3>")
74 (lml-print "Use this <a href=\"https://www.b9.com/key.asc\">key</a> to verify file signtatures"))
77 (defun print-sect-title (title)
78 (lml-print "<h~D>~A</h~D>" *section-indent* title *section-indent*))
80 (defun match-base-name? (name)
81 (let ((len-base-name (length *base-name*)))
82 (when (>= (length name) len-base-name)
83 (dotimes (i len-base-name)
85 (unless (char= (char *base-name* i)
87 (return-from match-base-name? nil)))))
90 (defun filter-against-base (files)
93 (let ((name (pathname-name f)))
94 (when (match-base-name? name)
97 (sort filtered #'(lambda (a b) (when (and a b)
100 (namestring b))))))))
102 (defun display-one-section (title pat)
103 (let ((files (filter-against-base (directory pat))))
105 (print-sect-title title)
106 (lml-print "<div style=\"padding-left: 20pt;\">")
108 (lml-print"</div>"))))
111 (defun display-sections (sects)
113 (let ((title (car sects))
114 (value (cadr sects)))
116 (mapcar #'display-sections sects)
119 (print-sect-title title)
120 (incf *section-indent*)
121 (display-sections value)
122 (decf *section-indent*))
123 (display-one-section title value))))))
125 (defun display-page (pkg-name pkg-base ftp-base ftp-url sects)
126 (let ((*section-indent* 3)
127 (*ftp-base* ftp-base)
129 (*base-name* pkg-base)
131 (display-header pkg-name ftp-url)
132 (mapcar #'display-sections sects)
135 (defun std-dl-page (pkg-name pkg-base ftp-base ftp-url)
136 (let ((base (parse-namestring ftp-base)))
137 (let ((tgz-path (make-pathname :defaults base :type "gz" :name :wild))
138 (zip-path (make-pathname :defaults base :type "zip" :name :wild))
139 (doc-path (make-pathname :defaults base :type "pdf" :name :wild)))
140 (display-page pkg-name pkg-base ftp-base ftp-url
141 `(("Manual" ,doc-path)
143 (("Unix (.tar.gz)" ,tgz-path)
144 ("Windows (.zip)" ,zip-path))))))))
146 (defun full-dl-page (pkg-name pkg-base ftp-base ftp-url)
147 (let ((base (parse-namestring ftp-base)))
148 (let ((tgz-path (make-pathname :defaults base :type "gz" :name :wild))
149 (zip-path (make-pathname :defaults base :type "zip" :name :wild))
150 (doc-path (make-pathname :defaults base :type "pdf" :name :wild))
151 (deb-path (merge-pathnames
152 (make-pathname :directory '(:relative "linux-debian")
153 :type :wild :name :wild)
155 (rpm-path (merge-pathnames
156 (make-pathname :directory '(:relative "linux-rpm")
157 :type :wild :name :wild)
159 (w32-path (merge-pathnames
160 (make-pathname :directory '(:relative "w32")
161 :type :wild :name :wild)
163 (display-page pkg-name pkg-base ftp-base ftp-url
164 `(("Manual" ,doc-path)
166 (("Unix (.tar.gz)" ,tgz-path)
167 ("Windows (.zip)" ,zip-path)))
170 (("Debian Linux" ,deb-path)
171 ("RedHat Linux" ,rpm-path)))
172 ("Windows Binaries" ,w32-path))))))))