1 ;;; package-get.el --- Retrieve XEmacs package
3 ;; Copyright (C) 1998 by Pete Ware
5 ;; Author: Pete Ware <ware@cis.ohio-state.edu>
6 ;; Heavy-Modifications: Greg Klanderman <greg@alphatech.com>
7 ;; Jan Vroonhof <vroonhof@math.ethz.ch>
10 ;; This file is part of XEmacs.
12 ;; XEmacs is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; XEmacs is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 ;;; Synched up with: Not in FSF
32 ;; Retrieve a package and any other required packages from an archive
35 ;; Note (JV): Most of this no longer applies!
38 ;; A new XEmacs lisp-only release is generated with the following steps:
39 ;; 1. The maintainer runs some yet to be written program that
40 ;; generates all the dependency information. This should
41 ;; determine all the require and provide statements and associate
42 ;; them with a package.
43 ;; 2. All the packages are then bundled into their own tar balls
44 ;; (or whatever format)
45 ;; 3. Maintainer automatically generates a new `package-get-base'
46 ;; data structure which contains information such as the
47 ;; package name, the file to be retrieved, an md5 checksum,
48 ;; etc (see `package-get-base').
49 ;; 4. The maintainer posts an announcement with the new version
50 ;; of `package-get-base'.
51 ;; 5. A user/system manager saves this posting and runs
52 ;; `package-get-update' which uses the previously saved list
53 ;; of packages, `package-get-here' that the user/site
54 ;; wants to determine what new versions to download and
57 ;; A user/site manager can generate a new `package-get-here' structure
58 ;; by using `package-get-setup' which generates a customize like
59 ;; interface to the list of packages. The buffer looks something
62 ;; gnus - a mail and news reader
65 ;; [] Required by other [packages]
71 ;; [] Required by other [packages]
73 ;; Where `[]' indicates a toggle box
75 ;; - Clicking on "Always install" puts this into
76 ;; `package-get-here' list. "Needs updating" indicates a new
77 ;; version is available. Anything already in
78 ;; `package-get-here' has this enabled.
79 ;; - "Required by other" means some other packages are going to force
80 ;; this to be installed. Clicking on [packages] gives a list
81 ;; of packages that require this.
83 ;; The `package-get-base' should be installed in a file in
84 ;; `data-directory'. The `package-get-here' should be installed in
85 ;; site-lisp. Both are then read at run time.
88 ;; - Implement `package-get-setup'
89 ;; - Actually put `package-get-base' and `package-get-here' into
90 ;; files that are read.
91 ;; - Allow users to have their own packages that they want installed
93 ;; - SOMEONE needs to write the programs that generate the
94 ;; provides/requires database and makes it into a lisp data
95 ;; structure suitable for `package-get-base'
96 ;; - Handle errors such as no package providing a required symbol.
97 ;; - Tie this into the `require' function to download packages
104 (require 'package-admin)
105 ;; (require 'package-get-base)
107 (defgroup package-tools nil
108 "Tools to manipulate packages."
111 (defgroup package-get nil
112 "Automatic Package Fetcher and Installer."
113 :prefix "package-get"
114 :group 'package-tools)
117 (defvar package-get-base nil
118 "List of packages that are installed at this site.
119 For each element in the alist, car is the package name and the cdr is
120 a plist containing information about the package. Typical fields
121 kept in the plist are:
123 version - version of this package
124 provides - list of symbols provided
125 requires - list of symbols that are required.
126 These in turn are provided by other packages.
127 filename - name of the file.
128 size - size of the file (aka the bundled package)
129 md5sum - computed md5 checksum
130 description - What this package is for.
131 type - Whether this is a 'binary (default) or 'single file package
133 More fields may be added as needed. An example:
137 (version \"<version 2>\"
139 description \"what this package is about.\"
146 (version \"<version 1>\"
148 description \"what this package is about.\"
158 For version information, it is assumed things are listed in most
159 recent to least recent -- in other words, the version names don't have to
160 be lexically ordered. It is debatable if it makes sense to have more than
161 one version of a package available.")
163 (defcustom package-get-dir (temp-directory)
164 "*Where to store temporary files for staging."
165 :tag "Temporary directory"
169 (define-widget 'host-name 'string
173 (defcustom package-get-remote nil
174 "*List of remote sites to contact for downloading packages.
175 List format is '(site-name directory-on-site). Each site is tried in
176 order until the package is found. As a special case, `site-name' can be
177 `nil', in which case `directory-on-site' is treated as a local directory."
178 :tag "Package repository"
179 :type '(repeat (choice (list :tag "Local" (const :tag "Local" nil) directory )
180 (list :tag "Remote" host-name directory) ))
184 (defcustom package-get-download-sites
187 ("Pre-Releases" "ftp.xemacs.org" "pub/xemacs/beta/experimental/packages")
188 ("xemacs.org" "ftp.xemacs.org" "pub/xemacs/packages")
189 ("ca.xemacs.org (Canada)" "ftp.ca.xemacs.org" "pub/Mirror/xemacs/packages")
190 ("crc.ca (Canada)" "ftp.crc.ca" "pub/packages/editors/xemacs/packages")
191 ("us.xemacs.org (United States)" "ftp.us.xemacs.org" "pub/xemacs/packages")
192 ("ibiblio.org (United States)" "ibiblio.org" "pub/packages/editors/xemacs/packages")
193 ("stealth.net (United States)" "ftp.stealth.net" "pub/mirrors/ftp.xemacs.org/pub/xemacs/packages")
194 ;("uiuc.edu (United States)" "uiarchive.uiuc.edu" "pub/packages/xemacs/packages")
197 ("br.xemacs.org (Brazil)" "ftp.br.xemacs.org" "pub/xemacs/packages")
200 ("at.xemacs.org (Austria)" "ftp.at.xemacs.org" "editors/xemacs/packages")
201 ("be.xemacs.org (Belgium)" "ftp.be.xemacs.org" "xemacs/packages")
202 ("cz.xemacs.org (Czech Republic)" "ftp.cz.xemacs.org" "MIRRORS/ftp.xemacs.org/pub/xemacs/packages")
203 ("dk.xemacs.org (Denmark)" "ftp.dk.xemacs.org" "pub/emacs/xemacs/packages")
204 ("fi.xemacs.org (Finland)" "ftp.fi.xemacs.org" "pub/mirrors/ftp.xemacs.org/pub/tux/xemacs/packages")
205 ("fr.xemacs.org (France)" "ftp.fr.xemacs.org" "pub/xemacs/packages")
206 ("pasteur.fr (France)" "ftp.pasteur.fr" "pub/computing/xemacs/packages")
207 ("de.xemacs.org (Germany)" "ftp.de.xemacs.org" "pub/ftp.xemacs.org/tux/xemacs/packages")
208 ("tu-darmstadt.de (Germany)" "ftp.tu-darmstadt.de" "pub/editors/xemacs/packages")
209 ;("hu.xemacs.org (Hungary)" "ftp.hu.xemacs.org" "pub/packages/xemacs/packages")
210 ("ie.xemacs.org (Ireland)" "ftp.ie.xemacs.org" "mirrors/ftp.xemacs.org/pub/xemacs/packages")
211 ("it.xemacs.org (Italy)" "ftp.it.xemacs.org" "unix/packages/XEMACS/packages")
212 ("no.xemacs.org (Norway)" "ftp.no.xemacs.org" "pub/xemacs/packages")
213 ("pl.xemacs.org (Poland)" "ftp.pl.xemacs.org" "pub/unix/editors/xemacs/packages")
214 ("ru.xemacs.org (Russia)" "ftp.ru.xemacs.org" "pub/xemacs/packages")
215 ("sk.xemacs.org (Slovakia)" "ftp.sk.xemacs.org" "pub/mirrors/xemacs/packages")
216 ("se.xemacs.org (Sweden)" "ftp.se.xemacs.org" "pub/gnu/xemacs/packages")
217 ("ch.xemacs.org (Switzerland)" "ftp.ch.xemacs.org" "mirror/xemacs/packages")
218 ("uk.xemacs.org (United Kingdom)" "ftp.uk.xemacs.org" "sites/ftp.xemacs.org/pub/xemacs/packages")
221 ("jp.xemacs.org (Japan)" "ftp.jp.xemacs.org" "pub/GNU/xemacs/packages")
222 ("aist.go.jp (Japan)" "ring.aist.go.jp" "pub/text/xemacs/packages")
223 ("asahi-net.or.jp (Japan)" "ring.asahi-net.or.jp" "pub/text/xemacs/packages")
224 ("dti.ad.jp (Japan)" "ftp.dti.ad.jp" "pub/unix/editor/xemacs/packages")
225 ("jaist.ac.jp (Japan)" "ftp.jaist.ac.jp" "pub/GNU/xemacs/packages")
226 ("nucba.ac.jp (Japan)" "mirror.nucba.ac.jp" "mirror/xemacs/packages")
227 ("sut.ac.jp (Japan)" "sunsite.sut.ac.jp" "pub/archives/packages/xemacs/packages")
228 ("kr.xemacs.org (Korea)" "ftp.kr.xemacs.org" "pub/tools/emacs/xemacs/packages")
229 ;("tw.xemacs.org (Taiwan)" "ftp.tw.xemacs.org" "Editors/xemacs/packages")
232 ("za.xemacs.org (South Africa)" "ftp.za.xemacs.org" "mirrorsites/ftp.xemacs.org/packages")
235 ("sa.xemacs.org (Saudi Arabia)" "ftp.sa.xemacs.org" "pub/mirrors/ftp.xemacs.org/xemacs/packages")
238 ("au.xemacs.org (Australia)" "ftp.au.xemacs.org" "pub/xemacs/packages")
239 ("aarnet.edu.au (Australia)" "mirror.aarnet.edu.au" "pub/xemacs/packages")
242 ("nz.xemacs.org (New Zealand)" "ftp.nz.xemacs.org" "mirror/ftp.xemacs.org/packages")
244 "*List of remote sites available for downloading packages.
245 List format is '(site-description site-name directory-on-site).
246 SITE-DESCRIPTION is a textual description of the site. SITE-NAME
247 is the internet address of the download site. DIRECTORY-ON-SITE
248 is the directory on the site in which packages may be found.
249 This variable is used to initialize `package-get-remote', the
250 variable actually used to specify package download sites."
251 :tag "Package download sites"
252 :type '(repeat (list (string :tag "Name") host-name directory))
255 (defcustom package-get-remove-copy t
256 "*After copying and installing a package, if this is t, then remove the
257 copy. Otherwise, keep it around."
261 ;; #### it may make sense for this to be a list of names.
262 ;; #### also, should we rename "*base*" to "*index*" or "*db*"?
263 ;; "base" is a pretty poor name.
264 (defcustom package-get-base-filename "package-index.LATEST.pgp"
265 "*Name of the default package-get database file.
266 This may either be a relative path, in which case it is interpreted
267 with respect to `package-get-remote', or an absolute path."
271 (defvar package-get-user-index-filename
272 (paths-construct-path (list user-init-directory package-get-base-filename))
273 "Name for the user-specific location of the package-get database file.")
275 (defcustom package-get-always-update nil
276 "*If Non-nil always make sure we are using the latest package index (base).
277 Otherwise respect the `force-current' argument of `package-get-require-base'."
281 (defcustom package-get-require-signed-base-updates nil
282 "*If set to a non-nil value, require explicit user confirmation for updates
283 to the package-get database which cannot have their signature verified via PGP.
284 When nil, updates which are not PGP signed are allowed without confirmation."
288 (defvar package-get-was-current nil
289 "Non-nil we did our best to fetch a current database.")
292 ;Shouldn't this be in package-ui?
294 (defun package-get-download-menu ()
295 "Build the `Add Download Site' menu."
296 (mapcar (lambda (site)
298 `(if (member (quote ,(cdr site))
300 (setq package-get-remote
301 (delete (quote ,(cdr site))
303 (package-ui-add-site (quote ,(cdr site))))
305 :selected `(member (quote ,(cdr site))
306 package-get-remote)))
307 package-get-download-sites))
310 (defun package-get-require-base (&optional force-current)
311 "Require that a package-get database has been loaded.
312 If the optional FORCE-CURRENT argument or the value of
313 `package-get-always-update' is Non-nil, try to update the database
314 from a location in `package-get-remote'. Otherwise a local copy is used
315 if available and remote access is never done.
317 Please use FORCE-CURRENT only when the user is explictly dealing with packages
318 and remote access is likely in the near future."
319 (setq force-current (or force-current package-get-always-update))
320 (unless (and (boundp 'package-get-base)
322 (or (not force-current) package-get-was-current))
323 (package-get-update-base nil force-current))
324 (if (or (not (boundp 'package-get-base))
325 (not package-get-base))
326 (error "Package-get database not loaded")
327 (setq package-get-was-current force-current)))
329 (defconst package-get-pgp-signed-begin-line "^-----BEGIN PGP SIGNED MESSAGE-----"
330 "Text for start of PGP signed messages.")
331 (defconst package-get-pgp-signature-begin-line "^-----BEGIN PGP SIGNATURE-----"
332 "Text for beginning of PGP signature.")
333 (defconst package-get-pgp-signature-end-line "^-----END PGP SIGNATURE-----"
334 "Text for end of PGP signature.")
337 (defun package-get-update-base-entry (entry)
338 "Update an entry in `package-get-base'."
339 (let ((existing (assq (car entry) package-get-base)))
341 (setcdr existing (cdr entry))
342 (setq package-get-base (cons entry package-get-base))
343 (package-get-custom-add-entry (car entry) (car (cdr entry))))))
345 (defun package-get-locate-file (file &optional nil-if-not-found no-remote)
346 "Locate an existing FILE with respect to `package-get-remote'.
347 If FILE is an absolute path or is not found, simply return FILE.
348 If optional argument NIL-IF-NOT-FOUND is non-nil, return nil
349 if FILE can not be located.
350 If NO-REMOTE is non-nil never search remote locations."
351 (if (file-name-absolute-p file)
353 (let ((entries package-get-remote)
356 (unless (and no-remote (caar entries))
357 (let ((expn (package-get-remote-filename (car entries) file)))
358 (if (and expn (file-exists-p expn))
361 (setq entries (cdr entries)))
363 (and (not nil-if-not-found)
366 (defun package-get-locate-index-file (no-remote)
367 "Locate the package-get index file. Do not return remote paths if NO-REMOTE
369 (or (package-get-locate-file package-get-base-filename t no-remote)
370 (if (file-exists-p package-get-user-index-filename)
371 package-get-user-index-filename)
372 (locate-data-file package-get-base-filename)
373 (error "Can't locate a package index file.")))
375 (defun package-get-maybe-save-index (filename)
376 "Offer to save the current buffer as the local package index file,
378 (let ((location (package-get-locate-index-file t)))
379 (unless (and filename (equal filename location))
380 (unless (and location
381 (equal (md5 (current-buffer))
383 (insert-file-contents-literally location)
384 (md5 (current-buffer)))))
385 (unless (and location (file-writable-p location))
386 (setq location package-get-user-index-filename))
387 (when (y-or-n-p (concat "Update package index in " location "? "))
388 (let ((coding-system-for-write 'binary))
389 (write-file location)))))))
393 (defun package-get-update-base (&optional db-file force-current)
394 "Update the package-get database file with entries from DB-FILE.
395 Unless FORCE-CURRENT is non-nil never try to update the database."
397 (let ((dflt (package-get-locate-index-file nil)))
398 (list (read-file-name "Load package-get database: "
399 (file-name-directory dflt)
402 (file-name-nondirectory dflt)))))
403 (setq db-file (expand-file-name (or db-file
404 (package-get-locate-index-file
405 (not force-current)))))
406 (if (not (file-exists-p db-file))
407 (error "Package-get database file `%s' does not exist" db-file))
408 (if (not (file-readable-p db-file))
409 (error "Package-get database file `%s' not readable" db-file))
410 (let ((buf (get-buffer-create "*package database*")))
415 (insert-file-contents-literally db-file)
416 (package-get-update-base-from-buffer buf)
417 (if (file-remote-p db-file)
418 (package-get-maybe-save-index db-file)))
422 (defun package-get-update-base-from-buffer (&optional buf)
423 "Update the package-get database with entries from BUFFER.
424 BUFFER defaults to the current buffer. This command can be
425 used interactively, for example from a mail or news buffer."
427 (setq buf (or buf (current-buffer)))
428 (let (content-beg content-end beg end)
431 (goto-char (point-min))
432 (setq content-beg (point))
433 (setq content-end (save-excursion (goto-char (point-max)) (point)))
434 (when (re-search-forward package-get-pgp-signed-begin-line nil t)
435 (setq beg (match-beginning 0))
436 (setq content-beg (match-end 0)))
437 (when (re-search-forward package-get-pgp-signature-begin-line nil t)
438 (setq content-end (match-beginning 0)))
439 (when (re-search-forward package-get-pgp-signature-end-line nil t)
441 (if (not (and content-beg content-end beg end))
442 (or (not package-get-require-signed-base-updates)
443 (yes-or-no-p "Package-get entries not PGP signed, continue? ")
444 (error "Package-get database not updated")))
445 (if (and content-beg content-end beg end)
446 (if (not (condition-case nil
447 (or (fboundp 'mc-pgp-verify-region)
448 (load-library "mc-pgp")
449 (fboundp 'mc-pgp-verify-region))
451 (or (not package-get-require-signed-base-updates)
453 "No mailcrypt; can't verify package-get DB signature, continue? ")
454 (error "Package-get database not updated"))))
456 (fboundp 'mc-pgp-verify-region)
459 (mc-pgp-verify-region beg end)
461 (and (string-match "No such file" (nth 2 err))
462 (or (not package-get-require-signed-base-updates)
464 (concat "Can't find PGP, continue without "
465 "package-get DB verification? ")))))
467 (error "Package-get PGP signature failed to verify"))
468 ;; ToDo: We should call package-get-maybe-save-index on the region
469 (package-get-update-base-entries content-beg content-end)
470 (message "Updated package-get database"))))
472 (defun package-get-update-base-entries (start end)
473 "Update the package-get database with the entries found between
474 START and END in the current buffer."
477 (if (not (re-search-forward "^(package-get-update-base-entry" nil t))
478 (error "Buffer does not contain package-get database entries"))
481 (while (and (< (point) end)
482 (re-search-forward "^(package-get-update-base-entry" nil t))
484 (let ((entry (read (current-buffer))))
485 (if (or (not (consp entry))
486 (not (eq (car entry) 'package-get-update-base-entry)))
487 (error "Invalid package-get database entry found"))
488 (package-get-update-base-entry
489 (car (cdr (car (cdr entry)))))
490 (setq count (1+ count))))
491 (message "Got %d package-get database entries" count))))
494 (defun package-get-save-base (file)
495 "Write the package-get database to FILE.
497 Note: This database will be unsigned of course."
498 (interactive "FSave package-get database to: ")
499 (package-get-require-base t)
500 (let ((buf (get-buffer-create "*package database*")))
505 (goto-char (point-min))
506 (let ((entries package-get-base) entry plist)
507 (insert ";; Package Index file -- Do not edit manually.\n")
510 (setq entry (car entries))
511 (setq plist (car (cdr entry)))
512 (insert "(package-get-update-base-entry (quote\n")
513 (insert (format "(%s\n" (symbol-name (car entry))))
515 (insert (format " %s%s %S\n"
516 (if (eq plist (car (cdr entry))) "(" " ")
517 (symbol-name (car plist))
519 (setq plist (cdr (cdr plist))))
520 (insert "))\n))\n;;;@@@\n")
521 (setq entries (cdr entries))))
522 (insert ";; Package Index file ends here\n")
523 (write-region (point-min) (point-max) file))
526 (defun package-get-interactive-package-query (get-version package-symbol)
527 "Perform interactive querying for package and optional version.
528 Query for a version if GET-VERSION is non-nil. Return package name as
529 a symbol instead of a string if PACKAGE-SYMBOL is non-nil.
530 The return value is suitable for direct passing to `interactive'."
531 (package-get-require-base t)
532 (let ((table (mapcar #'(lambda (item)
533 (let ((name (symbol-name (car item))))
536 package package-symbol default-version version)
537 (save-window-excursion
538 (setq package (completing-read "Package: " table nil t))
539 (setq package-symbol (intern package))
542 (setq default-version
543 (package-get-info-prop
544 (package-get-info-version
545 (package-get-info-find-package package-get-base
549 (setq version (read-string "Version: " default-version))
553 (list package-symbol version)
554 (list package version))
557 (list package-symbol)
561 (defun package-get-delete-package (package &optional pkg-topdir)
562 "Delete an installation of PACKAGE below directory PKG-TOPDIR.
563 PACKAGE is a symbol, not a string.
564 This is just an interactive wrapper for `package-admin-delete-binary-package'."
565 (interactive (package-get-interactive-package-query nil t))
566 (package-admin-delete-binary-package package pkg-topdir))
569 (defun package-get-update-all ()
570 "Fetch and install the latest versions of all currently installed packages."
572 (package-get-require-base t)
575 (mapcar (lambda (pkg)
576 (if (not (package-get (car pkg) nil 'never))
577 (throw 'exit nil) ;; Bail out if error detected
579 packages-package-list))
580 (package-net-update-installed-db))
583 (defun package-get-all (package version &optional fetched-packages install-dir)
584 "Fetch PACKAGE with VERSION and all other required packages.
585 Uses `package-get-base' to determine just what is required and what
586 package provides that functionality. If VERSION is nil, retrieves
587 latest version. Optional argument FETCHED-PACKAGES is used to keep
588 track of packages already fetched. Optional argument INSTALL-DIR,
589 if non-nil, specifies the package directory where fetched packages
592 Returns nil upon error."
593 (interactive (package-get-interactive-package-query t nil))
594 (let* ((the-package (package-get-info-find-package package-get-base
596 (this-package (package-get-info-version
597 the-package version))
598 (this-requires (package-get-info-prop this-package 'requires))
601 (setq version (package-get-info-prop this-package 'version))
602 (unless (package-get-installedp package version)
603 (if (not (package-get package version nil install-dir))
605 (setq fetched-packages nil)
607 (setq fetched-packages
608 (append (list package)
609 (package-get-info-prop this-package 'provides)
611 ;; grab everything that this package requires plus recursively
612 ;; grab everything that the requires require. Keep track
613 ;; in `fetched-packages' the list of things provided -- this
614 ;; keeps us from going into a loop
616 (if (not (member (car this-requires) fetched-packages))
617 (let* ((reqd-package (package-get-package-provider
618 (car this-requires) t))
619 (reqd-version (cadr reqd-package))
620 (reqd-name (car reqd-package)))
622 (error "Unable to find a provider for %s"
623 (car this-requires)))
624 (if (not (setq fetched-packages
625 (package-get-all reqd-name reqd-version
630 (setq this-requires (cdr this-requires)))
636 (defun package-get-dependencies (packages)
637 "Compute dependencies for PACKAGES.
638 Uses `package-get-base' to determine just what is required and what
639 package provides that functionality. Returns the list of packages
640 required by PACKAGES."
641 (package-get-require-base t)
642 (let ((orig-packages packages)
643 dependencies provided)
645 (let* ((package (car packages))
646 (the-package (package-get-info-find-package
647 package-get-base package))
648 (this-package (package-get-info-version
650 (this-requires (package-get-info-prop this-package 'requires))
651 (new-depends (set-difference
654 (let* ((reqd-package (package-get-package-provider reqd))
655 (reqd-name (car reqd-package)))
657 (error "Unable to find a provider for %s" reqd))
661 (this-provides (package-get-info-prop this-package 'provides)))
663 (union dependencies new-depends))
665 (union provided (union (list package) this-provides)))
667 (union new-depends (cdr packages)))))
668 (set-difference dependencies orig-packages)))
670 (defun package-get-load-package-file (lispdir file)
672 (setq pathname (expand-file-name file lispdir))
678 (message "Error loading package file \"%s\" %s!" pathname err)
682 (defun package-get-init-package (lispdir)
683 "Initialize the package.
684 This really assumes that the package has never been loaded. Updating
685 a newer package can cause problems, due to old, obsolete functions in
688 Return `t' upon complete success, `nil' if any errors occurred."
691 (file-accessible-directory-p lispdir))
693 ;; Add lispdir to load-path if it doesn't already exist.
694 ;; NOTE: this does not take symlinks, etc., into account.
695 (if (let ( (dirs load-path) )
698 (if (string-equal (car dirs) lispdir)
700 (setq dirs (cdr dirs))
703 (setq load-path (cons lispdir load-path)))
704 (if (not (package-get-load-package-file lispdir "auto-autoloads"))
705 (package-get-load-package-file lispdir "_pkg"))
711 (defun package-get (package &optional version conflict install-dir)
712 "Fetch PACKAGE from remote site.
713 Optional arguments VERSION indicates which version to retrieve, nil
714 means most recent version. CONFLICT indicates what happens if the
715 package is already installed. Valid values for CONFLICT are:
716 'always always retrieve the package even if it is already installed
717 'never do not retrieve the package if it is installed.
718 INSTALL-DIR, if non-nil, specifies the package directory where
719 fetched packages should be installed.
721 The value of `package-get-base' is used to determine what files should
722 be retrieved. The value of `package-get-remote' is used to determine
723 where a package should be retrieved from. The sites are tried in
724 order so one is better off listing easily reached sites first.
726 Once the package is retrieved, its md5 checksum is computed. If that
727 sum does not match that stored in `package-get-base' for this version
728 of the package, an error is signalled.
730 Returns `t' upon success, the symbol `error' if the package was
731 successfully installed but errors occurred during initialization, or
733 (interactive (package-get-interactive-package-query nil t))
736 (package-get-info-version
737 (package-get-info-find-package package-get-base
739 (latest (package-get-info-prop this-package 'version))
740 (installed (package-get-key package :version))
741 (this-requires (package-get-info-prop this-package 'requires))
743 (search-dirs package-get-remote)
744 (base-filename (package-get-info-prop this-package 'filename))
746 filenames full-package-filename)
747 (if (null this-package)
748 (if package-get-remote
749 (error "Couldn't find package %s with version %s"
751 (error "No download sites or local package locations specified.")))
752 (if (null base-filename)
753 (error "No filename associated with package %s, version %s"
756 (package-admin-get-install-dir package install-dir
757 (or (eq package 'mule-base) (memq 'mule-base this-requires))))
759 ;; If they asked for the latest using version=nil, don't get an older
760 ;; version than we already have.
762 (if (> (if (stringp installed)
763 (string-to-number installed)
766 (string-to-number latest)
768 (if (not (null version))
769 (warn "Installing %s package version %s, you had a newer version %s"
770 package latest installed)
771 (warn "Skipping %s package, you have a newer version %s"
773 (throw 'skip-update t))))
775 ;; Contrive a list of possible package filenames.
776 ;; Ugly. Is there a better way to do this?
777 (setq filenames (cons base-filename nil))
778 (if (string-match "^\\(..*\\)\.tar\.gz$" base-filename)
779 (setq filenames (append filenames
780 (list (concat (match-string 1 base-filename)
783 (setq version latest)
784 (unless (and (eq conflict 'never)
785 (package-get-installedp package version))
786 ;; Find the package from the search list in package-get-remote
787 ;; and copy it into the staging directory. Then validate
788 ;; the checksum. Finally, install the package.
790 (let (search-filenames current-dir-entry host dir current-filename
792 ;; In each search directory ...
794 (setq current-dir-entry (car search-dirs)
795 host (car current-dir-entry)
796 dir (car (cdr current-dir-entry))
797 search-filenames filenames
800 ;; Look for one of the possible package filenames ...
801 (while search-filenames
802 (setq current-filename (car search-filenames)
803 dest-filename (package-get-staging-dir current-filename))
805 ;; No host means look on the current system.
807 (setq full-package-filename
808 (substitute-in-file-name
809 (expand-file-name current-filename
810 (file-name-as-directory dir))))
813 ;; If it's already on the disk locally, and the size is
814 ;; greater than zero ...
815 ( (and (file-exists-p dest-filename)
817 ;; file-attributes could return -1 for LARGE files,
818 ;; but, hopefully, packages won't be that large.
819 (and (setq attrs (file-attributes dest-filename))
820 (> (nth 7 attrs) 0))))
821 (setq full-package-filename dest-filename)
824 ;; If the file exists on the remote system ...
825 ( (file-exists-p (package-get-remote-filename
826 current-dir-entry current-filename))
828 (setq full-package-filename dest-filename)
829 (message "Retrieving package `%s' ..."
832 (copy-file (package-get-remote-filename current-dir-entry
834 full-package-filename t)
838 ;; If we found it, we're done.
839 (if (and full-package-filename
840 (file-exists-p full-package-filename))
842 ;; Didn't find it. Try the next possible filename.
843 (setq search-filenames (cdr search-filenames))
845 ;; Try looking in the next possible directory ...
846 (setq search-dirs (cdr search-dirs))
850 (if (or (not full-package-filename)
851 (not (file-exists-p full-package-filename)))
852 (if package-get-remote
853 (error "Unable to find file %s" base-filename)
855 "No download sites or local package locations specified.")))
856 ;; Validate the md5 checksum
857 ;; Doing it with XEmacs removes the need for an external md5 program
858 (message "Validating checksum for `%s'..." package) (sit-for 0)
860 (insert-file-contents-literally full-package-filename)
861 (if (not (string= (md5 (current-buffer))
862 (package-get-info-prop this-package
864 (error "Package %s does not match md5 checksum" base-filename)))
866 (package-admin-delete-binary-package package install-dir)
868 (message "Installing package `%s' ..." package) (sit-for 0)
870 (package-admin-add-binary-package full-package-filename
874 ;; clear messages so that only messages from
875 ;; package-get-init-package are seen, below.
877 (if (package-get-init-package (package-admin-get-lispdir
878 install-dir package))
880 (run-hook-with-args 'package-install-hook package install-dir)
881 (message "Added package `%s'" package)
885 ;; display message only if there isn't already one.
886 (if (not (current-message))
888 (message "Added package `%s' (errors occurred)"
893 (setq package-status 'errors))
896 (message "Installation of package %s failed." base-filename)
898 (switch-to-buffer package-admin-temp-buffer)
899 (setq package-status nil)
902 (if (and found package-get-remove-copy)
903 (delete-file full-package-filename))
907 (defun package-get-info-find-package (which name)
908 "Look in WHICH for the package called NAME and return all the info
909 associated with it. See `package-get-base' for info on the format
912 To access fields returned from this, use
913 `package-get-info-version' to return information about particular a
914 version. Use `package-get-info-find-prop' to find particular property
915 from a version returned by `package-get-info-version'."
916 (interactive "xPackage list: \nsPackage Name: ")
918 (if (eq (caar which) name)
921 (package-get-info-find-package (cdr which) name)))))
923 (defun package-get-info-version (package version)
924 "In PACKAGE, return the plist associated with a particular VERSION of the
925 package. PACKAGE is typically as returned by
926 `package-get-info-find-package'. If VERSION is nil, then return the
927 first (aka most recent) version. Use `package-get-info-find-prop'
928 to retrieve a particular property from the value returned by this."
929 (interactive (package-get-interactive-package-query t t))
930 (while (and version package (not (string= (plist-get (car package) 'version) version)))
931 (setq package (cdr package)))
932 (if package (car package)))
934 (defun package-get-info-prop (package-version property)
935 "In PACKAGE-VERSION, return the value associated with PROPERTY.
936 PACKAGE-VERSION is typically returned by `package-get-info-version'
937 and PROPERTY is typically (although not limited to) one of the
940 version - version of this package
941 provides - list of symbols provided
942 requires - list of symbols that are required.
943 These in turn are provided by other packages.
944 size - size of the bundled package
945 md5sum - computed md5 checksum"
946 (interactive "xPackage Version: \nSProperty")
947 (plist-get package-version property))
949 (defun package-get-info-version-prop (package-list package version property)
950 "In PACKAGE-LIST, search for PACKAGE with this VERSION and return
952 (package-get-info-prop
953 (package-get-info-version
954 (package-get-info-find-package package-list package) version) property))
956 (defun package-get-set-version-prop (package-list package version
958 "A utility to make it easier to add a VALUE for a specific PROPERTY
959 in this VERSION of a specific PACKAGE kept in the PACKAGE-LIST.
960 Returns the modified PACKAGE-LIST. Any missing fields are created."
963 (defun package-get-staging-dir (filename)
964 "Return a good place to stash FILENAME when it is retrieved.
965 Use `package-get-dir' for directory to store stuff.
966 Creates `package-get-dir' if it doesn't exist."
967 (interactive "FPackage filename: ")
968 (if (not (file-exists-p package-get-dir))
969 (make-directory package-get-dir))
971 (file-name-nondirectory (or (and (fboundp 'efs-ftp-path)
972 (nth 2 (efs-ftp-path filename)))
974 (file-name-as-directory package-get-dir)))
976 (defun package-get-remote-filename (search filename)
977 "Return FILENAME as a remote filename.
978 It first checks if FILENAME already is a remote filename. If it is
979 not, then it uses the (car search) as the remote site-name and the (cadr
980 search) as the remote-directory and concatenates filename. In other
982 site-name:remote-directory/filename.
984 If (car search) is nil, (cadr search is interpreted as a local directory).
986 (if (file-remote-p filename)
988 (let ((dir (cadr search)))
989 (concat (when (car search)
991 (if (string-match "@" (car search))
995 (if (string-match "/$" dir)
1001 (defun package-get-installedp (package version)
1002 "Determine if PACKAGE with VERSION has already been installed.
1003 I'm not sure if I want to do this by searching directories or checking
1004 some built in variables. For now, use packages-package-list."
1005 ;; Use packages-package-list which contains name and version
1007 (package-get-info-find-package packages-package-list
1009 (if (floatp version) version (string-to-number version))))
1012 (defun package-get-package-provider (sym &optional force-current)
1013 "Search for a package that provides SYM and return the name and
1014 version. Searches in `package-get-base' for SYM. If SYM is a
1015 consp, then it must match a corresponding (provide (SYM VERSION)) from
1018 If FORCE-CURRENT is non-nil make sure the database is up to date. This might
1019 lead to Emacs accessing remote sites."
1020 (interactive "SSymbol: ")
1021 (package-get-require-base force-current)
1022 (let ((packages package-get-base)
1025 (while (and (not done) packages)
1026 (let* ((this-name (caar packages))
1027 (this-package (cdr (car packages)))) ;strip off package name
1028 (while (and (not done) this-package)
1029 (if (or (eq this-name sym)
1031 (package-get-info-prop (car this-package) 'version))
1034 (package-get-info-prop (car this-package) 'provides)))
1035 (progn (setq done t)
1037 (list (caar packages)
1038 (package-get-info-prop (car this-package) 'version))))
1039 (setq this-package (cdr this-package)))))
1040 (setq packages (cdr packages)))
1041 (when (interactive-p)
1043 (message "%S" found)
1044 (message "No appropriate package found")))
1048 ;; customize interfaces.
1049 ;; The group is in this file so that custom loads includes this file.
1051 (defgroup packages nil
1052 "Configure XEmacs packages."
1056 (defun package-get-custom ()
1057 "Fetch and install the latest versions of all customized packages."
1059 (package-get-require-base t)
1060 (mapcar (lambda (pkg)
1061 (if (eval (intern (concat (symbol-name (car pkg)) "-package")))
1062 (package-get (car pkg) nil))
1065 (package-net-update-installed-db))
1067 (defun package-get-ever-installed-p (pkg &optional notused)
1068 (string-match "-package$" (symbol-name pkg))
1069 (custom-initialize-set
1071 (if (package-get-info-find-package
1072 packages-package-list
1073 (intern (substring (symbol-name pkg) 0 (match-beginning 0))))
1076 (defvar package-get-custom-groups nil
1077 "List of package-get-custom groups")
1079 (defun package-get-custom-add-entry (package props)
1080 (let* ((category (plist-get props 'category))
1081 (group (intern (concat category "-packages")))
1082 (custom-var (intern (concat (symbol-name package) "-package")))
1083 (description (plist-get props 'description)))
1084 (when (not (memq group package-get-custom-groups))
1085 (setq package-get-custom-groups (cons group
1086 package-get-custom-groups))
1087 (eval `(defgroup ,group nil
1088 ,(concat category " package group")
1090 (eval `(defcustom ,custom-var nil
1093 :initialize 'package-get-ever-installed-p
1097 (provide 'package-get)
1098 ;;; package-get.el ends here