235
|
1 ;;; package-get.el --- Retrieve XEmacs package
|
|
2
|
|
3 ;; Copyright (C) 1998 by Pete Ware
|
|
4
|
|
5 ;; Author: Pete Ware <ware@cis.ohio-state.edu>
|
|
6 ;; Keywords: internal
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
23 ;; 02111-1307, USA.
|
|
24
|
|
25 ;;; Synched up with: Not in FSF
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; package-get -
|
|
30 ;; Retrieve a package and any other required packages from an archive
|
|
31 ;;
|
|
32 ;; The idea:
|
|
33 ;; A new XEmacs lisp-only release is generated with the following steps:
|
|
34 ;; 1. The maintainer runs some yet to be written program that
|
|
35 ;; generates all the dependency information. This should
|
|
36 ;; determine all the require and provide statements and associate
|
|
37 ;; them with a package.
|
|
38 ;; 2. All the packages are then bundled into their own tar balls
|
|
39 ;; (or whatever format)
|
|
40 ;; 3. Maintainer automatically generates a new `package-get-base'
|
|
41 ;; data structure which contains information such as the
|
|
42 ;; package name, the file to be retrieved, an md5 checksum,
|
|
43 ;; etc (see `package-get-base').
|
|
44 ;; 4. The maintainer posts an announcement with the new version
|
|
45 ;; of `package-get-base'.
|
|
46 ;; 5. A user/system manager saves this posting and runs
|
|
47 ;; `package-get-update' which uses the previously saved list
|
|
48 ;; of packages, `package-get-here' that the user/site
|
|
49 ;; wants to determine what new versions to download and
|
|
50 ;; install.
|
|
51 ;;
|
|
52 ;; A user/site manager can generate a new `package-get-here' structure
|
|
53 ;; by using `package-get-setup' which generates a customize like
|
|
54 ;; interface to the list of packages. The buffer looks something
|
|
55 ;; like:
|
|
56 ;;
|
|
57 ;; gnus - a mail and news reader
|
|
58 ;; [] Always install
|
|
59 ;; [] Needs updating
|
|
60 ;; [] Required by other [packages]
|
|
61 ;; version: 2.0
|
|
62 ;;
|
|
63 ;; vm - a mail reader
|
|
64 ;; [] Always install
|
|
65 ;; [] Needs updating
|
|
66 ;; [] Required by other [packages]
|
|
67 ;;
|
|
68 ;; Where `[]' indicates a toggle box
|
|
69 ;;
|
|
70 ;; - Clicking on "Always install" puts this into
|
|
71 ;; `package-get-here' list. "Needs updating" indicates a new
|
|
72 ;; version is available. Anything already in
|
|
73 ;; `package-get-here' has this enabled.
|
|
74 ;; - "Required by other" means some other packages are going to force
|
|
75 ;; this to be installed. Clicking on [packages] gives a list
|
|
76 ;; of packages that require this.
|
|
77 ;;
|
|
78 ;; The `package-get-base' should be installed in a file in
|
|
79 ;; `data-directory'. The `package-get-here' should be installed in
|
|
80 ;; site-lisp. Both are then read at run time.
|
|
81 ;;
|
|
82 ;; TODO:
|
|
83 ;; - Implement `package-get-setup'
|
|
84 ;; - Actually put `package-get-base' and `package-get-here' into
|
|
85 ;; files that are read.
|
|
86 ;; - Allow users to have their own packages that they want installed
|
|
87 ;; in ~/.xemacs/.
|
|
88 ;; - SOMEONE needs to write the programs that generate the
|
|
89 ;; provides/requires database and makes it into a lisp data
|
|
90 ;; structure suitable for `package-get-base'
|
|
91 ;; - Handle errors such as no package providing a required symbol.
|
|
92 ;; - Tie this into the `require' function to download packages
|
|
93 ;; transparently.
|
|
94
|
|
95 ;;; Change Log
|
|
96
|
|
97 ;;; Code:
|
|
98
|
|
99 (require 'package-admin)
|
298
|
100 (require 'package-get-base)
|
235
|
101
|
|
102 (defvar package-get-base nil
|
|
103 "List of packages that are installed at this site.
|
|
104 For each element in the alist, car is the package name and the cdr is
|
|
105 a plist containing information about the package. Typical fields
|
|
106 kept in the plist are:
|
|
107
|
|
108 version - version of this package
|
|
109 provides - list of symbols provided
|
|
110 requires - list of symbols that are required.
|
|
111 These in turn are provided by other packages.
|
|
112 filename - name of the file.
|
|
113 size - size of the file (aka the bundled package)
|
|
114 md5sum - computed md5 checksum
|
|
115 description - What this package is for.
|
|
116 type - Whether this is a 'binary (default) or 'single file package
|
|
117
|
|
118 More fields may be added as needed. An example:
|
|
119
|
|
120 '(
|
|
121 (name
|
|
122 (version \"<version 2>\"
|
|
123 file \"filename\"
|
|
124 description \"what this package is about.\"
|
|
125 provides (<list>)
|
|
126 requires (<list>)
|
|
127 size <integer-bytes>
|
|
128 md5sum \"<checksum\"
|
|
129 type single
|
|
130 )
|
|
131 (version \"<version 1>\"
|
|
132 file \"filename\"
|
|
133 description \"what this package is about.\"
|
|
134 provides (<list>)
|
|
135 requires (<list>)
|
|
136 size <integer-bytes>
|
|
137 md5sum \"<checksum\"
|
|
138 type single
|
|
139 )
|
|
140 ...
|
|
141 ))
|
|
142
|
|
143 For version information, it is assumed things are listed in most
|
|
144 recent to least recent -- in other words, the version names don't have to
|
|
145 be lexically ordered. It is debatable if it makes sense to have more than
|
|
146 one version of a package available.")
|
|
147
|
263
|
148 (defvar package-get-dir (temp-directory)
|
235
|
149 "*Where to store temporary files for staging.")
|
|
150
|
|
151 (defvar package-get-remote
|
|
152 '(
|
276
|
153 ("ftp.xemacs.org" "/pub/xemacs/beta/xemacs-21.0/packages/binary-packages")
|
|
154 ("ftp.xemacs.org" "/pub/xemacs/beta/xemacs-21.0/packages/single-file-packages")
|
235
|
155 ("ftp.xemacs.org" "/pub/xemacs/package"))
|
|
156 "*List of remote sites to contact for downloading packages.
|
|
157 List format is '(site-name directory-on-site). Each site is tried in
|
|
158 order until the package is found.")
|
|
159
|
|
160 (defvar package-get-remove-copy nil
|
|
161 "*After copying and installing a package, if this is T, then remove the
|
|
162 copy. Otherwise, keep it around.")
|
|
163
|
292
|
164 ;;;###autoload
|
263
|
165 (defun package-get-update-all ()
|
|
166 "Fetch and install the latest versions of all currently installed packages."
|
|
167 (interactive)
|
|
168 ;; Load a fresh copy
|
|
169 (mapcar (lambda (pkg)
|
306
|
170 (package-get (car pkg) nil 'never))
|
263
|
171 packages-package-list))
|
|
172
|
292
|
173 ;;;###autoload
|
235
|
174 (defun package-get-all (package version &optional fetched-packages)
|
|
175 "Fetch PACKAGE with VERSION and all other required packages.
|
|
176 Uses `package-get-base' to determine just what is required and what
|
|
177 package provides that functionality. If VERSION is nil, retrieves
|
|
178 latest version. Optional argument FETCHED-PACKAGES is used to keep
|
|
179 track of packages already fetched."
|
278
|
180 (interactive "sPackage: \nsVersion: ")
|
237
|
181 (let* ((the-package (package-get-info-find-package package-get-base
|
|
182 package))
|
|
183 (this-package (package-get-info-version
|
|
184 the-package version))
|
235
|
185 (this-requires (package-get-info-prop this-package 'requires))
|
|
186 )
|
237
|
187 (setq version (package-get-info-prop this-package 'version))
|
235
|
188 (unless (package-get-installedp package version)
|
|
189 (package-get package version))
|
|
190 (setq fetched-packages
|
237
|
191 (append (list package)
|
|
192 (package-get-info-prop this-package 'provides)
|
235
|
193 fetched-packages))
|
|
194 ;; grab everything that this package requires plus recursively
|
|
195 ;; grab everything that the requires require. Keep track
|
|
196 ;; in `fetched-packages' the list of things provided -- this
|
|
197 ;; keeps us from going into a loop
|
|
198 (while this-requires
|
|
199 (if (not (member (car this-requires) fetched-packages))
|
|
200 (let* ((reqd-package (package-get-package-provider
|
|
201 (car this-requires)))
|
|
202 (reqd-version (cadr reqd-package))
|
|
203 (reqd-name (car reqd-package)))
|
237
|
204 (if (null reqd-name)
|
|
205 (error "Unable to find a provider for %s" (car this-requires)))
|
235
|
206 (setq fetched-packages
|
|
207 (package-get-all reqd-name reqd-version fetched-packages)))
|
|
208 )
|
|
209 (setq this-requires (cdr this-requires)))
|
294
|
210 fetched-packages
|
|
211 ))
|
235
|
212
|
292
|
213 ;;;###autoload
|
306
|
214 (defun package-get (package &optional version conflict install-dir)
|
235
|
215 "Fetch PACKAGE from remote site.
|
|
216 Optional arguments VERSION indicates which version to retrieve, nil
|
|
217 means most recent version. CONFLICT indicates what happens if the
|
|
218 package is already installed. Valid values for CONFLICT are:
|
|
219 'always always retrieve the package even if it is already installed
|
|
220 'never do not retrieve the package if it is installed.
|
306
|
221 INSTALL-DIR, if non-nil, specifies the package directory where
|
|
222 fetched packages should be installed.
|
235
|
223
|
|
224 The value of `package-get-base' is used to determine what files should
|
|
225 be retrieved. The value of `package-get-remote' is used to determine
|
|
226 where a package should be retrieved from. The sites are tried in
|
|
227 order so one is better off listing easily reached sites first.
|
|
228
|
|
229 Once the package is retrieved, its md5 checksum is computed. If that
|
|
230 sum does not match that stored in `package-get-base' for this version
|
|
231 of the package, an error is signalled."
|
|
232 (interactive "xPackage List: ")
|
|
233 (let* ((this-package
|
|
234 (package-get-info-version
|
|
235 (package-get-info-find-package package-get-base
|
|
236 package) version))
|
|
237 (found nil)
|
|
238 (search-dirs package-get-remote)
|
|
239 (filename (package-get-info-prop this-package 'filename)))
|
|
240 (if (null this-package)
|
|
241 (error "Couldn't find package %s with version %s"
|
|
242 package version))
|
|
243 (if (null filename)
|
|
244 (error "No filename associated with package %s, version %s"
|
|
245 package version))
|
237
|
246 (setq version (package-get-info-prop this-package 'version))
|
235
|
247 (unless (and (eq conflict 'never)
|
|
248 (package-get-installedp package version))
|
|
249 ;; Find the package from search list in package-get-remote
|
|
250 ;; and copy it into the staging directory. Then validate
|
|
251 ;; the checksum. Finally, install the package.
|
|
252 (while (and search-dirs
|
|
253 (not (file-exists-p (package-get-staging-dir filename))))
|
|
254 (if (file-exists-p (package-get-remote-filename
|
|
255 (car search-dirs) filename))
|
294
|
256 (copy-file (package-get-remote-filename (car search-dirs) filename)
|
|
257 (package-get-staging-dir filename))
|
235
|
258 (setq search-dirs (cdr search-dirs))
|
|
259 ))
|
|
260 (if (not (file-exists-p (package-get-staging-dir filename)))
|
|
261 (error "Unable to find file %s" filename))
|
|
262 ;; Validate the md5 checksum
|
284
|
263 ;; Doing it with XEmacs removes the need for an external md5 program
|
235
|
264 (with-temp-buffer
|
294
|
265 ;; What ever happened to i-f-c-literally
|
284
|
266 (let (file-name-handler-alist)
|
|
267 (insert-file-contents-internal (package-get-staging-dir filename)))
|
|
268 (if (not (string= (md5 (current-buffer))
|
|
269 (package-get-info-prop this-package
|
|
270 'md5sum)))
|
235
|
271 (error "Package %s does not match md5 checksum" filename)))
|
237
|
272 (message "Retrieved package %s" filename) (sit-for 0)
|
235
|
273 (let ((status
|
288
|
274 (package-admin-add-binary-package
|
306
|
275 (package-get-staging-dir filename)
|
|
276 install-dir)))
|
235
|
277 (when (not (= status 0))
|
|
278 (message "Package failed.")
|
237
|
279 (switch-to-buffer package-admin-temp-buffer)))
|
|
280 (sit-for 0)
|
|
281 (message "Added package") (sit-for 0)
|
235
|
282 (setq found t))
|
|
283 (if (and found package-get-remove-copy)
|
|
284 (delete-file (package-get-staging-dir filename)))
|
|
285 ))
|
|
286
|
|
287 (defun package-get-info-find-package (which name)
|
294
|
288 "Look in WHICH for the package called NAME and return all the info
|
|
289 associated with it. See `package-get-base' for info on the format
|
|
290 returned.
|
235
|
291
|
|
292 To access fields returned from this, use
|
|
293 `package-get-info-version' to return information about particular a
|
|
294 version. Use `package-get-info-find-prop' to find particular property
|
|
295 from a version returned by `package-get-info-version'."
|
294
|
296 (interactive "xPackage list: \nsPackage Name: ")
|
235
|
297 (if which
|
|
298 (if (eq (caar which) name)
|
|
299 (cdar which)
|
|
300 (if (cdr which)
|
|
301 (package-get-info-find-package (cdr which) name)))))
|
|
302
|
|
303 (defun package-get-info-version (package version)
|
|
304 "In PACKAGE, return the plist associated with a particular VERSION of the
|
|
305 package. PACKAGE is typically as returned by
|
|
306 `package-get-info-find-package'. If VERSION is nil, then return the
|
|
307 first (aka most recent) version. Use `package-get-info-find-prop'
|
|
308 to retrieve a particular property from the value returned by this."
|
|
309 (interactive "xPackage Info: \nsVersion: ")
|
|
310 (while (and version package (not (string= (plist-get (car package) 'version) version)))
|
|
311 (setq package (cdr package)))
|
|
312 (if package (car package)))
|
|
313
|
|
314 (defun package-get-info-prop (package-version property)
|
|
315 "In PACKAGE-VERSION, return the value associated with PROPERTY.
|
|
316 PACKAGE-VERSION is typically returned by `package-get-info-version'
|
|
317 and PROPERTY is typically (although not limited to) one of the
|
|
318 following:
|
|
319
|
|
320 version - version of this package
|
|
321 provides - list of symbols provided
|
|
322 requires - list of symbols that are required.
|
|
323 These in turn are provided by other packages.
|
|
324 size - size of the bundled package
|
|
325 md5sum - computed md5 checksum"
|
|
326 (interactive "xPackage Version: \nSProperty")
|
|
327 (plist-get package-version property))
|
|
328
|
|
329 (defun package-get-info-version-prop (package-list package version property)
|
|
330 "In PACKAGE-LIST, search for PACKAGE with this VERSION and return
|
|
331 PROPERTY value."
|
|
332 (package-get-info-prop
|
|
333 (package-get-info-version
|
|
334 (package-get-info-find-package package-list package) version) property))
|
|
335
|
|
336 (defun package-get-set-version-prop (package-list package version
|
|
337 property value)
|
|
338 "A utility to make it easier to add a VALUE for a specific PROPERTY
|
|
339 in this VERSION of a specific PACKAGE kept in the PACKAGE-LIST.
|
|
340 Returns the modified PACKAGE-LIST. Any missing fields are created."
|
|
341 )
|
|
342
|
|
343 (defun package-get-staging-dir (filename)
|
|
344 "Return a good place to stash FILENAME when it is retrieved.
|
|
345 Use `package-get-dir' for directory to store stuff.
|
|
346 Creates `package-get-dir' it it doesn't exist."
|
|
347 (interactive "FPackage filename: ")
|
|
348 (if (not (file-exists-p package-get-dir))
|
|
349 (make-directory package-get-dir))
|
|
350 (concat
|
|
351 (file-name-as-directory package-get-dir)
|
|
352 (file-name-nondirectory (or (nth 2 (efs-ftp-path filename)) filename))))
|
|
353
|
|
354
|
|
355 (defun package-get-remote-filename (search filename)
|
|
356 "Return FILENAME as a remote filename.
|
|
357 It first checks if FILENAME already is a remote filename. If it is
|
|
358 not, then it uses the (car search) as the remote site-name and the (cadr
|
|
359 search) as the remote-directory and concatenates filename. In other
|
|
360 words
|
|
361 site-name:remote-directory/filename
|
|
362 "
|
|
363 (if (efs-ftp-path filename)
|
|
364 filename
|
298
|
365 (let ((dir (cadr search)))
|
|
366 (concat "/"
|
|
367 (car search) ":"
|
|
368 (if (string-match "/$" dir)
|
|
369 dir
|
|
370 (concat dir "/"))
|
|
371 filename))))
|
235
|
372
|
|
373
|
|
374 (defun package-get-installedp (package version)
|
|
375 "Determine if PACKAGE with VERSION has already been installed.
|
|
376 I'm not sure if I want to do this by searching directories or checking
|
263
|
377 some built in variables. For now, use packages-package-list."
|
|
378 ;; Use packages-package-list which contains name and version
|
294
|
379 (equal (plist-get
|
|
380 (package-get-info-find-package packages-package-list
|
|
381 package) ':version)
|
|
382 (if (floatp version) version (string-to-number version))))
|
235
|
383
|
294
|
384 ;;;###autoload
|
235
|
385 (defun package-get-package-provider (sym)
|
|
386 "Search for a package that provides SYM and return the name and
|
|
387 version. Searches in `package-get-base' for SYM. If SYM is a
|
|
388 consp, then it must match a corresponding (provide (SYM VERSION)) from
|
|
389 the package."
|
|
390 (interactive "SSymbol: ")
|
|
391 (let ((packages package-get-base)
|
|
392 (done nil)
|
|
393 (found nil))
|
|
394 (while (and (not done) packages)
|
237
|
395 (let* ((this-name (caar packages))
|
|
396 (this-package (cdr (car packages)))) ;strip off package name
|
235
|
397 (while (and (not done) this-package)
|
237
|
398 (if (or (eq this-name sym)
|
|
399 (eq (cons this-name
|
|
400 (package-get-info-prop (car this-package) 'version))
|
|
401 sym)
|
|
402 (member sym (package-get-info-prop (car this-package) 'provides)))
|
235
|
403 (progn (setq done t)
|
|
404 (setq found (list (caar packages)
|
|
405 (package-get-info-prop (car this-package) 'version))))
|
|
406 (setq this-package (cdr this-package)))))
|
|
407 (setq packages (cdr packages)))
|
|
408 found))
|
|
409
|
286
|
410 ;;
|
|
411 ;; customize interfaces.
|
|
412 ;; The group is in this file so that custom loads includes this file.
|
|
413 ;;
|
|
414 (defgroup packages nil
|
|
415 "Configure XEmacs packages."
|
|
416 :group 'emacs)
|
|
417
|
292
|
418 ;;;###autoload
|
286
|
419 (defun package-get-custom ()
|
|
420 "Fetch and install the latest versions of all customized packages."
|
|
421 (interactive)
|
|
422 ;; Load a fresh copy
|
|
423 (load "package-get-custom.el")
|
|
424 (mapcar (lambda (pkg)
|
|
425 (if (eval (intern (concat (symbol-name (car pkg)) "-package")))
|
|
426 (package-get-all (car pkg) nil))
|
|
427 t)
|
|
428 package-get-base))
|
|
429
|
288
|
430 (defun package-get-ever-installed-p (pkg &optional notused)
|
286
|
431 (string-match "-package$" (symbol-name pkg))
|
|
432 (custom-initialize-set
|
|
433 pkg
|
|
434 (if (package-get-info-find-package
|
|
435 packages-package-list
|
|
436 (intern (substring (symbol-name pkg) 0 (match-beginning 0))))
|
|
437 t)))
|
|
438
|
288
|
439 (defun package-get-file-installed-p (file &optional paths)
|
|
440 "Return absolute-path of FILE if FILE exists in PATHS.
|
|
441 If PATHS is omitted, `load-path' is used."
|
|
442 (if (null paths)
|
|
443 (setq paths load-path)
|
|
444 )
|
|
445 (catch 'tag
|
|
446 (let (path)
|
|
447 (while paths
|
|
448 (setq path (expand-file-name file (car paths)))
|
|
449 (if (file-exists-p path)
|
|
450 (throw 'tag path)
|
|
451 )
|
|
452 (setq paths (cdr paths))
|
|
453 ))))
|
|
454
|
286
|
455 (defun package-get-create-custom ()
|
|
456 "Creates a package customization file package-get-custom.el.
|
|
457 Entries in the customization file are retrieved from package-get-base.el."
|
|
458 (interactive)
|
|
459 ;; Load a fresh copy
|
|
460 (let ((custom-buffer (find-file-noselect
|
288
|
461 (or (package-get-file-installed-p
|
|
462 "package-get-custom.el")
|
286
|
463 (concat (file-name-directory
|
288
|
464 (package-get-file-installed-p
|
|
465 "package-get-base.el"))
|
286
|
466 "package-get-custom.el"))))
|
|
467 (pkg-groups nil))
|
|
468
|
|
469 ;; clear existing stuff
|
|
470 (delete-region (point-min custom-buffer)
|
|
471 (point-max custom-buffer) custom-buffer)
|
|
472 (insert-string "(require 'package-get)\n" custom-buffer)
|
|
473
|
|
474 (mapcar (lambda (pkg)
|
|
475 (let ((category (plist-get (car (cdr pkg)) 'category)))
|
|
476 (or (memq (intern category) pkg-groups)
|
|
477 (progn
|
|
478 (setq pkg-groups (cons (intern category) pkg-groups))
|
|
479 (insert-string
|
|
480 (concat "(defgroup " category "-packages nil\n"
|
|
481 " \"" category " package group\"\n"
|
|
482 " :group 'packages)\n\n") custom-buffer)))
|
|
483
|
|
484 (insert-string
|
|
485 (concat "(defcustom " (symbol-name (car pkg))
|
|
486 "-package nil \n"
|
|
487 " \"" (plist-get (car (cdr pkg)) 'description) "\"\n"
|
|
488 " :group '" category "-packages\n"
|
288
|
489 " :initialize 'package-get-ever-installed-p\n"
|
286
|
490 " :type 'boolean)\n\n") custom-buffer)))
|
294
|
491 package-get-base) custom-buffer)
|
286
|
492 )
|
|
493
|
|
494 ;; need this first to avoid infinite dependency loops
|
|
495 (provide 'package-get)
|
|
496
|
|
497 ;; potentially update the custom dependencies every time we load this
|
288
|
498 (let ((custom-file (package-get-file-installed-p "package-get-custom.el"))
|
|
499 (package-file (package-get-file-installed-p "package-get-base.el")))
|
286
|
500 ;; update custom file if it doesn't exist
|
|
501 (if (or (not custom-file)
|
|
502 (and (< (car (nth 5 (file-attributes custom-file)))
|
|
503 (car (nth 5 (file-attributes package-file))))
|
|
504 (< (car (nth 5 (file-attributes custom-file)))
|
|
505 (car (nth 5 (file-attributes package-file))))))
|
|
506 (save-excursion
|
|
507 (message "generating package customizations...")
|
|
508 (set-buffer (package-get-create-custom))
|
|
509 (save-buffer)
|
|
510 (message "generating package customizations...done")))
|
|
511 (load "package-get-custom.el"))
|
|
512
|
235
|
513 ;;; package-get.el ends here
|