1 ;; edict-update.el --- Dictionary update functions for edict.el
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
5 ;; Author: Stephen J. Turnbull <stephen@xemacs.org>
6 ;; Keywords: mule, edict, dictionary
8 ;; Created: 27 January 2002
9 ;; Last Update: 27 January 2002
10 ;; Maintainer: Stephen J. Turnbull <stephen@xemacs.org>
12 ;; This file is part of XEmacs.
14 ;; XEmacs is free software; you can redistribute it and/or modify it
15 ;; under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your
17 ;; option) any later version.
19 ;; XEmacs is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with XEmacs; if not, write to the Free Software Foundation,
26 ;; Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 ;; Functions to update EDICT dictionaries and to report private dictionary
35 ;; Customize `edict-dictionary-path', `edict-dictionaries',
36 ;; `edict-update-file-list', `edict-update-staging',
37 ;; `edict-update-local-mirror', and `edict-update-archive-url'
38 ;; appropriately. Then "M-x edict-update RET" and if you're lucky,
43 ;; 1. Use the package transport stuff I wrote; test it here.
44 ;; 2. Think carefully about the process of updating packages. The
45 ;; problem is that there should be a difference between updates
46 ;; done by administrators and updates done by ordinary users. The
47 ;; administrators should update the main hierarchies, while the
48 ;; users should update their personal packages. This probably
49 ;; involves checking for write permission and/or ownership on the
50 ;; package hierarchy and possibly some kind of "su.el"
55 (require 'edict) ; for dictionary list and path
57 ;;; User customization
59 (defgroup edict-update nil
60 "Customization of functions used to keep your EDICT current."
63 (defcustom edict-update-file-list nil
64 "List of files to update.
66 If nil, default to the value of `edict-dictionaries'."
67 ;; #### should default to something else for package administrators,
68 ;; like all known edict dictionaries.
72 (defcustom edict-update-staging "/tmp/edict"
73 "Basename of temporary directory for staging EDICT dictionary archives.
75 Should not end in a slash, because it will be used to generate a unique
76 name for a directory to be created. The directory is deleted after use.
78 If `edict-update-local-mirror' is non-nil, this variable is ignored."
79 :type 'file ; not directory
82 (defcustom edict-update-local-mirror nil
83 "Path to a local mirror of the EDICT dictionary archives.
85 Files downloaded here are persistent. This location takes precedence
86 over `edict-update-staging'."
87 :type '(choice directory
88 (const :tag "none" nil))
91 (defcustom edict-update-archive-url
92 "ftp://ftp.cc.monash.edu.au/pub/nihongo/"
93 "URL pointing to a host and directory serving EDICT dictionaries.
95 Should end with a slash.
97 Default is Jim Breen's Nihongo Archive at Monash University,
98 ftp://ftp.cc.monash.edu.au/pub/nihongo/."
99 ;; WE DEMAND AN URL WIDGET!!
101 :group 'edict-update)
103 (defcustom edict-update-sources-alist
104 '(("edict" "edict.gz")
105 ("kanjidic" "kanjidic.gz")
106 ("enamdict" "enamdict.gz"))
107 "Map dictionaries to archive name to download.
109 This isn't really a user customization (should be constant over time and
110 for different mirrors), but made customizable for convenience."
111 :type '(repeat (list string string))
112 :group 'edict-update)
114 ;; #### Evile temporary hack
115 (defvar edict-update-wget-options "-N")
120 (defun edict-update ()
121 "Update edict dictionaries from archives on the 'Net.
123 Customize `edict-dictionary-path', `edict-dictionaries',
124 `edict-update-file-list', `edict-update-staging',
125 `edict-update-local-mirror', and `edict-update-archive-url' to
126 determine how and where to download and install.
128 #### Currently not at all robust, requires wget on the path."
132 (let ((stage (edict-update-setup-stage))
133 ;; #### walk down the path looking for writables, confirm
134 (destination (file-name-as-directory (car edict-dictionary-path)))
135 (sources edict-update-sources-alist)
136 (files (or edict-update-file-list edict-dictionaries)))
137 ;; #### provide for alternative transports
138 (mapc (lambda (source)
139 (when (member (first source) files)
140 ;; #### this is very fragile
142 (concat "cd " stage "; "
143 "wget " edict-update-wget-options " "
144 edict-update-archive-url (second source)))
146 (concat "cd " stage "; "
147 (if edict-update-local-mirror "cp " "mv ")
148 (second source) " " destination))
149 (when (string-match "\\.gz$" (second source))
151 (concat "cd " destination "; " "gunzip " (second source))))))
153 (edict-update-cleanup-stage)))
155 ;; staging area utilities
157 (defun edict-update-setup-stage ()
158 "Determine staging directory, and create it if needed."
160 ;; #### do proper temporary creation
161 (if edict-update-local-mirror
162 (cond ((not (file-exists-p edict-update-local-mirror))
163 (make-directory edict-update-local-mirror t))
164 ((and (file-directory-p edict-update-local-mirror)
165 (not (file-writable-p edict-update-local-mirror)))
166 (error 'file-error "not writable by you"
167 edict-update-local-mirror))
168 ((not (file-directory-p edict-update-local-mirror))
169 (error 'file-already-exists "is not a directory"
170 edict-update-local-mirror)))
171 (if (file-exists-p edict-update-staging)
172 (error "%s exists, move it out of the way, please"
173 edict-update-staging)
174 (make-directory edict-update-staging t)
175 edict-update-staging)))
177 (defun edict-update-cleanup-stage ()
178 "Remove temporary staging area.
180 Files should already have been removed."
182 (unless edict-update-local-mirror
183 (remove-directory edict-update-staging)))
185 (provide 'edict-update)
187 ;;; edict-update.el ends here