;;; package-get.el --- Retrieve XEmacs package ;; Copyright (C) 1998 by Pete Ware ;; Copyright (C) 2002 Ben Wing. ;; Copyright (C) 2003, Steve Youngs ;; Author: Pete Ware ;; Heavy-Modifications: Greg Klanderman ;; Jan Vroonhof ;; Steve Youngs ;; Keywords: internal ;; This file is part of XEmacs. ;; XEmacs 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 2, or (at your option) ;; any later version. ;; XEmacs 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 XEmacs; see the file COPYING. If not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ;; 02111-1307, USA. ;;; Synched up with: Not in FSF ;;; Commentary: ;; package-get - ;; Retrieve a package and any other required packages from an archive ;; ;; ;; Note (JV): Most of this no longer applies! ;; ;; The idea: ;; A new XEmacs lisp-only release is generated with the following steps: ;; 1. The maintainer runs some yet to be written program that ;; generates all the dependency information. This should ;; determine all the require and provide statements and associate ;; them with a package. ;; 2. All the packages are then bundled into their own tar balls ;; (or whatever format) ;; 3. Maintainer automatically generates a new `package-get-base' ;; data structure which contains information such as the ;; package name, the file to be retrieved, an md5 checksum, ;; etc (see `package-get-base'). ;; 4. The maintainer posts an announcement with the new version ;; of `package-get-base'. ;; 5. A user/system manager saves this posting and runs ;; `package-get-update' which uses the previously saved list ;; of packages, `package-get-here' that the user/site ;; wants to determine what new versions to download and ;; install. ;; ;; A user/site manager can generate a new `package-get-here' structure ;; by using `package-get-setup' which generates a customize like ;; interface to the list of packages. The buffer looks something ;; like: ;; ;; gnus - a mail and news reader ;; [] Always install ;; [] Needs updating ;; [] Required by other [packages] ;; version: 2.0 ;; ;; vm - a mail reader ;; [] Always install ;; [] Needs updating ;; [] Required by other [packages] ;; ;; Where `[]' indicates a toggle box ;; ;; - Clicking on "Always install" puts this into ;; `package-get-here' list. "Needs updating" indicates a new ;; version is available. Anything already in ;; `package-get-here' has this enabled. ;; - "Required by other" means some other packages are going to force ;; this to be installed. Clicking on [packages] gives a list ;; of packages that require this. ;; ;; The `package-get-base' should be installed in a file in ;; `data-directory'. The `package-get-here' should be installed in ;; site-lisp. Both are then read at run time. ;; ;; TODO: ;; - Implement `package-get-setup' ;; - Actually put `package-get-base' and `package-get-here' into ;; files that are read. ;; - Allow users to have their own packages that they want installed ;; in ~/.xemacs/. ;; - SOMEONE needs to write the programs that generate the ;; provides/requires database and makes it into a lisp data ;; structure suitable for `package-get-base' ;; - Handle errors such as no package providing a required symbol. ;; - Tie this into the `require' function to download packages ;; transparently. ;;; Change Log ;;; Code: (require 'package-admin) ;; (require 'package-get-base) (defgroup package-tools nil "Tools to manipulate packages." :group 'emacs) (defgroup package-get nil "Automatic Package Fetcher and Installer." :prefix "package-get" :group 'package-tools) ;;;###autoload (defvar package-get-base nil "List of packages that are installed at this site. For each element in the alist, car is the package name and the cdr is a plist containing information about the package. Typical fields kept in the plist are: version - version of this package provides - list of symbols provided requires - list of symbols that are required. These in turn are provided by other packages. filename - name of the file. size - size of the file (aka the bundled package) md5sum - computed md5 checksum description - What this package is for. type - Whether this is a 'binary (default) or 'single file package More fields may be added as needed. An example: '( (name (version \"\" file \"filename\" description \"what this package is about.\" provides () requires () size md5sum \"\" file \"filename\" description \"what this package is about.\" provides () requires () size md5sum \" (if (stringp installed) (string-to-number installed) installed) (if (stringp latest) (string-to-number latest) latest)) (if (not (null version)) (warn "Installing %s package version %s, you had a newer version %s" package latest installed) (warn "Skipping %s package, you have a newer version %s" package installed) (throw 'skip-update t)))) ;; Contrive a list of possible package filenames. ;; Ugly. Is there a better way to do this? (setq filenames (cons base-filename nil)) (if (string-match "^\\(..*\\)\.tar\.gz$" base-filename) (setq filenames (append filenames (list (concat (match-string 1 base-filename) ".tgz"))))) (setq version latest) (unless (and (eq conflict 'never) (package-get-installedp package version)) ;; Find the package from the search list in package-get-remote ;; and copy it into the staging directory. Then validate ;; the checksum. Finally, install the package. (catch 'done (let (search-filenames host dir current-filename dest-filename) ;; In each search directory ... (when search-dir (setq host (car search-dir) dir (car (cdr search-dir)) search-filenames filenames) ;; Look for one of the possible package filenames ... (while search-filenames (setq current-filename (car search-filenames) dest-filename (package-get-staging-dir current-filename)) (cond ;; No host means look on the current system. ((null host) (setq full-package-filename (substitute-in-file-name (expand-file-name current-filename (file-name-as-directory dir))))) ;; If it's already on the disk locally, and the size is ;; correct ((and (file-exists-p dest-filename) (eq (nth 7 (file-attributes dest-filename)) (package-get-info package 'size))) (setq full-package-filename dest-filename)) ;; If the file exists on the remote system ... ((file-exists-p (package-get-remote-filename search-dir current-filename)) ;; Get it (setq full-package-filename dest-filename) (message "Retrieving package `%s' ..." current-filename) (sit-for 0) (copy-file (package-get-remote-filename search-dir current-filename) full-package-filename t))) ;; If we found it, we're done. (if (and full-package-filename (file-exists-p full-package-filename)) (throw 'done nil)) ;; Didn't find it. Try the next possible filename. (setq search-filenames (cdr search-filenames)))))) (if (or (not full-package-filename) (not (file-exists-p full-package-filename))) (if package-get-remote (error 'search-failed (format "Unable to find file %s" base-filename)) (error 'syntax-error "No download sites or local package locations specified."))) ;; Validate the md5 checksum ;; Doing it with XEmacs removes the need for an external md5 program (message "Validating checksum for `%s'..." package) (sit-for 0) (with-temp-buffer (insert-file-contents-literally full-package-filename) (if (not (string= (md5 (current-buffer)) (package-get-info-prop this-package 'md5sum))) (progn (delete-file full-package-filename) (error 'process-error (format "Package %s does not match md5 checksum %s has been deleted" base-filename full-package-filename))))) (package-admin-delete-binary-package package install-dir) (message "Installing package `%s' ..." package) (sit-for 0) (let ((status (package-admin-add-binary-package full-package-filename install-dir))) (if (= status 0) (progn ;; clear messages so that only messages from ;; package-get-init-package are seen, below. (clear-message) (if (package-get-init-package (package-admin-get-lispdir install-dir package)) (progn (run-hook-with-args 'package-install-hook package install-dir) (message "Added package `%s'" package) (sit-for 0)) (progn ;; display message only if there isn't already one. (if (not (current-message)) (progn (message "Added package `%s' (errors occurred)" package) (sit-for 0))) (if package-status (setq package-status 'errors))))) (message "Installation of package %s failed." base-filename) (sit-for 0) (switch-to-buffer package-admin-temp-buffer) (delete-file full-package-filename) (setq package-status nil))) (setq found t)) (if (and found package-get-remove-copy) (delete-file full-package-filename)) package-status))) (defun package-get-info-find-package (which name) "Look in WHICH for the package called NAME and return all the info associated with it. See `package-get-base' for info on the format returned. To access fields returned from this, use `package-get-info-version' to return information about particular a version. Use `package-get-info-find-prop' to find particular property from a version returned by `package-get-info-version'." (interactive "xPackage list: \nsPackage Name: ") (if which (if (eq (caar which) name) (cdar which) (if (cdr which) (package-get-info-find-package (cdr which) name))))) (defun package-get-info-version (package version) "In PACKAGE, return the plist associated with a particular VERSION of the package. PACKAGE is typically as returned by `package-get-info-find-package'. If VERSION is nil, then return the first (aka most recent) version. Use `package-get-info-find-prop' to retrieve a particular property from the value returned by this." (interactive (package-get-interactive-package-query t t)) (while (and version package (not (string= (plist-get (car package) 'version) version))) (setq package (cdr package))) (if package (car package))) (defun package-get-info-prop (package-version property) "In PACKAGE-VERSION, return the value associated with PROPERTY. PACKAGE-VERSION is typically returned by `package-get-info-version' and PROPERTY is typically (although not limited to) one of the following: version - version of this package provides - list of symbols provided requires - list of symbols that are required. These in turn are provided by other packages. size - size of the bundled package md5sum - computed md5 checksum" (interactive "xPackage Version: \nSProperty") (plist-get package-version property)) (defun package-get-info-version-prop (package-list package version property) "In PACKAGE-LIST, search for PACKAGE with this VERSION and return PROPERTY value." (package-get-info-prop (package-get-info-version (package-get-info-find-package package-list package) version) property)) (defun package-get-staging-dir (filename) "Return a good place to stash FILENAME when it is retrieved. Use `package-get-dir' for directory to store stuff. Creates `package-get-dir' if it doesn't exist." (interactive "FPackage filename: ") (if (not (file-exists-p package-get-dir)) (make-directory package-get-dir)) (expand-file-name (file-name-nondirectory (or (and (fboundp 'efs-ftp-path) (nth 2 (efs-ftp-path filename))) filename)) (file-name-as-directory package-get-dir))) (defun package-get-remote-filename (search filename) "Return FILENAME as a remote filename. It first checks if FILENAME already is a remote filename. If it is not, then it uses the (car search) as the remote site-name and the (cadr search) as the remote-directory and concatenates filename. In other words site-name:remote-directory/filename. If (car search) is nil, (cadr search is interpreted as a local directory). " (if (file-remote-p filename) filename (let ((dir (cadr search))) (concat (when (car search) (concat (if (string-match "@" (car search)) "/" "/anonymous@") (car search) ":")) (if (string-match "/$" dir) dir (concat dir "/")) filename)))) (defun package-get-installedp (package version) "Determine if PACKAGE with VERSION has already been installed. I'm not sure if I want to do this by searching directories or checking some built in variables. For now, use packages-package-list." ;; Use packages-package-list which contains name and version (equal (plist-get (package-get-info-find-package packages-package-list package) ':version) (if (floatp version) version (string-to-number version)))) ;;;###autoload (defun package-get-package-provider (sym &optional force-current) "Search for a package that provides SYM and return the name and version. Searches in `package-get-base' for SYM. If SYM is a consp, then it must match a corresponding (provide (SYM VERSION)) from the package. If FORCE-CURRENT is non-nil make sure the database is up to date. This might lead to Emacs accessing remote sites." (interactive "SSymbol: ") (package-get-require-base force-current) (let ((packages package-get-base) (done nil) (found nil)) (while (and (not done) packages) (let* ((this-name (caar packages)) (this-package (cdr (car packages)))) ;strip off package name (while (and (not done) this-package) (if (or (eq this-name sym) (eq (cons this-name (package-get-info-prop (car this-package) 'version)) sym) (member sym (package-get-info-prop (car this-package) 'provides))) (progn (setq done t) (setq found (list (caar packages) (package-get-info-prop (car this-package) 'version)))) (setq this-package (cdr this-package))))) (setq packages (cdr packages))) (when (interactive-p) (if found (message "%S" found) (message "No appropriate package found"))) found)) (defun package-get-ever-installed-p (pkg &optional notused) (string-match "-package$" (symbol-name pkg)) (custom-initialize-set pkg (if (package-get-info-find-package packages-package-list (intern (substring (symbol-name pkg) 0 (match-beginning 0)))) t))) (provide 'package-get) ;;; package-get.el ends here