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.cl,v 1.2 2002/09/16 03:09:00 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)
29 (defun list-files (files)
30 "List files in a directory for downloading"
32 (mapcar #'print-file files))
34 (defun strip-ftp-base (file)
35 (let ((fdir (pathname-directory file))
36 (bdir (pathname-directory *ftp-base*)))
38 :name (pathname-name file)
39 :type (pathname-type file)
41 (when (> (length bdir) (length fdir))
43 (subseq (length bdir) (length fdir) fdir))))))
45 (defun print-file (file)
47 (modtime (date-string (file-write-date file)))
49 (make-pathname :name (pathname-name file)
50 :type (pathname-type file))))
51 (ftp-name (strip-ftp-base file))
53 (make-pathname :defaults file
56 (pathname-type file) ".asc"))))
57 (with-open-file (strm file :direction :input)
58 (setq size (round (/ (file-length strm) 1024))))
59 (lml-print "<a href=\"~A~A\">~A</a>" *ftp-url* ftp-name basename)
60 (lml-print "<span class=\"modtime\">")
61 (lml-print " (~A, <b>~:D <span style=\"font-size:90%;\">KB</span></b>)</span>" modtime size)
62 (when (probe-file sig-path)
64 (lml-print " [<a href=\"~A~A.asc\">Signature</a>]" *ftp-url* ftp-name))
67 (defun display-header (name url)
68 (lml-print "<h1>Download</h1>")
69 (lml-print "<div class=\"mainbody\">")
70 (lml-print "<h3>Browse ~A FTP Site</h3>" name)
71 (lml-print "<a style=\"padding-left:20pt;\" href=\"~A\">~A</a>" url url))
73 (defun display-footer ()
75 (lml-print "<h3>GPG Public Key</h3>")
76 (lml-print "Use this <a href=\"https://www.b9.com/key.asc\">key</a> to verify file signtatures"))
79 (defun print-sect-title (title)
80 (lml-print "<h~D>~A</h~D>" *section-indent* title *section-indent*))
82 (defun filter-against-base (files)
85 (let ((name (pathname-name f)))
88 (dotimes (i (length *base-name*))
90 (unless (char= (char *base-name* i)
92 (return-from search nil)))
95 (sort filtered #'(lambda (a b) (string<
99 (defun display-one-section (title pat)
100 (let ((files (filter-against-base (directory pat))))
102 (print-sect-title title)
103 (lml-print "<div style=\"padding-left: 20pt;\">")
105 (lml-print"</div>"))))
108 (defun display-sections (sects)
110 (let ((title (car sects))
111 (value (cadr sects)))
113 (mapcar #'display-sections sects)
116 (print-sect-title title)
117 (incf *section-indent*)
118 (display-sections value)
119 (decf *section-indent*))
120 (display-one-section title value))))))
122 (defun display-page (pkg-name pkg-base ftp-base ftp-url sects)
123 (let ((*section-indent* 3)
124 (*ftp-base* ftp-base)
126 (*base-name* pkg-base)
128 (display-header pkg-name ftp-url)
129 (mapcar #'display-sections sects)
132 (defun std-dl-page (pkg-name pkg-base ftp-base ftp-url)
133 (let ((base (parse-namestring ftp-base)))
134 (let ((tgz-path (make-pathname :defaults base :type "gz" :name :wild))
135 (zip-path (make-pathname :defaults base :type "zip" :name :wild))
136 (doc-path (make-pathname :defaults base :type "pdf" :name :wild)))
137 (display-page pkg-name pkg-base ftp-base ftp-url
138 `(("Manual" ,doc-path)
140 (("Unix (.tar.gz)" ,tgz-path)
141 ("Windows (.zip)" ,zip-path))))))))
143 (defun full-dl-page (pkg-name pkg-base ftp-base ftp-url)
144 (let ((base (parse-namestring ftp-base)))
145 (let ((tgz-path (make-pathname :defaults base :type "gz" :name :wild))
146 (zip-path (make-pathname :defaults base :type "zip" :name :wild))
147 (doc-path (make-pathname :defaults base :type "pdf" :name :wild))
148 (deb-path (merge-pathnames
149 (make-pathname :directory '(:relative "linux-debian")
150 :type :wild :name :wild)
152 (rpm-path (merge-pathnames
153 (make-pathname :directory '(:relative "linux-rpm")
154 :type :wild :name :wild)
156 (w32-path (merge-pathnames
157 (make-pathname :directory '(:relative "w32")
158 :type :wild :name :wild)
160 (display-page pkg-name pkg-base ftp-base ftp-url
161 `(("Manual" ,doc-path)
163 (("Unix (.tar.gz)" ,tgz-path)
164 ("Windows (.zip)" ,zip-path)))
167 (("Debian Linux" ,deb-path)
168 ("RedHat Linux" ,rpm-path)))
169 ("Windows Binaries" ,w32-path))))))))