X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=downloads.lisp;fp=downloads.lisp;h=226095eebfa7d3bf0ea21fe208f9f3534498f465;hb=e741d288978f9a65554235ecb3115db8eef60b54;hp=0000000000000000000000000000000000000000;hpb=f3088cd6e99688e7bc3d37bb6c5a58e08c958611;p=lml.git diff --git a/downloads.lisp b/downloads.lisp new file mode 100644 index 0000000..226095e --- /dev/null +++ b/downloads.lisp @@ -0,0 +1,171 @@ +;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*- +;;;; ************************************************************************* +;;;; FILE IDENTIFICATION +;;;; +;;;; Name: downloads.cl +;;;; Purpose: Generate downloads page +;;;; Programmer: Kevin M. Rosenberg +;;;; Date Started: Aug 2002 +;;;; +;;;; $Id: downloads.lisp,v 1.1 2002/09/30 10:26:43 kevin Exp $ +;;;; +;;;; This file, part of LML, is Copyright (c) 2002 by Kevin M. Rosenberg +;;;; +;;;; LML users are granted the rights to distribute and use this software +;;;; as governed by the terms of the GNU General Public License v2 +;;;; (http://www.gnu.org/licenses/gpl.html) +;;;; ************************************************************************* + +(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0))) +(in-package :lml) + + +(defvar *ftp-base*) +(defvar *ftp-url*) +(defvar *base-name*) +(defvar *section-indent* 0) +(defvar *signed* nil) + +(defun list-files (files) + "List files in a directory for downloading" + ;;files.sort() + (mapcar #'print-file files)) + +(defun strip-ftp-base (file) + (let ((fdir (pathname-directory file)) + (bdir (pathname-directory *ftp-base*))) + (make-pathname + :name (pathname-name file) + :type (pathname-type file) + :directory + (when (> (length bdir) (length fdir)) + (append '(:absolute) + (subseq (length bdir) (length fdir) fdir)))))) + +(defun print-file (file) + (let ((size 0) + (modtime (date-string (file-write-date file))) + (basename (namestring + (make-pathname :name (pathname-name file) + :type (pathname-type file)))) + (ftp-name (strip-ftp-base file)) + (sig-path (concatenate 'string (namestring file) ".asc"))) + (when (plusp (length basename)) + (with-open-file (strm file :direction :input) + (setq size (round (/ (file-length strm) 1024)))) + (lml-print "~A" *ftp-url* ftp-name basename) + (lml-print "") + (lml-print " (~A, ~:D KB)" modtime size) + (when (probe-file sig-path) + (setq *signed* t) + (lml-print " [Signature]" *ftp-url* ftp-name)) + (br)))) + +(defun display-header (name url) + (lml-print "

Download

") + (lml-print "
") + (lml-print "

Browse ~A FTP Site

" name) + (lml-print "~A" url url)) + +(defun display-footer () + (when *signed* + (lml-print "

GPG Public Key

") + (lml-print "Use this key to verify file signtatures")) + (lml-print "
")) + +(defun print-sect-title (title) + (lml-print "~A" *section-indent* title *section-indent*)) + +(defun match-base-name? (name) + (let ((len-base-name (length *base-name*))) + (when (>= (length name) len-base-name) + (dotimes (i len-base-name) + (declare (fixnum i)) + (unless (char= (char *base-name* i) + (char name i)) + (return-from match-base-name? nil))))) + t) + +(defun filter-against-base (files) + (let ((filtered '())) + (dolist (f files) + (let ((name (pathname-name f))) + (when (match-base-name? name) + (push f filtered)))) + (when filtered + (sort filtered #'(lambda (a b) (when (and a b) + (string< + (namestring a) + (namestring b)))))))) + +(defun display-one-section (title pat) + (let ((files (filter-against-base (directory pat)))) + (when files + (print-sect-title title) + (lml-print "
") + (list-files files) + (lml-print"
")))) + + +(defun display-sections (sects) + (when sects + (let ((title (car sects)) + (value (cadr sects))) + (if (consp title) + (mapcar #'display-sections sects) + (if (consp value) + (progn + (print-sect-title title) + (incf *section-indent*) + (display-sections value) + (decf *section-indent*)) + (display-one-section title value)))))) + +(defun display-page (pkg-name pkg-base ftp-base ftp-url sects) + (let ((*section-indent* 3) + (*ftp-base* ftp-base) + (*ftp-url* ftp-url) + (*base-name* pkg-base) + (*signed* nil)) + (display-header pkg-name ftp-url) + (mapcar #'display-sections sects) + (display-footer))) + +(defun std-dl-page (pkg-name pkg-base ftp-base ftp-url) + (let ((base (parse-namestring ftp-base))) + (let ((tgz-path (make-pathname :defaults base :type "gz" :name :wild)) + (zip-path (make-pathname :defaults base :type "zip" :name :wild)) + (doc-path (make-pathname :defaults base :type "pdf" :name :wild))) + (display-page pkg-name pkg-base ftp-base ftp-url + `(("Manual" ,doc-path) + ("Source Code" + (("Unix (.tar.gz)" ,tgz-path) + ("Windows (.zip)" ,zip-path)))))))) + +(defun full-dl-page (pkg-name pkg-base ftp-base ftp-url) + (let ((base (parse-namestring ftp-base))) + (let ((tgz-path (make-pathname :defaults base :type "gz" :name :wild)) + (zip-path (make-pathname :defaults base :type "zip" :name :wild)) + (doc-path (make-pathname :defaults base :type "pdf" :name :wild)) + (deb-path (merge-pathnames + (make-pathname :directory '(:relative "linux-debian") + :type :wild :name :wild) + base)) + (rpm-path (merge-pathnames + (make-pathname :directory '(:relative "linux-rpm") + :type :wild :name :wild) + base)) + (w32-path (merge-pathnames + (make-pathname :directory '(:relative "w32") + :type :wild :name :wild) + base))) + (display-page pkg-name pkg-base ftp-base ftp-url + `(("Manual" ,doc-path) + ("Source Code" + (("Unix (.tar.gz)" ,tgz-path) + ("Windows (.zip)" ,zip-path))) + ("Binaries" + (("Linux Binaries" + (("Debian Linux" ,deb-path) + ("RedHat Linux" ,rpm-path))) + ("Windows Binaries" ,w32-path))))))))