1 ;;; package-get.el --- Retrieve XEmacs package
3 ;; Copyright (C) 1998 by Pete Ware
4 ;; Copyright (C) 2002 Ben Wing.
5 ;; Copyright (C) 2003, Steve Youngs
7 ;; Author: Pete Ware <ware@cis.ohio-state.edu>
8 ;; Heavy-Modifications: Greg Klanderman <greg@alphatech.com>
9 ;; Jan Vroonhof <vroonhof@math.ethz.ch>
10 ;; Steve Youngs <youngs@xemacs.org>
13 ;; This file is part of XEmacs.
15 ;; XEmacs is free software; you can redistribute it and/or modify it
16 ;; under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; XEmacs is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with XEmacs; see the file COPYING. If not, write to the Free
27 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 ;;; Synched up with: Not in FSF
35 ;; Retrieve a package and any other required packages from an archive
38 ;; Note (JV): Most of this no longer applies!
41 ;; A new XEmacs lisp-only release is generated with the following steps:
42 ;; 1. The maintainer runs some yet to be written program that
43 ;; generates all the dependency information. This should
44 ;; determine all the require and provide statements and associate
45 ;; them with a package.
46 ;; 2. All the packages are then bundled into their own tar balls
47 ;; (or whatever format)
48 ;; 3. Maintainer automatically generates a new `package-get-base'
49 ;; data structure which contains information such as the
50 ;; package name, the file to be retrieved, an md5 checksum,
51 ;; etc (see `package-get-base').
52 ;; 4. The maintainer posts an announcement with the new version
53 ;; of `package-get-base'.
54 ;; 5. A user/system manager saves this posting and runs
55 ;; `package-get-update' which uses the previously saved list
56 ;; of packages, `package-get-here' that the user/site
57 ;; wants to determine what new versions to download and
60 ;; A user/site manager can generate a new `package-get-here' structure
61 ;; by using `package-get-setup' which generates a customize like
62 ;; interface to the list of packages. The buffer looks something
65 ;; gnus - a mail and news reader
68 ;; [] Required by other [packages]
74 ;; [] Required by other [packages]
76 ;; Where `[]' indicates a toggle box
78 ;; - Clicking on "Always install" puts this into
79 ;; `package-get-here' list. "Needs updating" indicates a new
80 ;; version is available. Anything already in
81 ;; `package-get-here' has this enabled.
82 ;; - "Required by other" means some other packages are going to force
83 ;; this to be installed. Clicking on [packages] gives a list
84 ;; of packages that require this.
86 ;; The `package-get-base' should be installed in a file in
87 ;; `data-directory'. The `package-get-here' should be installed in
88 ;; site-lisp. Both are then read at run time.
91 ;; - Implement `package-get-setup'
92 ;; - Actually put `package-get-base' and `package-get-here' into
93 ;; files that are read.
94 ;; - Allow users to have their own packages that they want installed
96 ;; - SOMEONE needs to write the programs that generate the
97 ;; provides/requires database and makes it into a lisp data
98 ;; structure suitable for `package-get-base'
99 ;; - Handle errors such as no package providing a required symbol.
100 ;; - Tie this into the `require' function to download packages
107 (require 'package-admin)
108 ;; (require 'package-get-base)
110 (defgroup package-tools nil
111 "Tools to manipulate packages."
114 (defgroup package-get nil
115 "Automatic Package Fetcher and Installer."
116 :prefix "package-get"
117 :group 'package-tools)
120 (defvar package-get-base nil
121 "List of packages that are installed at this site.
122 For each element in the alist, car is the package name and the cdr is
123 a plist containing information about the package. Typical fields
124 kept in the plist are:
126 version - version of this package
127 provides - list of symbols provided
128 requires - list of symbols that are required.
129 These in turn are provided by other packages.
130 filename - name of the file.
131 size - size of the file (aka the bundled package)
132 md5sum - computed md5 checksum
133 description - What this package is for.
134 type - Whether this is a 'binary (default) or 'single file package
136 More fields may be added as needed. An example:
140 (version \"<version 2>\"
142 description \"what this package is about.\"
149 (version \"<version 1>\"
151 description \"what this package is about.\"
161 For version information, it is assumed things are listed in most
162 recent to least recent -- in other words, the version names don't have to
163 be lexically ordered. It is debatable if it makes sense to have more than
164 one version of a package available.")
166 (defcustom package-get-dir (temp-directory)
167 "*Where to store temporary files for staging."
168 :tag "Temporary directory"
173 (defcustom package-get-package-index-file-location
174 (car (split-path (or (getenv "EMACSPACKAGEPATH") user-init-directory)))
175 "*The directory where the package-index file can be found."
180 (defcustom package-get-install-to-user-init-directory nil
181 "*If non-nil install packages under `user-init-directory'."
185 (define-widget 'host-name 'string
189 (defcustom package-get-remote nil
190 "*The remote site to contact for downloading packages.
191 Format is '(site-name directory-on-site). As a special case, `site-name'
192 can be `nil', in which case `directory-on-site' is treated as a local
194 :tag "Package repository"
195 :type '(set (choice (const :tag "None" nil)
196 (list :tag "Local" (const :tag "Local" nil) directory)
197 (list :tag "Remote" host-name directory)))
201 (defcustom package-get-download-sites
203 ;; Main XEmacs Site (ftp.xemacs.org)
204 ("US (Main XEmacs Site)"
205 "ftp.xemacs.org" "pub/xemacs/packages")
206 ;; In alphabetical order of Country, our mirrors...
207 ("Australia (aarnet.edu.au)" "mirror.aarnet.edu.au" "pub/xemacs/packages")
208 ("Australia (au.xemacs.org)" "ftp.au.xemacs.org" "pub/xemacs/packages")
209 ("Austria (at.xemacs.org)" "ftp.at.xemacs.org" "editors/xemacs/packages")
210 ("Belgium (be.xemacs.org)" "ftp.be.xemacs.org" "xemacs/packages")
211 ("Brazil (br.xemacs.org)" "ftp.br.xemacs.org" "pub/xemacs/packages")
212 ("Canada (ca.xemacs.org)" "ftp.ca.xemacs.org" "pub/Mirror/xemacs/packages")
213 ("Canada (crc.ca)" "ftp.crc.ca" "pub/packages/editors/xemacs/packages")
214 ("Canada (ualberta.ca)" "sunsite.ualberta.ca" "pub/Mirror/xemacs/packages")
215 ("Czech Republic (cz.xemacs.org)" "ftp.cz.xemacs.org" "MIRRORS/ftp.xemacs.org/pub/xemacs/packages")
216 ("Denmark (dk.xemacs.org)" "ftp.dk.xemacs.org" "pub/emacs/xemacs/packages")
217 ("Finland (fi.xemacs.org)" "ftp.fi.xemacs.org" "pub/mirrors/ftp.xemacs.org/pub/tux/xemacs/packages")
218 ("France (fr.xemacs.org)" "ftp.fr.xemacs.org" "pub/xemacs/packages")
219 ("France (mirror.cict.fr)" "mirror.cict.fr" "xemacs/packages")
220 ("France (pasteur.fr)" "ftp.pasteur.fr" "pub/computing/xemacs/packages")
221 ("Germany (de.xemacs.org)" "ftp.de.xemacs.org" "pub/ftp.xemacs.org/tux/xemacs/packages")
222 ("Germany (tu-darmstadt.de)" "ftp.tu-darmstadt.de" "pub/editors/xemacs/packages")
223 ("Ireland (ie.xemacs.org)" "ftp.ie.xemacs.org" "mirrors/ftp.xemacs.org/pub/xemacs/packages")
224 ("Italy (it.xemacs.org)" "ftp.it.xemacs.org" "unix/packages/XEMACS/packages")
225 ("Japan (aist.go.jp)" "ring.aist.go.jp" "pub/text/xemacs/packages")
226 ("Japan (asahi-net.or.jp)" "ring.asahi-net.or.jp" "pub/text/xemacs/packages")
227 ("Japan (dti.ad.jp)" "ftp.dti.ad.jp" "pub/unix/editor/xemacs/packages")
228 ("Japan (jaist.ac.jp)" "ftp.jaist.ac.jp" "pub/GNU/xemacs/packages")
229 ("Japan (jp.xemacs.org)" "ftp.jp.xemacs.org" "pub/GNU/xemacs/packages")
230 ("Japan (nucba.ac.jp)" "mirror.nucba.ac.jp" "mirror/xemacs/packages")
231 ("Japan (sut.ac.jp)" "sunsite.sut.ac.jp" "pub/archives/packages/xemacs/packages")
232 ("Korea (kr.xemacs.org)" "ftp.kr.xemacs.org" "pub/tools/emacs/xemacs/packages")
233 ("New Zealand (nz.xemacs.org)" "ftp.nz.xemacs.org" "mirror/ftp.xemacs.org/packages")
234 ("Norway (no.xemacs.org)" "ftp.no.xemacs.org" "pub/xemacs/packages")
235 ("Poland (pl.xemacs.org)" "ftp.pl.xemacs.org" "pub/unix/editors/xemacs/packages")
236 ("Russia (ru.xemacs.org)" "ftp.ru.xemacs.org" "pub/xemacs/packages")
237 ("Slovakia (sk.xemacs.org)" "ftp.sk.xemacs.org" "pub/mirrors/xemacs/packages")
238 ("South Africa (za.xemacs.org)" "ftp.za.xemacs.org" "mirrorsites/ftp.xemacs.org/packages")
239 ("Sweden (se.xemacs.org)" "ftp.se.xemacs.org" "pub/gnu/xemacs/packages")
240 ("Switzerland (ch.xemacs.org)" "ftp.ch.xemacs.org" "mirror/xemacs/packages")
241 ("UK (uk.xemacs.org)" "ftp.uk.xemacs.org" "sites/ftp.xemacs.org/pub/xemacs/packages")
242 ("US (ibiblio.org)" "ibiblio.org" "pub/packages/editors/xemacs/packages")
243 ("US (stealth.net)" "ftp.stealth.net" "pub/mirrors/ftp.xemacs.org/pub/xemacs/packages")
244 ("US (unc.edu)" "metalab.unc.edu" "pub/packages/editors/xemacs/packages")
245 ("US (us.xemacs.org)" "ftp.us.xemacs.org" "pub/xemacs/packages")
246 ("US (utk.edu)" "ftp.sunsite.utk.edu" "pub/xemacs/packages")
248 "*List of remote sites available for downloading packages.
249 List format is '(site-description site-name directory-on-site).
250 SITE-DESCRIPTION is a textual description of the site. SITE-NAME
251 is the internet address of the download site. DIRECTORY-ON-SITE
252 is the directory on the site in which packages may be found.
253 This variable is used to initialize `package-get-remote', the
254 variable actually used to specify package download sites."
255 :tag "Package download sites"
256 :type '(repeat (list (string :tag "Name") host-name directory))
260 (defcustom package-get-pre-release-download-sites
262 ;; Main XEmacs Site (ftp.xemacs.org)
263 ("Pre-Releases (Main XEmacs Site)" "ftp.xemacs.org"
264 "pub/xemacs/beta/experimental/packages")
265 ;; In alphabetical order of Country, our mirrors...
266 ("Australia Pre-Releases (aarnet.edu.au)" "mirror.aarnet.edu.au"
267 "pub/xemacs/beta/experimental/packages")
268 ("Australia Pre-Releases (au.xemacs.org)" "ftp.au.xemacs.org"
269 "pub/xemacs/beta/experimental/packages")
270 ("Austria Pre-Releases (at.xemacs.org)" "ftp.at.xemacs.org"
271 "editors/xemacs/beta/experimentsl/packages")
272 ("Brazil Pre-Releases (br.xemacs.org)" "ftp.br.xemacs.org"
273 "pub/xemacs/xemacs-21.5/experimental/packages")
274 ("Canada Pre-Releases (ca.xemacs.org)" "ftp.ca.xemacs.org"
275 "pub/Mirror/xemacs/beta/experimental/packages")
276 ("Canada Pre-Releases (crc.ca)" "ftp.crc.ca"
277 "pub/packages/editors/xemacs/beta/experimental/packages")
278 ("Canada Pre-Releases (ualberta.ca)" "sunsite.ualberta.ca"
279 "pub/Mirror/xemacs/beta/experimental/packages")
280 ("Czech Republic Pre-Releases (cz.xemacs.org)" "ftp.cz.xemacs.org"
281 "MIRRORS/ftp.xemacs.org/pub/xemacs/xemacs-21.5/experimental/packages")
282 ("Denmark Pre-Releases (dk.xemacs.org)" "ftp.dk.xemacs.org"
283 "pub/emacs/xemacs/beta/experimental/packages")
284 ("Finland Pre-Releases (fi.xemacs.org)" "ftp.fi.xemacs.org"
285 "pub/mirrors/ftp.xemacs.org/pub/tux/xemacs/beta/experimental/packages")
286 ("France Pre-Releases (fr.xemacs.org)" "ftp.fr.xemacs.org"
287 "pub/xemacs/beta/experimental/packages")
288 ("France Pre-Releases (mirror.cict.fr)" "mirror.cict.fr"
289 "xemacs/beta/experimental/packages")
290 ("France Pre-Releases (pasteur.fr)" "ftp.pasteur.fr"
291 "pub/computing/xemacs/beta/experimental/packages")
292 ("Germany Pre-Releases (de.xemacs.org)" "ftp.de.xemacs.org"
293 "pub/ftp.xemacs.org/tux/xemacs/beta/experimental/packages")
294 ("Germany Pre-Releases (tu-darmstadt.de)" "ftp.tu-darmstadt.de"
295 "pub/editors/xemacs/beta/experimental/packages")
296 ("Ireland Pre-Releases (ie.xemacs.org)" "ftp.ie.xemacs.org"
297 "mirrors/ftp.xemacs.org/pub/xemacs/beta/experimental/packages")
298 ("Italy Pre-Releases (it.xemacs.org)" "ftp.it.xemacs.org"
299 "unix/packages/XEMACS/beta/experimental/packages")
300 ("Japan Pre-Releases (aist.go.jp)" "ring.aist.go.jp"
301 "pub/text/xemacs/beta/experimental/packages")
302 ("Japan Pre-Releases (asahi-net.or.jp)" "ring.asahi-net.or.jp"
303 "pub/text/xemacs/beta/experimental/packages")
304 ("Japan Pre-Releases (dti.ad.jp)" "ftp.dti.ad.jp"
305 "pub/unix/editor/xemacs/beta/experimental/packages")
306 ("Japan Pre-Releases (jaist.ac.jp)" "ftp.jaist.ac.jp"
307 "pub/GNU/xemacs/beta/experimental/packages")
308 ("Japan Pre-Releases (jp.xemacs.org)" "ftp.jp.xemacs.org"
309 "pub/GNU/xemacs/beta/experimental/packages")
310 ("Japan Pre-Releases (sut.ac.jp)" "sunsite.sut.ac.jp"
311 "pub/archives/packages/xemacs/xemacs-21.5/experimental/packages")
312 ("New Zealand Pre-Releases (nz.xemacs.org)" "ftp.nz.xemacs.org" "mirror/ftp.xemacs.org/packages")
313 ("Norway Pre-Releases (no.xemacs.org)" "ftp.no.xemacs.org"
314 "pub/xemacs/beta/experimental/packages")
315 ("Poland Pre-Releases (pl.xemacs.org)" "ftp.pl.xemacs.org"
316 "pub/unix/editors/xemacs/beta/experimental/packages")
317 ("Russia Pre-Releases (ru.xemacs.org)" "ftp.ru.xemacs.org"
318 "pub/xemacs/beta/experimental/packages")
319 ("Saudi Arabia Pre-Releases (sa.xemacs.org)" "ftp.sa.xemacs.org"
320 "pub/mirrors/ftp.xemacs.org/xemacs/xemacs-21.5/experimental/packages")
321 ("Slovakia Pre-Releases (sk.xemacs.org)" "ftp.sk.xemacs.org"
322 "pub/mirrors/xemacs/beta/experimental/packages")
323 ("South Africa Pre-Releases (za.xemacs.org)" "ftp.za.xemacs.org"
324 "mirrorsites/ftp.xemacs.org/beta/experimental/packages")
325 ("Sweden Pre-Releases (se.xemacs.org)" "ftp.se.xemacs.org"
326 "pub/gnu/xemacs/beta/experimental/packages")
327 ("Switzerland Pre-Releases (ch.xemacs.org)" "ftp.ch.xemacs.org"
328 "mirror/xemacs/beta/experimental/packages")
329 ("UK Pre-Releases (uk.xemacs.org)" "ftp.uk.xemacs.org"
330 "sites/ftp.xemacs.org/pub/xemacs/beta/experimental/packages")
331 ("US Pre-Releases (ibiblio.org)" "ibiblio.org"
332 "pub/packages/editors/xemacs/beta/experimental/packages")
333 ("US Pre-Releases (stealth.net)" "ftp.stealth.net"
334 "pub/mirrors/ftp.xemacs.org/pub/xemacs/beta/experimental/packages")
335 ("US Pre-Releases (unc.edu)" "metalab.unc.edu"
336 "pub/packages/editors/xemacs/beta/experimental/packages")
337 ("US Pre-Releases (us.xemacs.org)" "ftp.us.xemacs.org"
338 "pub/xemacs/beta/experimental/packages")
339 ("US Pre-Releases (utk.edu)" "ftp.sunsite.utk.edu"
340 "pub/xemacs/beta/experimental/packages"))
341 "*List of remote sites available for downloading \"Pre-Release\" packages.
342 List format is '(site-description site-name directory-on-site).
343 SITE-DESCRIPTION is a textual description of the site. SITE-NAME
344 is the internet address of the download site. DIRECTORY-ON-SITE
345 is the directory on the site in which packages may be found.
346 This variable is used to initialize `package-get-remote', the
347 variable actually used to specify package download sites."
348 :tag "Pre-Release Package download sites"
349 :type '(repeat (list (string :tag "Name") host-name directory))
353 (defcustom package-get-site-release-download-sites
355 "*List of remote sites available for downloading \"Site Release\" packages.
356 List format is '(site-description site-name directory-on-site).
357 SITE-DESCRIPTION is a textual description of the site. SITE-NAME
358 is the internet address of the download site. DIRECTORY-ON-SITE
359 is the directory on the site in which packages may be found.
360 This variable is used to initialize `package-get-remote', the
361 variable actually used to specify package download sites."
362 :tag "Site Release Package download sites"
363 :type '(repeat (list (string :tag "Name") host-name directory))
366 (defcustom package-get-remove-copy t
367 "*After copying and installing a package, if this is t, then remove the
368 copy. Otherwise, keep it around."
372 ;; #### it may make sense for this to be a list of names.
373 ;; #### also, should we rename "*base*" to "*index*" or "*db*"?
374 ;; "base" is a pretty poor name.
375 (defcustom package-get-base-filename "package-index.LATEST.gpg"
376 "*Name of the default package-get database file.
377 This may either be a relative path, in which case it is interpreted
378 with respect to `package-get-remote', or an absolute path."
382 (defcustom package-get-always-update nil
383 "*If Non-nil always make sure we are using the latest package index (base).
384 Otherwise respect the `force-current' argument of `package-get-require-base'."
388 (defun package-get-pgp-available-p ()
389 "Checks the availability of Mailcrypt and PGP executable.
391 Returns t if both are found, nil otherwise. As a side effect, set
392 `mc-default-scheme' dependent on the PGP executable found."
394 (when (featurep 'mailcrypt-autoloads)
395 (autoload 'mc-setversion "mc-setversion"))
396 (when (fboundp 'mc-setversion)
397 (cond ((locate-file "gpg" exec-path
398 '("" ".btm" ".bat" ".cmd" ".exe" ".com")
400 (mc-setversion "gpg")
402 ((locate-file "pgpe" exec-path
403 '("" ".btm" ".bat" ".cmd" ".exe" ".com")
405 (mc-setversion "5.0")
407 ((locate-file "pgp" exec-path
408 '("" ".btm" ".bat" ".cmd" ".exe" ".com")
410 (mc-setversion "2.6")
416 (defcustom package-get-require-signed-base-updates nil
417 "*If non-nil, try to verify the package index database via PGP.
419 If nil, no PGP verification is done. If the package index database
420 entries are not PGP signed and this variable is non-nil, require user
421 confirmation to continue with the package-get procedure."
425 (defvar package-entries-are-signed nil
426 "Non-nil when the package index file has been PGP signed.")
428 (defvar package-get-continue-update-base nil
429 "Non-nil update the index even if it hasn't been signed.")
431 (defvar package-get-was-current nil
432 "Non-nil we did our best to fetch a current database.")
435 (defun package-get-require-base (&optional force-current)
436 "Require that a package-get database has been loaded.
437 If the optional FORCE-CURRENT argument or the value of
438 `package-get-always-update' is Non-nil, try to update the database
439 from a location in `package-get-remote'. Otherwise a local copy is used
440 if available and remote access is never done.
442 Please use FORCE-CURRENT only when the user is explictly dealing with packages
443 and remote access is likely in the near future."
444 (setq force-current (or force-current package-get-always-update))
445 (unless (and (boundp 'package-get-base)
447 (or (not force-current) package-get-was-current))
448 (package-get-update-base nil force-current))
449 (if (or (not (boundp 'package-get-base))
450 (not package-get-base))
451 (error 'void-variable
452 "Package-get database not loaded")
453 (setq package-get-was-current force-current)))
455 (defconst package-get-pgp-signed-begin-line "^-----BEGIN PGP SIGNED MESSAGE-----"
456 "Text for start of PGP signed messages.")
457 (defconst package-get-pgp-signature-begin-line "^-----BEGIN PGP SIGNATURE-----"
458 "Text for beginning of PGP signature.")
459 (defconst package-get-pgp-signature-end-line "^-----END PGP SIGNATURE-----"
460 "Text for end of PGP signature.")
463 (defun package-get-update-base-entry (entry)
464 "Update an entry in `package-get-base'."
465 (let ((existing (assq (car entry) package-get-base)))
467 (setcdr existing (cdr entry))
468 (setq package-get-base (cons entry package-get-base)))))
470 (defun package-get-locate-file (file &optional nil-if-not-found no-remote)
471 "Locate an existing FILE with respect to `package-get-remote'.
472 If FILE is an absolute path or is not found, simply return FILE.
473 If optional argument NIL-IF-NOT-FOUND is non-nil, return nil
474 if FILE can not be located.
475 If NO-REMOTE is non-nil never search remote locations."
476 (if (file-name-absolute-p file)
478 (let ((site package-get-remote)
481 (unless (and no-remote (caar (list site)))
482 (let ((expn (package-get-remote-filename (car (list site)) file)))
483 (if (and expn (file-exists-p expn))
487 (and (not nil-if-not-found)
490 (defun package-get-locate-index-file (no-remote)
491 "Locate the package-get index file.
493 Do not return remote paths if NO-REMOTE is non-nil. If the index
494 file doesn't exist in `package-get-package-index-file-location', ask
495 the user if one should be created using the index file in core as a
497 (or (package-get-locate-file package-get-base-filename t no-remote)
498 (if (file-exists-p (expand-file-name package-get-base-filename
499 package-get-package-index-file-location))
500 (expand-file-name package-get-base-filename
501 package-get-package-index-file-location)
502 (if (y-or-n-p (format "No index file, shall I create one in %s? "
503 package-get-package-index-file-location))
507 (find-file-noselect (expand-file-name
508 package-get-base-filename
509 package-get-package-index-file-location)))
510 (let ((coding-system-for-write 'binary))
512 (insert-file-contents-literally
513 (locate-data-file package-get-base-filename))
514 (save-buffer (current-buffer))
515 (kill-buffer (current-buffer))))
516 (expand-file-name package-get-base-filename
517 package-get-package-index-file-location))
518 (error 'search-failed
519 "Can't locate a package index file.")))))
521 (defun package-get-maybe-save-index (filename)
522 "Offer to save the current buffer as the local package index file,
524 (let ((location (package-get-locate-index-file t)))
525 (unless (and filename (equal filename location))
526 (unless (and location
527 (equal (md5 (current-buffer))
529 (insert-file-contents-literally location)
530 (md5 (current-buffer)))))
531 (when (not (file-writable-p location))
532 (if (y-or-n-p (format "Sorry, %s is read-only, can I use %s? "
533 location user-init-directory))
534 (setq location (expand-file-name
535 package-get-base-filename
536 package-get-package-index-file-location))
538 (format "%s is read-only" location))))
539 (when (y-or-n-p (concat "Update package index in " location "? "))
540 (let ((coding-system-for-write 'binary))
541 (write-file location)))))))
544 (defun package-get-update-base (&optional db-file force-current)
545 "Update the package-get database file with entries from DB-FILE.
546 Unless FORCE-CURRENT is non-nil never try to update the database."
548 (let ((dflt (package-get-locate-index-file nil)))
549 (list (read-file-name "Load package-get database: "
550 (file-name-directory dflt)
553 (file-name-nondirectory dflt)))))
554 (setq db-file (expand-file-name (or db-file
555 (package-get-locate-index-file
556 (not force-current)))))
557 (if (not (file-exists-p db-file))
559 (format "Package-get database file `%s' does not exist" db-file)))
560 (if (not (file-readable-p db-file))
562 (format "Package-get database file `%s' not readable" db-file)))
563 (let ((buf (get-buffer-create "*package database*")))
568 (insert-file-contents-literally db-file)
569 (package-get-update-base-from-buffer buf)
570 (if (file-remote-p db-file)
571 (package-get-maybe-save-index db-file)))
574 ;; This is here because the `process-error' datum doesn't exist in
576 (define-error 'process-error "Process error")
579 (defun package-get-update-base-from-buffer (&optional buf)
580 "Update the package-get database with entries from BUFFER.
581 BUFFER defaults to the current buffer. This command can be
582 used interactively, for example from a mail or news buffer."
584 (setq buf (or buf (current-buffer)))
585 (let ((coding-system-for-read 'binary)
586 (coding-system-for-write 'binary)
587 content-beg content-end)
590 (goto-char (point-min))
591 (setq content-beg (point))
592 (setq content-end (save-excursion (goto-char (point-max)) (point)))
593 (when (re-search-forward package-get-pgp-signed-begin-line nil t)
594 (setq content-beg (match-end 0)))
595 (when (re-search-forward package-get-pgp-signature-begin-line nil t)
596 (setq content-end (match-beginning 0))
597 (setq package-entries-are-signed t))
598 (re-search-forward package-get-pgp-signature-end-line nil t)
599 (setq package-get-continue-update-base t)
600 ;; This is a little overkill because the default value of
601 ;; `package-get-require-signed-base-updates' is the return of
602 ;; `package-get-pgp-available-p', but we have to allow for
603 ;; someone explicitly setting
604 ;; `package-get-require-signed-base-updates' to t. --SY
605 (when (and package-get-require-signed-base-updates
606 (package-get-pgp-available-p))
607 (if package-entries-are-signed
609 (setq package-get-continue-update-base nil)
610 (autoload 'mc-verify "mc-toplev")
614 (setq package-get-continue-update-base t)
615 (error 'process-error
616 "GnuPG error. Package database not updated")))
618 "Package Index is not PGP signed. Continue anyway? ")
619 (setq package-get-continue-update-base t)
620 (setq package-get-continue-update-base nil)
621 (warn "Package database not updated"))))
622 ;; ToDo: We should call package-get-maybe-save-index on the region
623 (when package-get-continue-update-base
624 (package-get-update-base-entries content-beg content-end)
625 (message "Updated package database")))))
627 (defun package-get-update-base-entries (start end)
628 "Update the package-get database with the entries found between
629 START and END in the current buffer."
632 (if (not (re-search-forward "^(package-get-update-base-entry" nil t))
633 (error 'search-failed
634 "Buffer does not contain package-get database entries"))
637 (while (and (< (point) end)
638 (re-search-forward "^(package-get-update-base-entry" nil t))
640 (let ((entry (read (current-buffer))))
641 (if (or (not (consp entry))
642 (not (eq (car entry) 'package-get-update-base-entry)))
644 "Invalid package-get database entry found"))
645 (package-get-update-base-entry
646 (car (cdr (car (cdr entry)))))
647 (setq count (1+ count))))
648 (message "Got %d package-get database entries" count))))
651 (defun package-get-save-base (file)
652 "Write the package-get database to FILE.
654 Note: This database will be unsigned of course."
655 (interactive "FSave package-get database to: ")
656 (package-get-require-base t)
657 (let ((buf (get-buffer-create "*package database*")))
662 (goto-char (point-min))
663 (let ((entries package-get-base) entry plist)
664 (insert ";; Package Index file -- Do not edit manually.\n")
667 (setq entry (car entries))
668 (setq plist (car (cdr entry)))
669 (insert "(package-get-update-base-entry (quote\n")
670 (insert (format "(%s\n" (symbol-name (car entry))))
672 (insert (format " %s%s %S\n"
673 (if (eq plist (car (cdr entry))) "(" " ")
674 (symbol-name (car plist))
676 (setq plist (cdr (cdr plist))))
677 (insert "))\n))\n;;;@@@\n")
678 (setq entries (cdr entries))))
679 (insert ";; Package Index file ends here\n")
680 (write-region (point-min) (point-max) file))
683 (defun package-get-interactive-package-query (get-version package-symbol)
684 "Perform interactive querying for package and optional version.
685 Query for a version if GET-VERSION is non-nil. Return package name as
686 a symbol instead of a string if PACKAGE-SYMBOL is non-nil.
687 The return value is suitable for direct passing to `interactive'."
688 (package-get-require-base t)
689 (let ((table (mapcar #'(lambda (item)
690 (let ((name (symbol-name (car item))))
693 package package-symbol default-version version)
694 (save-window-excursion
695 (setq package (completing-read "Package: " table nil t))
696 (setq package-symbol (intern package))
699 (setq default-version
700 (package-get-info-prop
701 (package-get-info-version
702 (package-get-info-find-package package-get-base
706 (setq version (read-string "Version: " default-version))
709 (list package-symbol version)
710 (list package version)))
712 (list package-symbol)
716 (defun package-get-delete-package (package &optional pkg-topdir)
717 "Delete an installation of PACKAGE below directory PKG-TOPDIR.
718 PACKAGE is a symbol, not a string.
719 This is just an interactive wrapper for `package-admin-delete-binary-package'."
720 (interactive (package-get-interactive-package-query nil t))
721 (package-admin-delete-binary-package package pkg-topdir))
724 (defun package-get-update-all ()
725 "Fetch and install the latest versions of all currently installed packages."
727 (package-get-require-base t)
730 (mapcar (lambda (pkg)
731 (if (not (package-get (car pkg) nil 'never))
732 (throw 'exit nil))) ;; Bail out if error detected
733 packages-package-list))
734 (package-net-update-installed-db))
737 (defun package-get-all (package version &optional fetched-packages install-dir)
738 "Fetch PACKAGE with VERSION and all other required packages.
739 Uses `package-get-base' to determine just what is required and what
740 package provides that functionality. If VERSION is nil, retrieves
741 latest version. Optional argument FETCHED-PACKAGES is used to keep
742 track of packages already fetched. Optional argument INSTALL-DIR,
743 if non-nil, specifies the package directory where fetched packages
746 Returns nil upon error."
747 (interactive (package-get-interactive-package-query t nil))
748 (let* ((the-package (package-get-info-find-package package-get-base
750 (this-package (package-get-info-version
751 the-package version))
752 (this-requires (package-get-info-prop this-package 'requires)))
754 (setq version (package-get-info-prop this-package 'version))
755 (unless (package-get-installedp package version)
756 (if (not (package-get package version nil install-dir))
758 (setq fetched-packages nil)
760 (setq fetched-packages
761 (append (list package)
762 (package-get-info-prop this-package 'provides)
764 ;; grab everything that this package requires plus recursively
765 ;; grab everything that the requires require. Keep track
766 ;; in `fetched-packages' the list of things provided -- this
767 ;; keeps us from going into a loop
769 (if (not (member (car this-requires) fetched-packages))
770 (let* ((reqd-package (package-get-package-provider
771 (car this-requires) t))
772 (reqd-version (cadr reqd-package))
773 (reqd-name (car reqd-package)))
775 (error 'search-failed
776 (format "Unable to find a provider for %s"
777 (car this-requires))))
778 (if (not (setq fetched-packages
779 (package-get-all reqd-name reqd-version
783 (setq this-requires (cdr this-requires))))
787 (defun package-get-dependencies (packages)
788 "Compute dependencies for PACKAGES.
789 Uses `package-get-base' to determine just what is required and what
790 package provides that functionality. Returns the list of packages
791 required by PACKAGES."
792 (package-get-require-base t)
793 (let ((orig-packages packages)
794 dependencies provided)
796 (let* ((package (car packages))
797 (the-package (package-get-info-find-package
798 package-get-base package))
799 (this-package (package-get-info-version
801 (this-requires (package-get-info-prop this-package 'requires))
802 (new-depends (set-difference
805 (let* ((reqd-package (package-get-package-provider reqd))
806 (reqd-name (car reqd-package)))
808 (error 'search-failed
809 (format "Unable to find a provider for %s" reqd)))
813 (this-provides (package-get-info-prop this-package 'provides)))
815 (union dependencies new-depends))
817 (union provided (union (list package) this-provides)))
819 (union new-depends (cdr packages)))))
820 (set-difference dependencies orig-packages)))
822 (defun package-get-load-package-file (lispdir file)
824 (setq pathname (expand-file-name file lispdir))
830 (message "Error loading package file \"%s\" %s!" pathname err)
834 (defun package-get-init-package (lispdir)
835 "Initialize the package.
836 This really assumes that the package has never been loaded. Updating
837 a newer package can cause problems, due to old, obsolete functions in
840 Return `t' upon complete success, `nil' if any errors occurred."
843 (file-accessible-directory-p lispdir))
845 ;; Add lispdir to load-path if it doesn't already exist.
846 ;; NOTE: this does not take symlinks, etc., into account.
847 (if (let ((dirs load-path))
850 (if (string-equal (car dirs) lispdir)
852 (setq dirs (cdr dirs)))
854 (setq load-path (cons lispdir load-path)))
855 (if (not (package-get-load-package-file lispdir "auto-autoloads"))
856 (package-get-load-package-file lispdir "_pkg"))
861 (defun package-get-info (package information &optional arg remote)
862 "Get information about a package.
864 Quite similar to `package-get-info-prop', but can retrieve a lot more
867 Argument PACKAGE is the name of an XEmacs package (a symbol). It must
868 be a valid package, ie, a member of `package-get-base'.
870 Argument INFORMATION is a symbol that can be any one of:
872 standards-version Package system version (not used).
873 version Version of the XEmacs package.
874 author-version The upstream version of the package.
875 date The date the package was last modified.
876 build-date The date the package was last built.
877 maintainer The maintainer of the package.
878 distribution Will always be \"xemacs\" (not used).
879 priority \"low\", \"medium\", or \"high\" (not used).
880 category Either \"standard\", \"mule\", or \"unsupported\"..
881 dump Is the package dumped (not used).
882 description A description of the package.
883 filename The filename of the binary tarball of the package.
884 md5sum The md5sum of filename.
885 size The size in bytes of filename.
886 provides A list of symbols that this package provides.
887 requires A list of packages that this package requires.
888 type Can be either \"regular\" or \"single-file\".
890 If optional argument ARG is non-nil insert INFORMATION into current
891 buffer at point. This is very useful for doing things like inserting
892 a maintainer's email address into a mail buffer.
894 If optional argument REMOTE is non-nil use a package list from a
895 remote site. For this to work `package-get-remote' must be non-nil.
897 If this function is called interactively it will display INFORMATION
899 (interactive "SPackage: \nSInfo: \nP")
901 (package-get-require-base t)
902 (package-get-require-base nil))
903 (let ((all-pkgs package-get-base)
905 (loop until (equal package (caar all-pkgs))
906 do (setq all-pkgs (cdr all-pkgs))
907 do (if (not all-pkgs)
908 (error 'invalid-argument
909 (format "%s is not a valid package" package))))
910 (setq info (plist-get (cadar all-pkgs) information))
913 (insert (format "%s" info))
914 (if (package-get-key package :version)
916 (message "%s (Package: %s is not installed)" info package)))
918 (insert (format "%s" info))
922 (defun package-get-list-packages-where (item field &optional arg)
923 "Return a list of packages that fulfill certain criteria.
925 Argument ITEM, a symbol, is what you want to check for. ITEM must be a
926 symbol even when it doesn't make sense to be a symbol \(think, searching
927 maintainers, descriptions, etc\). The function will convert the symbol
928 to a string if a string is what is needed. The downside to this is that
929 ITEM can only ever be a single word.
931 Argument FIELD, a symbol, is the field to check in. You can specify
934 Field Sane or Allowable Content
935 description any single word
936 category `standard' or `mule'
937 maintainer any single word
938 build-date yyyy-mm-dd
940 type `regular' or `single'
941 requires any package name
943 priority `low', `medium', or `high'
945 Optional Argument ARG, a prefix arg, insert output at point in the
947 (interactive "SList packages that have (item): \nSin their (field): \nP")
948 (package-get-require-base nil)
949 (let ((pkgs package-get-base)
950 (strings '(description category maintainer build-date date))
951 (symbols '(type requires provides priority))
953 (cond ((memq field strings)
954 (setq item (symbol-name item))
956 (when (string-match item (package-get-info (caar pkgs) field))
957 (setq results (push (caar pkgs) results)))
958 (setq pkgs (cdr pkgs))))
959 ((memq field symbols)
960 (if (or (eq field 'type)
961 (eq field 'priority))
963 (when (eq item (package-get-info (caar pkgs) field))
964 (setq results (push (caar pkgs) results)))
965 (setq pkgs (cdr pkgs)))
967 (when (memq item (package-get-info (caar pkgs) field))
968 (setq results (push (caar pkgs) results)))
969 (setq pkgs (cdr pkgs)))))
971 (error 'wrong-type-argument field)))
974 (insert (format "%s" results))
975 (message "%s" results)))
979 (defun package-get (package &optional version conflict install-dir)
980 "Fetch PACKAGE from remote site.
981 Optional arguments VERSION indicates which version to retrieve, nil
982 means most recent version. CONFLICT indicates what happens if the
983 package is already installed. Valid values for CONFLICT are:
984 'always always retrieve the package even if it is already installed
985 'never do not retrieve the package if it is installed.
986 INSTALL-DIR, if non-nil, specifies the package directory where
987 fetched packages should be installed.
989 The value of `package-get-base' is used to determine what files should
990 be retrieved. The value of `package-get-remote' is used to determine
991 where a package should be retrieved from.
993 Once the package is retrieved, its md5 checksum is computed. If that
994 sum does not match that stored in `package-get-base' for this version
995 of the package, an error is signalled.
997 Returns `t' upon success, the symbol `error' if the package was
998 successfully installed but errors occurred during initialization, or
1000 (interactive (package-get-interactive-package-query nil t))
1002 (let* ((this-package
1003 (package-get-info-version
1004 (package-get-info-find-package package-get-base
1006 (latest (package-get-info-prop this-package 'version))
1007 (installed (package-get-key package :version))
1009 (search-dir package-get-remote)
1010 (base-filename (package-get-info-prop this-package 'filename))
1012 filenames full-package-filename)
1013 (if (and (equal (package-get-info package 'category) "mule")
1014 (not (featurep 'mule)))
1015 (error 'invalid-state
1016 "Mule packages can't be installed with a non-Mule XEmacs"))
1017 (if (null this-package)
1018 (if package-get-remote
1019 (error 'search-failed
1020 (format "Couldn't find package %s with version %s"
1022 (error 'syntax-error
1023 "No download site or local package location specified.")))
1024 (if (null base-filename)
1025 (error 'syntax-error
1026 (format "No filename associated with package %s, version %s"
1028 (setq install-dir (package-admin-get-install-dir package install-dir))
1030 ;; If they asked for the latest using version=nil, don't get an older
1031 ;; version than we already have.
1033 (if (> (if (stringp installed)
1034 (string-to-number installed)
1036 (if (stringp latest)
1037 (string-to-number latest)
1039 (if (not (null version))
1040 (warn "Installing %s package version %s, you had a newer version %s"
1041 package latest installed)
1042 (warn "Skipping %s package, you have a newer version %s"
1044 (throw 'skip-update t))))
1046 ;; Contrive a list of possible package filenames.
1047 ;; Ugly. Is there a better way to do this?
1048 (setq filenames (cons base-filename nil))
1049 (if (string-match "^\\(..*\\)\.tar\.gz$" base-filename)
1050 (setq filenames (append filenames
1051 (list (concat (match-string 1 base-filename)
1054 (setq version latest)
1055 (unless (and (eq conflict 'never)
1056 (package-get-installedp package version))
1057 ;; Find the package from the search list in package-get-remote
1058 ;; and copy it into the staging directory. Then validate
1059 ;; the checksum. Finally, install the package.
1061 (let (search-filenames host dir current-filename dest-filename)
1062 ;; In each search directory ...
1064 (setq host (car search-dir)
1065 dir (car (cdr search-dir))
1066 search-filenames filenames)
1068 ;; Look for one of the possible package filenames ...
1069 (while search-filenames
1070 (setq current-filename (car search-filenames)
1071 dest-filename (package-get-staging-dir current-filename))
1073 ;; No host means look on the current system.
1075 (setq full-package-filename
1076 (substitute-in-file-name
1077 (expand-file-name current-filename
1078 (file-name-as-directory dir)))))
1080 ;; If it's already on the disk locally, and the size is
1082 ((and (file-exists-p dest-filename)
1083 (eq (nth 7 (file-attributes dest-filename))
1084 (package-get-info package 'size)))
1085 (setq full-package-filename dest-filename))
1087 ;; If the file exists on the remote system ...
1088 ((file-exists-p (package-get-remote-filename
1089 search-dir current-filename))
1091 (setq full-package-filename dest-filename)
1092 (message "Retrieving package `%s' ..."
1095 (copy-file (package-get-remote-filename search-dir
1097 full-package-filename t)))
1099 ;; If we found it, we're done.
1100 (if (and full-package-filename
1101 (file-exists-p full-package-filename))
1103 ;; Didn't find it. Try the next possible filename.
1104 (setq search-filenames (cdr search-filenames))))))
1106 (if (or (not full-package-filename)
1107 (not (file-exists-p full-package-filename)))
1108 (if package-get-remote
1109 (error 'search-failed
1110 (format "Unable to find file %s" base-filename))
1111 (error 'syntax-error
1112 "No download sites or local package locations specified.")))
1113 ;; Validate the md5 checksum
1114 ;; Doing it with XEmacs removes the need for an external md5 program
1115 (message "Validating checksum for `%s'..." package) (sit-for 0)
1117 (insert-file-contents-literally full-package-filename)
1118 (if (not (string= (md5 (current-buffer))
1119 (package-get-info-prop this-package
1122 (delete-file full-package-filename)
1123 (error 'process-error
1124 (format "Package %s does not match md5 checksum %s has been deleted"
1125 base-filename full-package-filename)))))
1127 (package-admin-delete-binary-package package install-dir)
1129 (message "Installing package `%s' ..." package) (sit-for 0)
1131 (package-admin-add-binary-package full-package-filename
1135 ;; clear messages so that only messages from
1136 ;; package-get-init-package are seen, below.
1138 (if (package-get-init-package (package-admin-get-lispdir
1139 install-dir package))
1141 (run-hook-with-args 'package-install-hook package install-dir)
1142 (message "Added package `%s'" package)
1145 ;; display message only if there isn't already one.
1146 (if (not (current-message))
1148 (message "Added package `%s' (errors occurred)"
1152 (setq package-status 'errors)))))
1153 (message "Installation of package %s failed." base-filename)
1155 (switch-to-buffer package-admin-temp-buffer)
1156 (delete-file full-package-filename)
1157 (setq package-status nil)))
1159 (if (and found package-get-remove-copy)
1160 (delete-file full-package-filename))
1163 (defun package-get-info-find-package (which name)
1164 "Look in WHICH for the package called NAME and return all the info
1165 associated with it. See `package-get-base' for info on the format
1168 To access fields returned from this, use
1169 `package-get-info-version' to return information about particular a
1170 version. Use `package-get-info-find-prop' to find particular property
1171 from a version returned by `package-get-info-version'."
1172 (interactive "xPackage list: \nsPackage Name: ")
1174 (if (eq (caar which) name)
1177 (package-get-info-find-package (cdr which) name)))))
1179 (defun package-get-info-version (package version)
1180 "In PACKAGE, return the plist associated with a particular VERSION of the
1181 package. PACKAGE is typically as returned by
1182 `package-get-info-find-package'. If VERSION is nil, then return the
1183 first (aka most recent) version. Use `package-get-info-find-prop'
1184 to retrieve a particular property from the value returned by this."
1185 (interactive (package-get-interactive-package-query t t))
1186 (while (and version package (not (string= (plist-get (car package) 'version) version)))
1187 (setq package (cdr package)))
1188 (if package (car package)))
1190 (defun package-get-info-prop (package-version property)
1191 "In PACKAGE-VERSION, return the value associated with PROPERTY.
1192 PACKAGE-VERSION is typically returned by `package-get-info-version'
1193 and PROPERTY is typically (although not limited to) one of the
1196 version - version of this package
1197 provides - list of symbols provided
1198 requires - list of symbols that are required.
1199 These in turn are provided by other packages.
1200 size - size of the bundled package
1201 md5sum - computed md5 checksum"
1202 (interactive "xPackage Version: \nSProperty")
1203 (plist-get package-version property))
1205 (defun package-get-info-version-prop (package-list package version property)
1206 "In PACKAGE-LIST, search for PACKAGE with this VERSION and return
1208 (package-get-info-prop
1209 (package-get-info-version
1210 (package-get-info-find-package package-list package) version) property))
1212 (defun package-get-staging-dir (filename)
1213 "Return a good place to stash FILENAME when it is retrieved.
1214 Use `package-get-dir' for directory to store stuff.
1215 Creates `package-get-dir' if it doesn't exist."
1216 (interactive "FPackage filename: ")
1217 (if (not (file-exists-p package-get-dir))
1218 (make-directory package-get-dir))
1220 (file-name-nondirectory (or (and (fboundp 'efs-ftp-path)
1221 (nth 2 (efs-ftp-path filename)))
1223 (file-name-as-directory package-get-dir)))
1225 (defun package-get-remote-filename (search filename)
1226 "Return FILENAME as a remote filename.
1227 It first checks if FILENAME already is a remote filename. If it is
1228 not, then it uses the (car search) as the remote site-name and the (cadr
1229 search) as the remote-directory and concatenates filename. In other
1231 site-name:remote-directory/filename.
1233 If (car search) is nil, (cadr search is interpreted as a local directory).
1235 (if (file-remote-p filename)
1237 (let ((dir (cadr search)))
1238 (concat (when (car search)
1240 (if (string-match "@" (car search))
1244 (if (string-match "/$" dir)
1249 (defun package-get-installedp (package version)
1250 "Determine if PACKAGE with VERSION has already been installed.
1251 I'm not sure if I want to do this by searching directories or checking
1252 some built in variables. For now, use packages-package-list."
1253 ;; Use packages-package-list which contains name and version
1255 (package-get-info-find-package packages-package-list
1257 (if (floatp version)
1259 (string-to-number version))))
1262 (defun package-get-package-provider (sym &optional force-current)
1263 "Search for a package that provides SYM and return the name and
1264 version. Searches in `package-get-base' for SYM. If SYM is a
1265 consp, then it must match a corresponding (provide (SYM VERSION)) from
1268 If FORCE-CURRENT is non-nil make sure the database is up to date. This might
1269 lead to Emacs accessing remote sites."
1270 (interactive "SSymbol: ")
1271 (package-get-require-base force-current)
1272 (let ((packages package-get-base)
1275 (while (and (not done) packages)
1276 (let* ((this-name (caar packages))
1277 (this-package (cdr (car packages)))) ;strip off package name
1278 (while (and (not done) this-package)
1279 (if (or (eq this-name sym)
1281 (package-get-info-prop (car this-package) 'version))
1284 (package-get-info-prop (car this-package) 'provides)))
1285 (progn (setq done t)
1287 (list (caar packages)
1288 (package-get-info-prop (car this-package) 'version))))
1289 (setq this-package (cdr this-package)))))
1290 (setq packages (cdr packages)))
1291 (when (interactive-p)
1293 (message "%S" found)
1294 (message "No appropriate package found")))
1297 (defun package-get-ever-installed-p (pkg &optional notused)
1298 (string-match "-package$" (symbol-name pkg))
1299 (custom-initialize-set
1301 (if (package-get-info-find-package
1302 packages-package-list
1303 (intern (substring (symbol-name pkg) 0 (match-beginning 0))))
1306 (provide 'package-get)
1307 ;;; package-get.el ends here