/[gentoo-x86]/eclass/myspell.eclass
Gentoo

Contents of /eclass/myspell.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Sun Jan 5 11:39:48 2014 UTC (11 months, 2 weeks ago) by pacho
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +3 -3 lines
Cleanup due http://gentoo.2317880.n4.nabble.com/app-dicts-herd-is-empty-td271273.html

1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/myspell.eclass,v 1.8 2011/12/27 17:55:12 fauli Exp $
4
5 # Author: Kevin F. Quinn <kevquinn@gentoo.org>
6 # Packages: app-dicts/myspell-*
7 # Maintainer: maintainer-needed@gentoo.org
8
9 inherit multilib
10
11 EXPORT_FUNCTIONS src_install pkg_preinst pkg_postinst
12
13 IUSE=""
14
15 SLOT="0"
16
17 # tar, gzip, bzip2 are included in the base profile, but not unzip
18 DEPEND="app-arch/unzip"
19
20 # Dictionaries don't have any runtime dependencies
21 # Myspell dictionaries can be used by hunspell, openoffice and others
22 RDEPEND=""
23
24 # The destination directory for myspell dictionaries
25 MYSPELL_DICTBASE="/usr/share/myspell"
26
27 # Legacy variable for dictionaries installed before eselect-oodict existed
28 # so has to remain for binpkg support. This variable is unmaintained -
29 # if you have a problem with it, emerge app-admin/eselect-oodict.
30 # The location for openoffice softlinks
31 MYSPELL_OOOBASE="/usr/lib/openoffice/share/dict/ooo"
32
33
34 # set array "fields" to the elements of $1, separated by $2.
35 # This saves having to muck about with IFS all over the place.
36 set_fields() {
37 local old_IFS
38 old_IFS="${IFS}"
39 IFS=$2
40 fields=($1)
41 IFS="${old_IFS}"
42 }
43
44 # language is the second element of the ebuild name
45 # myspell-<lang>-<version>
46 get_myspell_lang() {
47 local fields
48 set_fields "${P}" "-"
49 echo ${fields[1]}
50 }
51
52 get_myspell_suffixes() {
53 case $1 in
54 DICT) echo ".aff .dic" ;;
55 HYPH) echo ".dic" ;;
56 THES) echo ".dat .idx" ;;
57 esac
58 }
59
60 # OOo dictionary files are held on the mirrors, rather than
61 # being fetched direct from the OOo site as upstream doesn't
62 # change the name when they rebuild the dictionaries.
63 # <lang>-<country>.zip becomes myspell-<lang>-<country>-version.zip
64 get_myspell_ooo_uri() {
65 local files fields newfile filestem srcfile dict uris
66 files=()
67 uris=""
68 for dict in \
69 "${MYSPELL_SPELLING_DICTIONARIES[@]}" \
70 "${MYSPELL_HYPHENATION_DICTIONARIES[@]}" \
71 "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
72 set_fields "${dict}" ","
73 newfile=${fields[4]// }
74 for file in "${files[@]}"; do
75 [[ ${file} == ${newfile} ]] && continue 2
76 done
77 filestem=${newfile/.zip}
78 files=("${files[@]}" "${newfile}")
79 srcfile="myspell-${filestem}-${PV}.zip"
80 [[ -z ${uris} ]] &&
81 uris="mirror://gentoo/${srcfile}" ||
82 uris="${uris} mirror://gentoo/${srcfile}"
83 done
84 echo "${uris}"
85 }
86
87
88 [[ -z ${SRC_URI} ]] && SRC_URI=$(get_myspell_ooo_uri)
89
90 # Format of dictionary.lst files (from OOo standard
91 # dictionary.lst file):
92 #
93 # List of All Dictionaries to be Loaded by OpenOffice
94 # ---------------------------------------------------
95 # Each Entry in the list have the following space delimited fields
96 #
97 # Field 0: Entry Type "DICT" - spellchecking dictionary
98 # "HYPH" - hyphenation dictionary
99 # "THES" - thesaurus files
100 #
101 # Field 1: Language code from Locale "en" or "de" or "pt" ...
102 #
103 # Field 2: Country Code from Locale "US" or "GB" or "PT"
104 #
105 # Field 3: Root name of file(s) "en_US" or "hyph_de" or "th_en_US"
106 # (do not add extensions to the name)
107
108 # Format of MYSPELL_[SPELLING|HYPHENATION|THESAURUS]_DICTIONARIES:
109 #
110 # Field 0: Language code
111 # Field 1: Country code
112 # Field 2: Root name of dictionary files
113 # Field 3: Description
114 # Field 4: Archive filename
115 #
116 # This format is from the available.lst, hyphavail.lst and
117 # thesavail.lst files on the openoffice.org repository.
118
119 myspell_src_install() {
120 local filen fields entry dictlst
121 cd "${WORKDIR}"
122 # Install the dictionary, hyphenation and thesaurus files.
123 # Create dictionary.lst.<lang> file containing the parts of
124 # OOo's dictionary.lst file for this language, indicating
125 # which dictionaries are relevant for each country variant
126 # of the language.
127 insinto ${MYSPELL_DICTBASE}
128 dictlst="dictionary.lst.$(get_myspell_lang)"
129 echo "# Autogenerated by ${CATEGORY}/${P}" > ${dictlst}
130 for entry in "${MYSPELL_SPELLING_DICTIONARIES[@]}"; do
131 set_fields "${entry}" ","
132 echo "DICT ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
133 doins ${fields[2]}.aff || die "Missing ${fields[2]}.aff"
134 doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
135 done
136 for entry in "${MYSPELL_HYPHENATION_DICTIONARIES[@]}"; do
137 set_fields "${entry}" ","
138 echo "HYPH ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
139 doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
140 done
141 for entry in "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
142 set_fields "${entry}" ","
143 echo "THES ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
144 doins ${fields[2]}.dat || die "Missing ${fields[2]}.dat"
145 doins ${fields[2]}.idx || die "Missing ${fields[2]}.idx"
146 done
147 doins ${dictlst} || die "Failed to install ${dictlst}"
148 # Install any txt files (usually README.txt) as documentation
149 for filen in *.txt; do
150 [[ -s ${filen} ]] && dodoc ${filen}
151 done
152 }
153
154
155 # Add entries in dictionary.lst.<lang> to OOo dictionary.lst
156 # and create softlinks indicated by dictionary.lst.<lang>
157 myspell_pkg_postinst() {
158 # Update for known applications
159 if has_version ">=app-admin/eselect-oodict-20060706"; then
160 if has_version app-office/openoffice; then
161 eselect oodict set myspell-$(get_myspell_lang)
162 fi
163 if has_version app-office/openoffice-bin; then
164 # On AMD64, openoffice-bin is 32-bit so force ABI
165 has_multilib_profile && ABI=x86
166 eselect oodict set myspell-$(get_myspell_lang) --libdir $(get_libdir)
167 fi
168 return
169 fi
170 if has_version app-admin/eselect-oodict; then
171 eselect oodict set myspell-$(get_myspell_lang)
172 return
173 fi
174
175 # Legacy code for dictionaries installed before eselect-oodict existed
176 # so has to remain for binpkg support. This code is unmaintained -
177 # if you have a problem with it, emerge app-admin/eselect-oodict.
178 [[ -d ${MYSPELL_OOOBASE} ]] || return
179 # This stuff is here, not in src_install, as the softlinks are
180 # deliberately _not_ listed in the package database.
181 local dictlst entry fields prefix suffix suffixes filen
182 # Note; can only reach this point if ${MYSPELL_DICTBASE}/${dictlst}
183 # was successfully installed
184 dictlst="dictionary.lst.$(get_myspell_lang)"
185 while read entry; do
186 fields=(${entry})
187 [[ ${fields[0]:0:1} == "#" ]] && continue
188 [[ -f ${MYSPELL_OOOBASE}/dictionary.lst ]] || \
189 touch ${MYSPELL_OOOBASE}/dictionary.lst
190 grep "^${fields[0]} ${fields[1]} ${fields[2]} " \
191 ${MYSPELL_OOOBASE}/dictionary.lst > /dev/null 2>&1 ||
192 echo "${entry}" >> ${MYSPELL_OOOBASE}/dictionary.lst
193 for suffix in $(get_myspell_suffixes ${fields[0]}); do
194 filen="${fields[3]}${suffix}"
195 [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
196 rm -f ${MYSPELL_OOOBASE}/${filen}
197 [[ ! -f ${MYSPELL_OOOBASE}/${filen} ]] &&
198 ln -s ${MYSPELL_DICTBASE}/${filen} \
199 ${MYSPELL_OOOBASE}/${filen}
200 done
201 done < ${MYSPELL_DICTBASE}/${dictlst}
202 }
203
204
205 # Remove softlinks and entries in dictionary.lst - uses
206 # dictionary.<lang>.lst from /usr/share/myspell
207 # Done in preinst (prerm happens after postinst, which overwrites
208 # the dictionary.<lang>.lst file)
209 myspell_pkg_preinst() {
210 # Update for known applications
211 if has_version ">=app-admin/eselect-oodict-20060706"; then
212 if has_version app-office/openoffice; then
213 # When building from source, the default library path is correct
214 eselect oodict unset myspell-$(get_myspell_lang)
215 fi
216 if has_version app-office/openoffice-bin; then
217 # On AMD64, openoffice-bin is 32-bit, so get 32-bit library directory
218 has_multilib_profile && ABI=x86
219 eselect oodict unset myspell-$(get_myspell_lang) --libdir $(get_libdir)
220 fi
221 eselect oodict unset myspell-$(get_myspell_lang) --libdir $(get_libdir)
222 return
223 fi
224 # Previous versions of eselect-oodict didn't cater for -bin on amd64
225 if has_version app-admin/eselect-oodict; then
226 eselect oodict unset myspell-$(get_myspell_lang)
227 return
228 fi
229
230 # Legacy code for dictionaries installed before eselect-oodict existed
231 # Don't delete this; needed for uninstalls and binpkg support.
232 # This code is unmaintained - if you have a problem with it,
233 # emerge app-admin/eselect-oodict.
234 local filen dictlst entry fields removeentry suffix
235 dictlst="dictionary.lst.$(get_myspell_lang)"
236 [[ -d ${MYSPELL_OOOBASE} ]] || return
237 [[ -f ${MYSPELL_DICTBASE}/${dictlst} ]] || return
238 while read entry; do
239 fields=(${entry})
240 [[ ${fields[0]:0:1} == "#" ]] && continue
241 [[ ${fields[3]} == "" ]] && continue
242 # Remove entry from dictionary.lst
243 sed -i -e "/^${fields[0]} ${fields[1]} ${fields[2]} ${fields[3]}$/ { d }" \
244 ${MYSPELL_OOOBASE}/dictionary.lst
245 # See if any other entries in dictionary.lst match the current
246 # dictionary type and filename
247 grep "^${fields[0]} .* ${fields[3]}$" ${MYSPELL_OOOBASE}/dictionary.lst \
248 2>&1 > /dev/null && continue
249 # If no other entries match, remove relevant symlinks
250 for suffix in $(get_myspell_suffixes ${fields[0]}); do
251 filen="${fields[3]}${suffix}"
252 ewarn "Removing entry ${MYSPELL_OOOBASE}/${filen}"
253 [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
254 rm -f ${MYSPELL_OOOBASE}/${filen}
255 done
256 done < ${MYSPELL_DICTBASE}/${dictlst}
257 }

  ViewVC Help
Powered by ViewVC 1.1.20