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
|
314
|
158 order until the package is found. As a special case, `site-name' can be
|
|
159 `nil', in which case `directory-on-site' is treated as a local directory.")
|
235
|
160
|
|
161 (defvar package-get-remove-copy nil
|
|
162 "*After copying and installing a package, if this is T, then remove the
|
|
163 copy. Otherwise, keep it around.")
|
|
164
|
314
|
165 (defun package-get-rmtree (directory)
|
|
166 "Delete a directory and all of its contents, recursively.
|
|
167 This is a feeble attempt at making a portable rmdir."
|
|
168 (let ( (orig-default-directory default-directory) files dirs dir)
|
|
169 (unwind-protect
|
|
170 (progn
|
|
171 (setq directory (file-name-as-directory directory))
|
|
172 (setq files (directory-files directory nil nil nil t))
|
|
173 (setq dirs (directory-files directory nil nil nil 'dirs))
|
|
174 (while dirs
|
|
175 (setq dir (car dirs))
|
|
176 (if (file-symlink-p dir) ;; just in case, handle symlinks
|
|
177 (delete-file dir)
|
|
178 (if (not (or (string-equal dir ".") (string-equal dir "..")))
|
|
179 (package-get-rmtree (expand-file-name dir directory))))
|
|
180 (setq dirs (cdr dirs))
|
|
181 )
|
|
182 (setq default-directory directory)
|
|
183 (condition-case err
|
|
184 (progn
|
|
185 (while files
|
|
186 (delete-file (car files))
|
|
187 (setq files (cdr files))
|
|
188 )
|
|
189 (delete-directory directory)
|
|
190 )
|
|
191 (file-error
|
|
192 (message "%s: %s: \"%s\"" (nth 1 err) (nth 2 err) (nth 3 err)))
|
|
193 )
|
|
194 )
|
|
195 (progn
|
|
196 (setq default-directory orig-default-directory)
|
|
197 ))
|
|
198 ))
|
|
199
|
292
|
200 ;;;###autoload
|
263
|
201 (defun package-get-update-all ()
|
|
202 "Fetch and install the latest versions of all currently installed packages."
|
|
203 (interactive)
|
|
204 ;; Load a fresh copy
|
314
|
205 (catch 'exit
|
|
206 (mapcar (lambda (pkg)
|
|
207 (if (not (package-get (car pkg) nil 'never))
|
|
208 (throw 'exit nil) ;; Bail out if error detected
|
|
209 ))
|
|
210 packages-package-list)))
|
|
211
|
|
212 (defun package-get-interactive-package-query (get-version package-symbol)
|
|
213 "Perform interactive querying for package and optional version.
|
|
214 Query for a version if GET-VERSION is non-nil. Return package name as
|
|
215 a symbol instead of a string if PACKAGE-SYMBOL is non-nil.
|
|
216 The return value is suitable for direct passing to `interactive'."
|
|
217 (let ( (table (mapcar '(lambda (item)
|
|
218 (let ( (name (symbol-name (car item))) )
|
|
219 (cons name name)
|
|
220 ))
|
|
221 package-get-base))
|
|
222 package package-symbol default-version version)
|
|
223 (save-window-excursion
|
|
224 (setq package (completing-read "Package: " table nil t))
|
|
225 (setq package-symbol (intern package))
|
|
226 (if get-version
|
|
227 (progn
|
|
228 (setq default-version
|
|
229 (package-get-info-prop
|
|
230 (package-get-info-version
|
|
231 (package-get-info-find-package package-get-base
|
|
232 package-symbol) nil)
|
|
233 'version))
|
|
234 (while (string=
|
|
235 (setq version (read-string "Version: " default-version))
|
|
236 "")
|
|
237 )
|
|
238 (if package-symbol
|
|
239 (list package-symbol version)
|
|
240 (list package version))
|
|
241 )
|
|
242 (if package-symbol
|
|
243 (list package-symbol)
|
|
244 (list package)))
|
|
245 )))
|
263
|
246
|
292
|
247 ;;;###autoload
|
235
|
248 (defun package-get-all (package version &optional fetched-packages)
|
|
249 "Fetch PACKAGE with VERSION and all other required packages.
|
|
250 Uses `package-get-base' to determine just what is required and what
|
|
251 package provides that functionality. If VERSION is nil, retrieves
|
|
252 latest version. Optional argument FETCHED-PACKAGES is used to keep
|
314
|
253 track of packages already fetched.
|
|
254
|
|
255 Returns nil upon error."
|
|
256 (interactive (package-get-interactive-package-query t nil))
|
237
|
257 (let* ((the-package (package-get-info-find-package package-get-base
|
|
258 package))
|
|
259 (this-package (package-get-info-version
|
|
260 the-package version))
|
235
|
261 (this-requires (package-get-info-prop this-package 'requires))
|
|
262 )
|
314
|
263 (catch 'exit
|
|
264 (setq version (package-get-info-prop this-package 'version))
|
|
265 (unless (package-get-installedp package version)
|
|
266 (if (not (package-get package version))
|
|
267 (progn
|
|
268 (setq fetched-packages nil)
|
|
269 (throw 'exit nil))))
|
|
270 (setq fetched-packages
|
|
271 (append (list package)
|
|
272 (package-get-info-prop this-package 'provides)
|
|
273 fetched-packages))
|
|
274 ;; grab everything that this package requires plus recursively
|
|
275 ;; grab everything that the requires require. Keep track
|
|
276 ;; in `fetched-packages' the list of things provided -- this
|
|
277 ;; keeps us from going into a loop
|
|
278 (while this-requires
|
|
279 (if (not (member (car this-requires) fetched-packages))
|
|
280 (let* ((reqd-package (package-get-package-provider
|
|
281 (car this-requires)))
|
|
282 (reqd-version (cadr reqd-package))
|
|
283 (reqd-name (car reqd-package)))
|
|
284 (if (null reqd-name)
|
|
285 (error "Unable to find a provider for %s"
|
|
286 (car this-requires)))
|
|
287 (if (not (setq fetched-packages
|
|
288 (package-get-all reqd-name reqd-version
|
|
289 fetched-packages)))
|
|
290 (throw 'exit nil)))
|
|
291 )
|
|
292 (setq this-requires (cdr this-requires)))
|
|
293 )
|
294
|
294 fetched-packages
|
|
295 ))
|
235
|
296
|
314
|
297 (defun package-get-load-package-file (lispdir file)
|
|
298 (let (pathname)
|
|
299 (setq pathname (expand-file-name file lispdir))
|
|
300 (condition-case err
|
|
301 (progn
|
|
302 (load pathname t)
|
|
303 t)
|
|
304 (t
|
|
305 (message "Error loading package file \"%s\" %s!" pathname err)
|
|
306 nil))
|
|
307 ))
|
|
308
|
|
309 (defun package-get-init-package (lispdir)
|
|
310 "Initialize the package.
|
|
311 This really assumes that the package has never been loaded. Updating
|
|
312 a newer package can cause problems, due to old, obsolete functions in
|
|
313 the old package.
|
|
314
|
|
315 Return `t' upon complete success, `nil' if any errors occurred."
|
|
316 (progn
|
|
317 (if (and lispdir
|
|
318 (file-accessible-directory-p lispdir))
|
|
319 (progn
|
|
320 ;; Add lispdir to load-path if it doesn't already exist.
|
|
321 ;; NOTE: this does not take symlinks, etc., into account.
|
|
322 (if (let ( (dirs load-path) )
|
|
323 (catch 'done
|
|
324 (while dirs
|
|
325 (if (string-equal (car dirs) lispdir)
|
|
326 (throw 'done nil))
|
|
327 (setq dirs (cdr dirs))
|
|
328 )
|
|
329 t))
|
|
330 (setq load-path (cons lispdir load-path)))
|
316
|
331 (if (not (package-get-load-package-file lispdir "auto-autoloads"))
|
|
332 (package-get-load-package-file lispdir "_pkg"))
|
314
|
333 t)
|
|
334 nil)
|
|
335 ))
|
|
336
|
292
|
337 ;;;###autoload
|
306
|
338 (defun package-get (package &optional version conflict install-dir)
|
235
|
339 "Fetch PACKAGE from remote site.
|
|
340 Optional arguments VERSION indicates which version to retrieve, nil
|
|
341 means most recent version. CONFLICT indicates what happens if the
|
|
342 package is already installed. Valid values for CONFLICT are:
|
|
343 'always always retrieve the package even if it is already installed
|
|
344 'never do not retrieve the package if it is installed.
|
306
|
345 INSTALL-DIR, if non-nil, specifies the package directory where
|
|
346 fetched packages should be installed.
|
235
|
347
|
|
348 The value of `package-get-base' is used to determine what files should
|
|
349 be retrieved. The value of `package-get-remote' is used to determine
|
|
350 where a package should be retrieved from. The sites are tried in
|
|
351 order so one is better off listing easily reached sites first.
|
|
352
|
|
353 Once the package is retrieved, its md5 checksum is computed. If that
|
|
354 sum does not match that stored in `package-get-base' for this version
|
314
|
355 of the package, an error is signalled.
|
|
356
|
|
357 Returns `t' upon success, the symbol `error' if the package was
|
|
358 successfully installed but errors occurred during initialization, or
|
|
359 `nil' upon error."
|
|
360 (interactive (package-get-interactive-package-query nil t))
|
235
|
361 (let* ((this-package
|
|
362 (package-get-info-version
|
|
363 (package-get-info-find-package package-get-base
|
|
364 package) version))
|
|
365 (found nil)
|
|
366 (search-dirs package-get-remote)
|
314
|
367 (base-filename (package-get-info-prop this-package 'filename))
|
|
368 (package-status t)
|
|
369 filenames full-package-filename package-lispdir)
|
235
|
370 (if (null this-package)
|
|
371 (error "Couldn't find package %s with version %s"
|
|
372 package version))
|
314
|
373 (if (null base-filename)
|
235
|
374 (error "No filename associated with package %s, version %s"
|
|
375 package version))
|
314
|
376 (if (null install-dir)
|
|
377 (setq install-dir (package-admin-get-install-dir nil)))
|
|
378
|
|
379 ;; Contrive a list of possible package filenames.
|
|
380 ;; Ugly. Is there a better way to do this?
|
|
381 (setq filenames (cons base-filename nil))
|
|
382 (if (string-match "^\\(..*\\)\.tar\.gz$" base-filename)
|
316
|
383 (setq filenames (append filenames
|
|
384 (list (concat (match-string 1 base-filename)
|
|
385 ".tgz")))))
|
314
|
386
|
237
|
387 (setq version (package-get-info-prop this-package 'version))
|
235
|
388 (unless (and (eq conflict 'never)
|
|
389 (package-get-installedp package version))
|
314
|
390 ;; Find the package from the search list in package-get-remote
|
235
|
391 ;; and copy it into the staging directory. Then validate
|
|
392 ;; the checksum. Finally, install the package.
|
314
|
393 (catch 'done
|
316
|
394 (let (search-filenames current-dir-entry host dir current-filename
|
|
395 dest-filename)
|
314
|
396 ;; In each search directory ...
|
|
397 (while search-dirs
|
|
398 (setq current-dir-entry (car search-dirs)
|
|
399 host (car current-dir-entry)
|
|
400 dir (car (cdr current-dir-entry))
|
316
|
401 search-filenames filenames
|
|
402 )
|
314
|
403
|
|
404 ;; Look for one of the possible package filenames ...
|
|
405 (while search-filenames
|
316
|
406 (setq current-filename (car search-filenames)
|
|
407 dest-filename (package-get-staging-dir current-filename))
|
|
408 (cond
|
|
409 ;; No host means look on the current system.
|
|
410 ( (null host)
|
|
411 (setq full-package-filename
|
|
412 (substitute-in-file-name
|
|
413 (expand-file-name current-filename
|
|
414 (file-name-as-directory dir))))
|
|
415 )
|
|
416
|
|
417 ;; If it's already on the disk locally, and the size is
|
|
418 ;; greater than zero ...
|
|
419 ( (and (file-exists-p dest-filename)
|
|
420 (let (attrs)
|
|
421 ;; file-attributes could return -1 for LARGE files,
|
|
422 ;; but, hopefully, packages won't be that large.
|
|
423 (and (setq attrs (file-attributes dest-filename))
|
|
424 (> (nth 7 attrs) 0))))
|
|
425 (setq full-package-filename dest-filename)
|
|
426 )
|
|
427
|
|
428 ;; If the file exists on the remote system ...
|
|
429 ( (file-exists-p (package-get-remote-filename
|
|
430 current-dir-entry current-filename))
|
|
431 ;; Get it
|
|
432 (setq full-package-filename dest-filename)
|
|
433 (message "Retrieving package `%s' ..."
|
|
434 current-filename)
|
|
435 (sit-for 0)
|
|
436 (copy-file (package-get-remote-filename current-dir-entry
|
|
437 current-filename)
|
|
438 full-package-filename t)
|
|
439 )
|
|
440 )
|
|
441
|
314
|
442 ;; If we found it, we're done.
|
316
|
443 (if (and full-package-filename
|
|
444 (file-exists-p full-package-filename))
|
314
|
445 (throw 'done nil))
|
|
446 ;; Didn't find it. Try the next possible filename.
|
|
447 (setq search-filenames (cdr search-filenames))
|
|
448 )
|
|
449 ;; Try looking in the next possible directory ...
|
|
450 (setq search-dirs (cdr search-dirs))
|
|
451 )
|
235
|
452 ))
|
314
|
453
|
|
454 (if (or (not full-package-filename)
|
|
455 (not (file-exists-p full-package-filename)))
|
|
456 (error "Unable to find file %s" base-filename))
|
235
|
457 ;; Validate the md5 checksum
|
284
|
458 ;; Doing it with XEmacs removes the need for an external md5 program
|
314
|
459 (message "Validating checksum for `%s'..." package) (sit-for 0)
|
235
|
460 (with-temp-buffer
|
294
|
461 ;; What ever happened to i-f-c-literally
|
284
|
462 (let (file-name-handler-alist)
|
314
|
463 (insert-file-contents-internal full-package-filename))
|
284
|
464 (if (not (string= (md5 (current-buffer))
|
|
465 (package-get-info-prop this-package
|
|
466 'md5sum)))
|
314
|
467 (error "Package %s does not match md5 checksum" base-filename)))
|
|
468
|
|
469 ;; Now delete old lisp directory, if any
|
|
470 ;;
|
|
471 ;; Gads, this is ugly. However, we're not supposed to use `concat'
|
|
472 ;; in the name of portability.
|
|
473 (if (and (setq package-lispdir (expand-file-name "lisp" install-dir))
|
|
474 (setq package-lispdir (expand-file-name (symbol-name package)
|
|
475 package-lispdir))
|
|
476 (file-accessible-directory-p package-lispdir))
|
|
477 (progn
|
|
478 (message "Removing old lisp directory \"%s\" ..." package-lispdir)
|
|
479 (sit-for 0)
|
|
480 (package-get-rmtree package-lispdir)
|
|
481 ))
|
|
482
|
|
483 (message "Installing package `%s' ..." package) (sit-for 0)
|
235
|
484 (let ((status
|
314
|
485 (package-admin-add-binary-package full-package-filename
|
|
486 install-dir)))
|
|
487 (if (= status 0)
|
|
488 (progn
|
|
489 ;; clear messages so that only messages from
|
|
490 ;; package-get-init-package are seen, below.
|
|
491 (clear-message)
|
|
492 (if (package-get-init-package package-lispdir)
|
|
493 (progn
|
|
494 (message "Added package `%s'" package)
|
|
495 (sit-for 0)
|
|
496 )
|
|
497 (progn
|
|
498 ;; display message only if there isn't already one.
|
|
499 (if (not (current-message))
|
|
500 (progn
|
|
501 (message "Added package `%s' (errors occurred)"
|
|
502 package)
|
|
503 (sit-for 0)
|
|
504 ))
|
|
505 (if package-status
|
|
506 (setq package-status 'errors))
|
|
507 ))
|
|
508 )
|
|
509 (message "Installation of package %s failed." base-filename)
|
|
510 (sit-for 0)
|
|
511 (switch-to-buffer package-admin-temp-buffer)
|
|
512 (setq package-status nil)
|
|
513 ))
|
235
|
514 (setq found t))
|
|
515 (if (and found package-get-remove-copy)
|
314
|
516 (delete-file full-package-filename))
|
|
517 package-status
|
235
|
518 ))
|
|
519
|
|
520 (defun package-get-info-find-package (which name)
|
294
|
521 "Look in WHICH for the package called NAME and return all the info
|
|
522 associated with it. See `package-get-base' for info on the format
|
|
523 returned.
|
235
|
524
|
|
525 To access fields returned from this, use
|
|
526 `package-get-info-version' to return information about particular a
|
|
527 version. Use `package-get-info-find-prop' to find particular property
|
|
528 from a version returned by `package-get-info-version'."
|
294
|
529 (interactive "xPackage list: \nsPackage Name: ")
|
235
|
530 (if which
|
|
531 (if (eq (caar which) name)
|
|
532 (cdar which)
|
|
533 (if (cdr which)
|
|
534 (package-get-info-find-package (cdr which) name)))))
|
|
535
|
|
536 (defun package-get-info-version (package version)
|
|
537 "In PACKAGE, return the plist associated with a particular VERSION of the
|
|
538 package. PACKAGE is typically as returned by
|
|
539 `package-get-info-find-package'. If VERSION is nil, then return the
|
|
540 first (aka most recent) version. Use `package-get-info-find-prop'
|
|
541 to retrieve a particular property from the value returned by this."
|
314
|
542 (interactive (package-get-interactive-package-query t t))
|
235
|
543 (while (and version package (not (string= (plist-get (car package) 'version) version)))
|
|
544 (setq package (cdr package)))
|
|
545 (if package (car package)))
|
|
546
|
|
547 (defun package-get-info-prop (package-version property)
|
|
548 "In PACKAGE-VERSION, return the value associated with PROPERTY.
|
|
549 PACKAGE-VERSION is typically returned by `package-get-info-version'
|
|
550 and PROPERTY is typically (although not limited to) one of the
|
|
551 following:
|
|
552
|
|
553 version - version of this package
|
|
554 provides - list of symbols provided
|
|
555 requires - list of symbols that are required.
|
|
556 These in turn are provided by other packages.
|
|
557 size - size of the bundled package
|
|
558 md5sum - computed md5 checksum"
|
|
559 (interactive "xPackage Version: \nSProperty")
|
|
560 (plist-get package-version property))
|
|
561
|
|
562 (defun package-get-info-version-prop (package-list package version property)
|
|
563 "In PACKAGE-LIST, search for PACKAGE with this VERSION and return
|
|
564 PROPERTY value."
|
|
565 (package-get-info-prop
|
|
566 (package-get-info-version
|
|
567 (package-get-info-find-package package-list package) version) property))
|
|
568
|
|
569 (defun package-get-set-version-prop (package-list package version
|
|
570 property value)
|
|
571 "A utility to make it easier to add a VALUE for a specific PROPERTY
|
|
572 in this VERSION of a specific PACKAGE kept in the PACKAGE-LIST.
|
|
573 Returns the modified PACKAGE-LIST. Any missing fields are created."
|
|
574 )
|
|
575
|
|
576 (defun package-get-staging-dir (filename)
|
|
577 "Return a good place to stash FILENAME when it is retrieved.
|
|
578 Use `package-get-dir' for directory to store stuff.
|
|
579 Creates `package-get-dir' it it doesn't exist."
|
|
580 (interactive "FPackage filename: ")
|
|
581 (if (not (file-exists-p package-get-dir))
|
|
582 (make-directory package-get-dir))
|
314
|
583 (expand-file-name
|
|
584 (file-name-nondirectory (or (nth 2 (efs-ftp-path filename)) filename))
|
|
585 (file-name-as-directory package-get-dir)))
|
235
|
586
|
|
587
|
|
588 (defun package-get-remote-filename (search filename)
|
|
589 "Return FILENAME as a remote filename.
|
|
590 It first checks if FILENAME already is a remote filename. If it is
|
|
591 not, then it uses the (car search) as the remote site-name and the (cadr
|
|
592 search) as the remote-directory and concatenates filename. In other
|
|
593 words
|
|
594 site-name:remote-directory/filename
|
|
595 "
|
|
596 (if (efs-ftp-path filename)
|
|
597 filename
|
298
|
598 (let ((dir (cadr search)))
|
|
599 (concat "/"
|
|
600 (car search) ":"
|
|
601 (if (string-match "/$" dir)
|
|
602 dir
|
|
603 (concat dir "/"))
|
|
604 filename))))
|
235
|
605
|
|
606
|
|
607 (defun package-get-installedp (package version)
|
|
608 "Determine if PACKAGE with VERSION has already been installed.
|
|
609 I'm not sure if I want to do this by searching directories or checking
|
263
|
610 some built in variables. For now, use packages-package-list."
|
|
611 ;; Use packages-package-list which contains name and version
|
294
|
612 (equal (plist-get
|
|
613 (package-get-info-find-package packages-package-list
|
|
614 package) ':version)
|
|
615 (if (floatp version) version (string-to-number version))))
|
235
|
616
|
294
|
617 ;;;###autoload
|
235
|
618 (defun package-get-package-provider (sym)
|
|
619 "Search for a package that provides SYM and return the name and
|
|
620 version. Searches in `package-get-base' for SYM. If SYM is a
|
|
621 consp, then it must match a corresponding (provide (SYM VERSION)) from
|
|
622 the package."
|
|
623 (interactive "SSymbol: ")
|
|
624 (let ((packages package-get-base)
|
|
625 (done nil)
|
|
626 (found nil))
|
|
627 (while (and (not done) packages)
|
237
|
628 (let* ((this-name (caar packages))
|
|
629 (this-package (cdr (car packages)))) ;strip off package name
|
235
|
630 (while (and (not done) this-package)
|
237
|
631 (if (or (eq this-name sym)
|
|
632 (eq (cons this-name
|
|
633 (package-get-info-prop (car this-package) 'version))
|
|
634 sym)
|
|
635 (member sym (package-get-info-prop (car this-package) 'provides)))
|
235
|
636 (progn (setq done t)
|
|
637 (setq found (list (caar packages)
|
|
638 (package-get-info-prop (car this-package) 'version))))
|
|
639 (setq this-package (cdr this-package)))))
|
|
640 (setq packages (cdr packages)))
|
|
641 found))
|
|
642
|
286
|
643 ;;
|
|
644 ;; customize interfaces.
|
|
645 ;; The group is in this file so that custom loads includes this file.
|
|
646 ;;
|
|
647 (defgroup packages nil
|
|
648 "Configure XEmacs packages."
|
|
649 :group 'emacs)
|
|
650
|
292
|
651 ;;;###autoload
|
286
|
652 (defun package-get-custom ()
|
|
653 "Fetch and install the latest versions of all customized packages."
|
|
654 (interactive)
|
|
655 ;; Load a fresh copy
|
|
656 (load "package-get-custom.el")
|
|
657 (mapcar (lambda (pkg)
|
|
658 (if (eval (intern (concat (symbol-name (car pkg)) "-package")))
|
|
659 (package-get-all (car pkg) nil))
|
|
660 t)
|
|
661 package-get-base))
|
|
662
|
288
|
663 (defun package-get-ever-installed-p (pkg &optional notused)
|
286
|
664 (string-match "-package$" (symbol-name pkg))
|
|
665 (custom-initialize-set
|
|
666 pkg
|
|
667 (if (package-get-info-find-package
|
|
668 packages-package-list
|
|
669 (intern (substring (symbol-name pkg) 0 (match-beginning 0))))
|
|
670 t)))
|
|
671
|
288
|
672 (defun package-get-file-installed-p (file &optional paths)
|
|
673 "Return absolute-path of FILE if FILE exists in PATHS.
|
|
674 If PATHS is omitted, `load-path' is used."
|
|
675 (if (null paths)
|
|
676 (setq paths load-path)
|
|
677 )
|
|
678 (catch 'tag
|
|
679 (let (path)
|
|
680 (while paths
|
|
681 (setq path (expand-file-name file (car paths)))
|
|
682 (if (file-exists-p path)
|
|
683 (throw 'tag path)
|
|
684 )
|
|
685 (setq paths (cdr paths))
|
|
686 ))))
|
|
687
|
286
|
688 (defun package-get-create-custom ()
|
|
689 "Creates a package customization file package-get-custom.el.
|
|
690 Entries in the customization file are retrieved from package-get-base.el."
|
|
691 (interactive)
|
|
692 ;; Load a fresh copy
|
|
693 (let ((custom-buffer (find-file-noselect
|
288
|
694 (or (package-get-file-installed-p
|
|
695 "package-get-custom.el")
|
314
|
696 (expand-file-name
|
|
697 "package-get-custom.el"
|
|
698 (file-name-directory
|
|
699 (package-get-file-installed-p
|
|
700 "package-get-base.el"))
|
|
701 ))))
|
286
|
702 (pkg-groups nil))
|
|
703
|
|
704 ;; clear existing stuff
|
|
705 (delete-region (point-min custom-buffer)
|
|
706 (point-max custom-buffer) custom-buffer)
|
|
707 (insert-string "(require 'package-get)\n" custom-buffer)
|
|
708
|
|
709 (mapcar (lambda (pkg)
|
|
710 (let ((category (plist-get (car (cdr pkg)) 'category)))
|
|
711 (or (memq (intern category) pkg-groups)
|
|
712 (progn
|
|
713 (setq pkg-groups (cons (intern category) pkg-groups))
|
|
714 (insert-string
|
|
715 (concat "(defgroup " category "-packages nil\n"
|
|
716 " \"" category " package group\"\n"
|
|
717 " :group 'packages)\n\n") custom-buffer)))
|
|
718
|
|
719 (insert-string
|
|
720 (concat "(defcustom " (symbol-name (car pkg))
|
|
721 "-package nil \n"
|
|
722 " \"" (plist-get (car (cdr pkg)) 'description) "\"\n"
|
|
723 " :group '" category "-packages\n"
|
288
|
724 " :initialize 'package-get-ever-installed-p\n"
|
286
|
725 " :type 'boolean)\n\n") custom-buffer)))
|
294
|
726 package-get-base) custom-buffer)
|
286
|
727 )
|
|
728
|
|
729 ;; need this first to avoid infinite dependency loops
|
|
730 (provide 'package-get)
|
|
731
|
|
732 ;; potentially update the custom dependencies every time we load this
|
288
|
733 (let ((custom-file (package-get-file-installed-p "package-get-custom.el"))
|
|
734 (package-file (package-get-file-installed-p "package-get-base.el")))
|
286
|
735 ;; update custom file if it doesn't exist
|
|
736 (if (or (not custom-file)
|
|
737 (and (< (car (nth 5 (file-attributes custom-file)))
|
|
738 (car (nth 5 (file-attributes package-file))))
|
|
739 (< (car (nth 5 (file-attributes custom-file)))
|
|
740 (car (nth 5 (file-attributes package-file))))))
|
|
741 (save-excursion
|
|
742 (message "generating package customizations...")
|
|
743 (set-buffer (package-get-create-custom))
|
|
744 (save-buffer)
|
|
745 (message "generating package customizations...done")))
|
|
746 (load "package-get-custom.el"))
|
|
747
|
235
|
748 ;;; package-get.el ends here
|