Mercurial > emacs
comparison lisp/cedet/inversion.el @ 104407:4af663a1c4ab
cedet-cscope.el, cedet-edebug.el, cedet-global.el, cedet-idutils.el,
cedet.el, inversion.el, pulse.el: Initial version, from CEDET's
common/ directory.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sat, 22 Aug 2009 19:04:43 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
104406:399d233ddb97 | 104407:4af663a1c4ab |
---|---|
1 ;;; inversion.el --- When you need something in version XX.XX | |
2 | |
3 ;;; Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2009 | |
4 ;;; Free Software Foundation, Inc. | |
5 | |
6 ;; Author: Eric M. Ludlam <zappo@gnu.org> | |
7 ;; Version: 0.2 | |
8 ;; Keywords: OO, lisp | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation, either version 3 of the License, or | |
15 ;; (at your option) any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
24 | |
25 ;;; Commentary: | |
26 ;; | |
27 ;; Keeping track of rapidly developing software is a tough thing to | |
28 ;; do, especially if you want to have co-dependent packages which all | |
29 ;; move at different rates. | |
30 ;; | |
31 ;; This library provides a framework for specifying version numbers | |
32 ;; and (as side effect) have a flexible way of getting a desired feature set. | |
33 ;; | |
34 ;; If you would like to use this package to satisfy dependency replace this: | |
35 ;; | |
36 ;; (require 'spiffy) | |
37 ;; | |
38 ;; with this: | |
39 ;; | |
40 ;; (require 'inversion) | |
41 ;; (inversion-require 'spiffy "1.0") | |
42 ;; | |
43 ;; If you feel the need to not throw errors, you can do this instead: | |
44 ;; | |
45 ;; (let ((err (inversion-test 'spiffy "1.0"))) | |
46 ;; (if err (your-stuff-here))) | |
47 ;; | |
48 ;; If you new package (2.0) needs to make sure a load file from your | |
49 ;; package is compatible, use this test: | |
50 ;; | |
51 ;; (if (not (inversion-reverse-test 'spiffy version-from-file)) | |
52 ;; ;; Everything ok | |
53 ;; (do stuff) | |
54 ;; ;; Out of date | |
55 ;; (import-old-code)) | |
56 ;; | |
57 ;; If you would like to make inversion optional, do this: | |
58 ;; | |
59 ;; (or (require 'inversion nil t) | |
60 ;; (defun inversion-test (p v) | |
61 ;; (string= v (symbol-value | |
62 ;; (intern-soft (concat (symbol-string p) "-version")))))) | |
63 ;; | |
64 ;; Or modify to specify `inversion-require' instead. | |
65 ;; | |
66 ;; TODO: | |
67 ;; Offer to download newer versions of a package. | |
68 | |
69 ;;; History: | |
70 ;; | |
71 ;; Sept 3, 2002: First general publication. | |
72 | |
73 ;;; Code: | |
74 | |
75 (defvar inversion-version "1.3" | |
76 "Current version of InVersion.") | |
77 (defvar inversion-incompatible-version "0.1alpha1" | |
78 "An earlier release which is incompatible with this release.") | |
79 | |
80 (defconst inversion-decoders | |
81 '( | |
82 (alpha "^\\([0-9]+\\)\\.\\([0-9]+\\)\\s-*alpha\\([0-9]+\\)?$" 3) | |
83 (beta "^\\([0-9]+\\)\\.\\([0-9]+\\)\\s-*beta\\([0-9]+\\)?$" 3) | |
84 (beta "^\\([0-9]+\\)\\.\\([0-9]+\\)\\s-*(beta\\([0-9]+\\)?)" 3) | |
85 (prerelease "^\\([0-9]+\\)\\.\\([0-9]+\\)\\s-*pre\\([0-9]+\\)?$" 3) | |
86 (full "^\\([0-9]+\\)\\.\\([0-9]+\\)$" 2) | |
87 (fullsingle "^\\([0-9]+\\)$" 1) | |
88 (patch "^\\([0-9]+\\)\\.\\([0-9]+\\) (patch \\([0-9]+\\))" 3) | |
89 (point "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" 3) | |
90 (build "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\).\\([0-9]+\\)$" 4) | |
91 ) | |
92 "List of decoders for version strings. | |
93 Each decoder is of the form: | |
94 | |
95 ( RELEASE-TYPE REGEXP MAX ) | |
96 | |
97 RELEASE-TYPE is a symbol specifying something like `beta' or `alpha'. | |
98 REGEXP is the regular expression to match a version string. | |
99 MAX is the maximum number of match-numbers in the release number. | |
100 Decoders must be ordered to decode least stable versions before the | |
101 more stable ones.") | |
102 | |
103 ;;; Version Checking | |
104 ;; | |
105 (defun inversion-decode-version (version-string) | |
106 "Decode VERSION-STRING into an encoded list. | |
107 Return value is of the form: | |
108 (RELEASE MAJOR MINOR ...) | |
109 where RELEASE is a symbol such as `full', or `beta'." | |
110 (let ((decoders inversion-decoders) | |
111 (result nil)) | |
112 (while (and decoders (not result)) | |
113 (if (string-match (nth 1 (car decoders)) version-string) | |
114 (let ((ver nil) | |
115 (num-left (nth 2 (car decoders))) | |
116 (count 1)) | |
117 (while (<= count num-left) | |
118 (setq ver (cons | |
119 (if (match-beginning count) | |
120 (string-to-number | |
121 (substring version-string | |
122 (match-beginning count) | |
123 (match-end count))) | |
124 1) | |
125 ver) | |
126 count (1+ count))) | |
127 (setq result (cons (caar decoders) (nreverse ver)))) | |
128 (setq decoders (cdr decoders)))) | |
129 result)) | |
130 | |
131 (defun inversion-package-version (package) | |
132 "Return the decoded version for PACKAGE." | |
133 (let ((ver (symbol-value | |
134 (intern-soft | |
135 (concat (symbol-name package) | |
136 "-version")))) | |
137 (code nil)) | |
138 (unless ver | |
139 (error "Package %S does not define %S-version" package package)) | |
140 ;; Decode the code | |
141 (setq code (inversion-decode-version ver)) | |
142 (unless code | |
143 (error "%S-version value cannot be decoded" package)) | |
144 code)) | |
145 | |
146 (defun inversion-package-incompatibility-version (package) | |
147 "Return the decoded incompatibility version for PACKAGE. | |
148 The incompatibility version is specified by the programmer of | |
149 a package when a package is not backward compatible. It is | |
150 not an indication of new features or bug fixes." | |
151 (let ((ver (symbol-value | |
152 (intern-soft | |
153 (concat (symbol-name package) | |
154 "-incompatible-version"))))) | |
155 (if (not ver) | |
156 nil | |
157 ;; Decode the code | |
158 (inversion-decode-version ver)))) | |
159 | |
160 (defun inversion-recode (code) | |
161 "Convert CODE into a string." | |
162 (let ((r (nth 0 code)) ; release-type | |
163 (n (nth 1 code)) ; main number | |
164 (i (nth 2 code)) ; first increment | |
165 (p (nth 3 code))) ; second increment | |
166 (cond | |
167 ((eq r 'full) | |
168 (setq r "" p "")) | |
169 ((eq r 'point) | |
170 (setq r "."))) | |
171 (format "%s.%s%s%s" n i r p))) | |
172 | |
173 (defun inversion-release-to-number (release-symbol) | |
174 "Convert RELEASE-SYMBOL into a number." | |
175 (let* ((ra (assoc release-symbol inversion-decoders)) | |
176 (rn (- (length inversion-decoders) | |
177 (length (member ra inversion-decoders))))) | |
178 rn)) | |
179 | |
180 (defun inversion-= (ver1 ver2) | |
181 "Return non-nil if VER1 is equal to VER2." | |
182 (equal ver1 ver2)) | |
183 | |
184 (defun inversion-< (ver1 ver2) | |
185 "Return non-nil if VER1 is less than VER2." | |
186 (let ((v1-0 (inversion-release-to-number (nth 0 ver1))) | |
187 (v1-1 (nth 1 ver1)) | |
188 (v1-2 (nth 2 ver1)) | |
189 (v1-3 (nth 3 ver1)) | |
190 (v1-4 (nth 4 ver1)) | |
191 ;; v2 | |
192 (v2-0 (inversion-release-to-number (nth 0 ver2))) | |
193 (v2-1 (nth 1 ver2)) | |
194 (v2-2 (nth 2 ver2)) | |
195 (v2-3 (nth 3 ver2)) | |
196 (v2-4 (nth 4 ver2)) | |
197 ) | |
198 (or (and (= v1-0 v2-0) | |
199 (= v1-1 v2-1) | |
200 (= v1-2 v2-2) | |
201 (= v1-3 v2-3) | |
202 v1-4 v2-4 ; all or nothin if elt - is = | |
203 (< v1-4 v2-4)) | |
204 (and (= v1-0 v2-0) | |
205 (= v1-1 v2-1) | |
206 (= v1-2 v2-2) | |
207 v1-3 v2-3 ; all or nothin if elt - is = | |
208 (< v1-3 v2-3)) | |
209 (and (= v1-1 v2-1) | |
210 (< v1-2 v2-2)) | |
211 (and (< v1-1 v2-1)) | |
212 (and (< v1-0 v2-0) | |
213 (= v1-1 v2-1) | |
214 (= v1-2 v2-2) | |
215 ) | |
216 ))) | |
217 | |
218 (defun inversion-check-version (version incompatible-version | |
219 minimum &rest reserved) | |
220 "Check that a given version meets the minimum requirement. | |
221 VERSION, INCOMPATIBLE-VERSION and MINIMUM are of similar format to | |
222 return entries of `inversion-decode-version', or a classic version | |
223 string. INCOMPATIBLE-VERSION can be nil. | |
224 RESERVED arguments are kept for a later use. | |
225 Return: | |
226 - nil if everything is ok | |
227 - 'outdated if VERSION is less than MINIMUM. | |
228 - 'incompatible if VERSION is not backward compatible with MINIMUM. | |
229 - t if the check failed." | |
230 (let ((code (if (stringp version) | |
231 (inversion-decode-version version) | |
232 version)) | |
233 (req (if (stringp minimum) | |
234 (inversion-decode-version minimum) | |
235 minimum)) | |
236 ) | |
237 ;; Perform a test. | |
238 (cond | |
239 ((inversion-= code req) | |
240 ;; Same version.. Yay! | |
241 nil) | |
242 ((inversion-< code req) | |
243 ;; Version is too old! | |
244 'outdated) | |
245 ((inversion-< req code) | |
246 ;; Newer is installed. What to do? | |
247 (let ((incompatible | |
248 (if (stringp incompatible-version) | |
249 (inversion-decode-version incompatible-version) | |
250 incompatible-version))) | |
251 (cond | |
252 ((not incompatible) nil) | |
253 ((or (inversion-= req incompatible) | |
254 (inversion-< req incompatible)) | |
255 ;; The requested version is = or < than what the package | |
256 ;; maintainer says is incompatible. | |
257 'incompatible) | |
258 ;; Things are ok. | |
259 (t nil)))) | |
260 ;; Check failed | |
261 (t t)))) | |
262 | |
263 (defun inversion-test (package minimum &rest reserved) | |
264 "Test that PACKAGE meets the MINIMUM version requirement. | |
265 PACKAGE is a symbol, similar to what is passed to `require'. | |
266 MINIMUM is of similar format to return entries of | |
267 `inversion-decode-version', or a classic version string. | |
268 RESERVED arguments are kept for a later user. | |
269 This depends on the symbols `PACKAGE-version' and optionally | |
270 `PACKAGE-incompatible-version' being defined in PACKAGE. | |
271 Return nil if everything is ok. Return an error string otherwise." | |
272 (let ((check (inversion-check-version | |
273 (inversion-package-version package) | |
274 (inversion-package-incompatibility-version package) | |
275 minimum reserved))) | |
276 (cond | |
277 ((null check) | |
278 ;; Same version.. Yay! | |
279 nil) | |
280 ((eq check 'outdated) | |
281 ;; Version is too old! | |
282 (format "You need to upgrade package %s to %s" package minimum)) | |
283 ((eq check 'incompatible) | |
284 ;; Newer is installed but the requested version is = or < than | |
285 ;; what the package maintainer says is incompatible, then throw | |
286 ;; that error. | |
287 (format "Package %s version is not backward compatible with %s" | |
288 package minimum)) | |
289 ;; Check failed | |
290 (t "Inversion version check failed.")))) | |
291 | |
292 (defun inversion-reverse-test (package oldversion &rest reserved) | |
293 "Test that PACKAGE at OLDVERSION is still compatible. | |
294 If something like a save file is loaded at OLDVERSION, this | |
295 test will identify if OLDVERSION is compatible with the current version | |
296 of PACKAGE. | |
297 PACKAGE is a symbol, similar to what is passed to `require'. | |
298 OLDVERSION is of similar format to return entries of | |
299 `inversion-decode-version', or a classic version string. | |
300 RESERVED arguments are kept for a later user. | |
301 This depends on the symbols `PACKAGE-version' and optionally | |
302 `PACKAGE-incompatible-version' being defined in PACKAGE. | |
303 Return nil if everything is ok. Return an error string otherwise." | |
304 (let ((check (inversion-check-version | |
305 (inversion-package-version package) | |
306 (inversion-package-incompatibility-version package) | |
307 oldversion reserved))) | |
308 (cond | |
309 ((null check) | |
310 ;; Same version.. Yay! | |
311 nil) | |
312 ((eq check 'outdated) | |
313 ;; Version is too old! | |
314 (format "Package %s version %s is not compatible with current version" | |
315 package oldversion)) | |
316 ((eq check 'incompatible) | |
317 ;; Newer is installed but the requested version is = or < than | |
318 ;; what the package maintainer says is incompatible, then throw | |
319 ;; that error. | |
320 (format "Package %s version is not backward compatible with %s" | |
321 package oldversion)) | |
322 ;; Check failed | |
323 (t "Inversion version check failed.")))) | |
324 | |
325 (defun inversion-require (package version &optional file directory | |
326 &rest reserved) | |
327 "Declare that you need PACKAGE with at least VERSION. | |
328 PACKAGE might be found in FILE. (See `require'.) | |
329 Throws an error if VERSION is incompatible with what is installed. | |
330 Optional argument DIRECTORY is a location where new versions of | |
331 this tool can be located. If there is a versioning problem and | |
332 DIRECTORY is provided, inversion will offer to download the file. | |
333 Optional argument RESERVED is saved for later use." | |
334 (require package file) | |
335 (let ((err (inversion-test package version))) | |
336 (when err | |
337 (if directory | |
338 (inversion-download-package-ask err package directory version) | |
339 (error err))) | |
340 ;; Return the package symbol that was required. | |
341 package)) | |
342 | |
343 (defun inversion-require-emacs (emacs-ver xemacs-ver) | |
344 "Declare that you need either EMACS-VER, or XEMACS-VER. | |
345 Only checks one based on which kind of Emacs is being run." | |
346 (let ((err (inversion-test 'emacs | |
347 (if (featurep 'xemacs) | |
348 xemacs-ver | |
349 emacs-ver)))) | |
350 (if err (error err) | |
351 ;; Something nice... | |
352 t))) | |
353 | |
354 (defconst inversion-find-data | |
355 '("(def\\(var\\|const\\)\\s-+%s-%s\\s-+\"\\([^\"]+\\)" 2) | |
356 "Regexp template and match data index of a version string.") | |
357 | |
358 (defun inversion-find-version (package) | |
359 "Search for the version and incompatible version of PACKAGE. | |
360 Does not load PACKAGE nor requires that it has been previously loaded. | |
361 Search in the directories in `load-path' for a PACKAGE.el library. | |
362 Visit the file found and search for the declarations of variables or | |
363 constants `PACKAGE-version' and `PACKAGE-incompatible-version'. The | |
364 value of these variables must be a version string. | |
365 | |
366 Return a pair (VERSION-STRING . INCOMPATIBLE-VERSION-STRING) where | |
367 INCOMPATIBLE-VERSION-STRING can be nil. | |
368 Return nil when VERSION-STRING was not found." | |
369 (let* ((file (locate-library (format "%s.el" package) t)) | |
370 (tag (car inversion-find-data)) | |
371 (idx (nth 1 inversion-find-data)) | |
372 version) | |
373 (when file | |
374 (with-temp-buffer | |
375 ;; The 3000 is a bit arbitrary, but should cut down on | |
376 ;; fileio as version info usually is at the very top | |
377 ;; of a file. AFter a long commentary could be bad. | |
378 (insert-file-contents-literally file nil 0 3000) | |
379 (goto-char (point-min)) | |
380 (when (re-search-forward (format tag package 'version) nil t) | |
381 (setq version (list (match-string idx))) | |
382 (goto-char (point-min)) | |
383 (when (re-search-forward | |
384 (format tag package 'incompatible-version) nil t) | |
385 (setcdr version (match-string idx)))))) | |
386 version)) | |
387 | |
388 (defun inversion-add-to-load-path (package minimum | |
389 &optional installdir | |
390 &rest subdirs) | |
391 "Add the PACKAGE path to `load-path' if necessary. | |
392 MINIMUM is the minimum version requirement of PACKAGE. | |
393 Optional argument INSTALLDIR is the base directory where PACKAGE is | |
394 installed. It defaults to `default-directory'/PACKAGE. | |
395 SUBDIRS are sub-directories to add to `load-path', following the main | |
396 INSTALLDIR path." | |
397 (let ((ver (inversion-find-version package))) | |
398 ;; If PACKAGE not found or a bad version already in `load-path', | |
399 ;; prepend the new PACKAGE path, so it will be loaded first. | |
400 (when (or (not ver) | |
401 (and | |
402 (inversion-check-version (car ver) (cdr ver) minimum) | |
403 (message "Outdated %s %s shadowed to meet minimum version %s" | |
404 package (car ver) minimum) | |
405 t)) | |
406 (let* ((default-directory | |
407 (or installdir | |
408 (expand-file-name (format "./%s" package)))) | |
409 subdir) | |
410 (when (file-directory-p default-directory) | |
411 ;; Add SUBDIRS | |
412 (while subdirs | |
413 (setq subdir (expand-file-name (car subdirs)) | |
414 subdirs (cdr subdirs)) | |
415 (when (file-directory-p subdir) | |
416 ;;(message "%S added to `load-path'" subdir) | |
417 (add-to-list 'load-path subdir))) | |
418 ;; Add the main path | |
419 ;;(message "%S added to `load-path'" default-directory) | |
420 (add-to-list 'load-path default-directory)) | |
421 ;; We get to this point iff we do not accept or there is no | |
422 ;; system file. Lets check the version of what we just | |
423 ;; installed... just to be safe. | |
424 (let ((newver (inversion-find-version package))) | |
425 (if (not newver) | |
426 (error "Failed to find version for newly installed %s" | |
427 package)) | |
428 (if (inversion-check-version (car newver) (cdr newver) minimum) | |
429 (error "Outdated %s %s just installed" package (car newver))) | |
430 ))))) | |
431 | |
432 ;;; Inversion tests | |
433 ;; | |
434 (defun inversion-unit-test () | |
435 "Test inversion to make sure it can identify different version strings." | |
436 (interactive) | |
437 (let ((c1 (inversion-package-version 'inversion)) | |
438 (c1i (inversion-package-incompatibility-version 'inversion)) | |
439 (c2 (inversion-decode-version "1.3alpha2")) | |
440 (c3 (inversion-decode-version "1.3beta4")) | |
441 (c4 (inversion-decode-version "1.3 beta5")) | |
442 (c5 (inversion-decode-version "1.3.4")) | |
443 (c6 (inversion-decode-version "2.3alpha")) | |
444 (c7 (inversion-decode-version "1.3")) | |
445 (c8 (inversion-decode-version "1.3pre1")) | |
446 (c9 (inversion-decode-version "2.4 (patch 2)")) | |
447 (c10 (inversion-decode-version "2.4 (patch 3)")) | |
448 (c11 (inversion-decode-version "2.4.2.1")) | |
449 (c12 (inversion-decode-version "2.4.2.2")) | |
450 ) | |
451 (if (not (and | |
452 (inversion-= c1 c1) | |
453 (inversion-< c1i c1) | |
454 (inversion-< c2 c3) | |
455 (inversion-< c3 c4) | |
456 (inversion-< c4 c5) | |
457 (inversion-< c5 c6) | |
458 (inversion-< c2 c4) | |
459 (inversion-< c2 c5) | |
460 (inversion-< c2 c6) | |
461 (inversion-< c3 c5) | |
462 (inversion-< c3 c6) | |
463 (inversion-< c7 c6) | |
464 (inversion-< c4 c7) | |
465 (inversion-< c2 c7) | |
466 (inversion-< c8 c6) | |
467 (inversion-< c8 c7) | |
468 (inversion-< c4 c8) | |
469 (inversion-< c2 c8) | |
470 (inversion-< c9 c10) | |
471 (inversion-< c10 c11) | |
472 (inversion-< c11 c12) | |
473 ;; Negatives | |
474 (not (inversion-< c3 c2)) | |
475 (not (inversion-< c4 c3)) | |
476 (not (inversion-< c5 c4)) | |
477 (not (inversion-< c6 c5)) | |
478 (not (inversion-< c7 c2)) | |
479 (not (inversion-< c7 c8)) | |
480 (not (inversion-< c12 c11)) | |
481 ;; Test the tester on inversion | |
482 (not (inversion-test 'inversion inversion-version)) | |
483 ;; Test that we throw an error | |
484 (inversion-test 'inversion "0.0.0") | |
485 (inversion-test 'inversion "1000.0") | |
486 )) | |
487 (error "Inversion tests failed") | |
488 (message "Inversion tests passed.")))) | |
489 | |
490 ;;; URL and downloading code | |
491 ;; | |
492 (defun inversion-locate-package-files (package directory &optional version) | |
493 "Get a list of distributions of PACKAGE from DIRECTORY. | |
494 DIRECTORY can be an ange-ftp compatible filename, such as: | |
495 \"/ftp@ftp1.sourceforge.net/pub/sourceforge/PACKAGE\" | |
496 If it is a URL, wget will be used for download. | |
497 Optional argument VERSION will restrict the list of available versions | |
498 to the file matching VERSION exactly, or nil." | |
499 ;;DIRECTORY should also allow a URL: | |
500 ;; \"http://ftp1.sourceforge.net/PACKAGE\" | |
501 ;; but then I can get file listings easily. | |
502 (if (symbolp package) (setq package (symbol-name package))) | |
503 (directory-files directory t | |
504 (if version | |
505 (concat "^" package "-" version "\\>") | |
506 package))) | |
507 | |
508 (defvar inversion-package-common-tails '( ".tar.gz" | |
509 ".tar" | |
510 ".zip" | |
511 ".gz" | |
512 ) | |
513 "Common distribution mechanisms for Emacs Lisp packages.") | |
514 | |
515 (defun inversion-locate-package-files-and-split (package directory &optional version) | |
516 "Use `inversion-locate-package-files' to get a list of PACKAGE files. | |
517 DIRECTORY is the location where distributions of PACKAGE are. | |
518 VERSION is an optional argument specifying a version to restrict to. | |
519 The return list is an alist with the version string in the CAR, | |
520 and the full path name in the CDR." | |
521 (if (symbolp package) (setq package (symbol-name package))) | |
522 (let ((f (inversion-locate-package-files package directory version)) | |
523 (out nil)) | |
524 (while f | |
525 (let* ((file (car f)) | |
526 (dist (file-name-nondirectory file)) | |
527 (tails inversion-package-common-tails) | |
528 (verstring nil)) | |
529 (while (and tails (not verstring)) | |
530 (when (string-match (concat (car tails) "$") dist) | |
531 (setq verstring | |
532 (substring dist (1+ (length package)) (match-beginning 0)))) | |
533 (setq tails (cdr tails))) | |
534 (if (not verstring) | |
535 (error "Cannot decode version for %s" dist)) | |
536 (setq out | |
537 (cons | |
538 (cons verstring file) | |
539 out)) | |
540 (setq f (cdr f)))) | |
541 out)) | |
542 | |
543 (defun inversion-download-package-ask (err package directory version) | |
544 "Due to ERR, offer to download PACKAGE from DIRECTORY. | |
545 The package should have VERSION available for download." | |
546 (if (symbolp package) (setq package (symbol-name package))) | |
547 (let ((files (inversion-locate-package-files-and-split | |
548 package directory version))) | |
549 (if (not files) | |
550 (error err) | |
551 (if (not (y-or-n-p (concat err ": Download update? "))) | |
552 (error err) | |
553 (let ((dest (read-directory-name (format "Download %s to: " | |
554 package) | |
555 t))) | |
556 (if (> (length files) 1) | |
557 (setq files | |
558 (list | |
559 "foo" ;; ignored | |
560 (read-file-name "Version to download: " | |
561 directory | |
562 files | |
563 t | |
564 (concat | |
565 (file-name-as-directory directory) | |
566 package) | |
567 nil)))) | |
568 | |
569 (copy-file (cdr (car files)) dest)))))) | |
570 | |
571 (defun inversion-upgrade-package (package &optional directory) | |
572 "Try to upgrade PACKAGE in DIRECTORY is available." | |
573 (interactive "sPackage to upgrade: ") | |
574 (if (stringp package) (setq package (intern package))) | |
575 (if (not directory) | |
576 ;; Hope that the package maintainer specified. | |
577 (setq directory (symbol-value (or (intern-soft | |
578 (concat (symbol-name package) | |
579 "-url")) | |
580 (intern-soft | |
581 (concat (symbol-name package) | |
582 "-directory")))))) | |
583 (let ((files (inversion-locate-package-files-and-split | |
584 package directory)) | |
585 (cver (inversion-package-version package)) | |
586 (newer nil)) | |
587 (mapc (lambda (f) | |
588 (if (inversion-< cver (inversion-decode-version (car f))) | |
589 (setq newer (cons f newer)))) | |
590 files) | |
591 newer | |
592 )) | |
593 | |
594 ;; (inversion-upgrade-package | |
595 ;; 'semantic | |
596 ;; "/ftp@ftp1.sourceforge.net:/pub/sourceforge/cedet") | |
597 | |
598 ;; "/ftp@ftp1.sourceforge.net:/pub/sourceforge/cedet" | |
599 (provide 'inversion) | |
600 | |
601 ;;; inversion.el ends here |