Skip to content
This repository was archived by the owner on Aug 18, 2018. It is now read-only.

Commit 335292f

Browse files
committed
Fixed bug outputting to Kobo. New options.
1 parent 7e9df1c commit 335292f

24 files changed

Lines changed: 1037 additions & 652 deletions

README.md

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
**Penelope** is a multi-tool for creating, editing and converting dictionaries, especially for eReader devices.
44

5-
* Version: 3.0.1
6-
* Date: 2015-11-22
5+
* Version: 3.1.0
6+
* Date: 2015-11-29
77
* Developer: [Alberto Pettarin](http://www.albertopettarin.it/)
88
* License: the MIT License (MIT)
99
* Contact: [click here](http://www.albertopettarin.it/contact.html)
@@ -78,7 +78,7 @@ You might need to install `dictzip` (StarDict output) and `kindlegen` (MOBI out
7878
$ python -m penelope
7979
```
8080

81-
This procedure will not any dependencies, see below.
81+
This procedure will not install any dependencies: you will need to do that manually, see below.
8282

8383

8484
### Dependencies
@@ -97,9 +97,9 @@ This procedure will not any dependencies, see below.
9797
$ [sudo] pip install marisa-trie
9898
```
9999

100-
or [`MARISA`](https://code.google.com/p/marisa-trie/) executables available in your `$PATH` or specified with `--marisa-bin-path`
100+
or [MARISA](https://code.google.com/p/marisa-trie/) executables available in your `$PATH` or specified with `--marisa-bin-path`
101101

102-
* to write MOBI Kindle dictionaries: the [`kindlegen`](https://www.amazon.com/gp/feature.html?docId=1000765211) executable, available in your `$PATH` or specified with `--kindlegen-path`
102+
* to write MOBI Kindle dictionaries: the [kindlegen](https://www.amazon.com/gp/feature.html?docId=1000765211) executable, available in your `$PATH` or specified with `--kindlegen-path`
103103

104104
* to read/write XML dictionaries: the Python module `lxml`:
105105

@@ -154,6 +154,8 @@ optional arguments:
154154
--title TITLE title string
155155
--website WEBSITE website string
156156
--year YEAR year string
157+
--apply-css APPLY_CSS
158+
apply the given CSS file (epub and mobi output only)
157159
--bookeen-collation-function BOOKEEN_COLLATION_FUNCTION
158160
use the specified collation function
159161
--bookeen-install-file
@@ -165,29 +167,36 @@ optional arguments:
165167
--csv-ls CSV_LS CSV line separator (default: '\n')
166168
--dictzip-path DICTZIP_PATH
167169
path to dictzip executable
168-
--epub-escape-strings
169-
escape HTML strings (default: False)
170-
--epub-group-prefix-length EPUB_GROUP_PREFIX_LENGTH
171-
group headwords by prefix of given length (default: 3)
172-
--epub-merge-group-size EPUB_MERGE_GROUP_SIZE
173-
merge headword groups with less than this number of
174-
headwords (default: 128)
175-
--epub-output-definitions
176-
output definitions in addition to the headwords
177-
(default: False)
170+
--epub-no-compress do not create the compressed container (epub output
171+
only, default: False)
172+
--escape-strings escape HTML strings (default: False)
178173
--flatten-synonyms flatten synonyms, creating a new entry with
179174
headword=synonym and using the definition of the
180175
original headword (default: False)
176+
--group-by-prefix-function GROUP_BY_PREFIX_FUNCTION
177+
compute the prefix of headwords using the given prefix
178+
function file
179+
--group-by-prefix-length GROUP_BY_PREFIX_LENGTH
180+
group headwords by prefix of given length (default: 2)
181+
--group-by-prefix-merge-across-first
182+
merge headword groups even when the first character
183+
changes (default: False)
184+
--group-by-prefix-merge-min-size GROUP_BY_PREFIX_MERGE_MIN_SIZE
185+
merge headword groups until the given minimum number
186+
of headwords is reached (default: 0, meaning no merge
187+
will take place)
188+
--ignore-case ignore headword case, all headwords will be lowercased
189+
(default: False)
190+
--ignore-synonyms ignore synonyms, not reading/writing them if present
191+
(default: False)
192+
--include-index-page include an index page (epub and mobi output only,
193+
default: False)
181194
--input-file-encoding INPUT_FILE_ENCODING
182195
use the specified encoding for reading the raw
183196
contents of input file(s) (default: 'utf-8')
184197
--input-parser INPUT_PARSER
185198
use the specified parser function after reading the
186199
raw contents of input file(s)
187-
--ignore-case ignore headword case, all headwords will be lowercased
188-
(default: False)
189-
--ignore-synonyms ignore synonyms, not reading/writing them if present
190-
(default: False)
191200
--kindlegen-path KINDLEGEN_PATH
192201
path to kindlegen executable
193202
--marisa-bin-path MARISA_BIN_PATH
@@ -201,6 +210,8 @@ optional arguments:
201210
| ')
202211
--mobi-no-kindlegen do not run kindlegen, keep .opf and .html files
203212
(default: False)
213+
--no-definitions do not output definitions for EPUB and MOBI formats
214+
(default: False)
204215
--sd-ignore-sametypesequence
205216
ignore the value of sametypesequence in StarDict .ifo
206217
files (default: False)
@@ -253,7 +264,6 @@ examples:
253264

254265
$ penelope -i dict.xml -j xml -f en -t it -p mobi -o output.epub --epub-output-definitions
255266
As above, but also output definitions
256-
257267
```
258268
259269
You can find ISO 639-1 language codes [here](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
@@ -338,6 +348,8 @@ were released under the GNU GPL 3 License.
338348
* Reading EPUB (3) dictionaries is not supported; the writing part needs polishing/refactoring
339349
* Reading PRC/MOBI (Kindle) dictionaries is not supported
340350
* There are some limitations on StarDict files that can be read (see comments in `format_stardict.py`)
351+
* Documentation is not complete
352+
* Unit tests are missing
341353
342354
343355
## Acknowledgments

README.rst

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Penelope
44
**Penelope** is a multi-tool for creating, editing and converting
55
dictionaries, especially for eReader devices.
66

7-
- Version: 3.0.1
8-
- Date: 2015-11-22
7+
- Version: 3.1.0
8+
- Date: 2015-11-29
99
- Developer: `Alberto Pettarin <http://www.albertopettarin.it/>`__
1010
- License: the MIT License (MIT)
1111
- Contact: `click here <http://www.albertopettarin.it/contact.html>`__
@@ -96,7 +96,8 @@ From source code
9696
9797
$ python -m penelope
9898
99-
This procedure will not any dependencies, see below.
99+
This procedure will not install any dependencies: you will need to do
100+
that manually, see below.
100101

101102
Dependencies
102103
~~~~~~~~~~~~
@@ -116,11 +117,11 @@ Dependencies
116117
117118
$ [sudo] pip install marisa-trie
118119
119-
or ```MARISA`` <https://code.google.com/p/marisa-trie/>`__ executables
120+
or `MARISA <https://code.google.com/p/marisa-trie/>`__ executables
120121
available in your ``$PATH`` or specified with ``--marisa-bin-path``
121122

122123
- to write MOBI Kindle dictionaries: the
123-
```kindlegen`` <https://www.amazon.com/gp/feature.html?docId=1000765211>`__
124+
`kindlegen <https://www.amazon.com/gp/feature.html?docId=1000765211>`__
124125
executable, available in your ``$PATH`` or specified with
125126
``--kindlegen-path``
126127

@@ -178,6 +179,8 @@ Usage
178179
--title TITLE title string
179180
--website WEBSITE website string
180181
--year YEAR year string
182+
--apply-css APPLY_CSS
183+
apply the given CSS file (epub and mobi output only)
181184
--bookeen-collation-function BOOKEEN_COLLATION_FUNCTION
182185
use the specified collation function
183186
--bookeen-install-file
@@ -189,29 +192,36 @@ Usage
189192
--csv-ls CSV_LS CSV line separator (default: '\n')
190193
--dictzip-path DICTZIP_PATH
191194
path to dictzip executable
192-
--epub-escape-strings
193-
escape HTML strings (default: False)
194-
--epub-group-prefix-length EPUB_GROUP_PREFIX_LENGTH
195-
group headwords by prefix of given length (default: 3)
196-
--epub-merge-group-size EPUB_MERGE_GROUP_SIZE
197-
merge headword groups with less than this number of
198-
headwords (default: 128)
199-
--epub-output-definitions
200-
output definitions in addition to the headwords
201-
(default: False)
195+
--epub-no-compress do not create the compressed container (epub output
196+
only, default: False)
197+
--escape-strings escape HTML strings (default: False)
202198
--flatten-synonyms flatten synonyms, creating a new entry with
203199
headword=synonym and using the definition of the
204200
original headword (default: False)
201+
--group-by-prefix-function GROUP_BY_PREFIX_FUNCTION
202+
compute the prefix of headwords using the given prefix
203+
function file
204+
--group-by-prefix-length GROUP_BY_PREFIX_LENGTH
205+
group headwords by prefix of given length (default: 2)
206+
--group-by-prefix-merge-across-first
207+
merge headword groups even when the first character
208+
changes (default: False)
209+
--group-by-prefix-merge-min-size GROUP_BY_PREFIX_MERGE_MIN_SIZE
210+
merge headword groups until the given minimum number
211+
of headwords is reached (default: 0, meaning no merge
212+
will take place)
213+
--ignore-case ignore headword case, all headwords will be lowercased
214+
(default: False)
215+
--ignore-synonyms ignore synonyms, not reading/writing them if present
216+
(default: False)
217+
--include-index-page include an index page (epub and mobi output only,
218+
default: False)
205219
--input-file-encoding INPUT_FILE_ENCODING
206220
use the specified encoding for reading the raw
207221
contents of input file(s) (default: 'utf-8')
208222
--input-parser INPUT_PARSER
209223
use the specified parser function after reading the
210224
raw contents of input file(s)
211-
--ignore-case ignore headword case, all headwords will be lowercased
212-
(default: False)
213-
--ignore-synonyms ignore synonyms, not reading/writing them if present
214-
(default: False)
215225
--kindlegen-path KINDLEGEN_PATH
216226
path to kindlegen executable
217227
--marisa-bin-path MARISA_BIN_PATH
@@ -225,6 +235,8 @@ Usage
225235
| ')
226236
--mobi-no-kindlegen do not run kindlegen, keep .opf and .html files
227237
(default: False)
238+
--no-definitions do not output definitions for EPUB and MOBI formats
239+
(default: False)
228240
--sd-ignore-sametypesequence
229241
ignore the value of sametypesequence in StarDict .ifo
230242
files (default: False)
@@ -277,7 +289,6 @@ Usage
277289

278290
$ penelope -i dict.xml -j xml -f en -t it -p mobi -o output.epub --epub-output-definitions
279291
As above, but also output definitions
280-
281292

282293
You can find ISO 639-1 language codes
283294
`here <http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes>`__.
@@ -384,6 +395,8 @@ Limitations and Missing Features
384395
- Reading PRC/MOBI (Kindle) dictionaries is not supported
385396
- There are some limitations on StarDict files that can be read (see
386397
comments in ``format_stardict.py``)
398+
- Documentation is not complete
399+
- Unit tests are missing
387400

388401
Acknowledgments
389402
---------------

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.1
1+
3.1.0

bin/penelope

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ from penelope import main as package_main
1414
__author__ = "Alberto Pettarin"
1515
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)"
1616
__license__ = "MIT"
17-
__version__ = "3.0.1"
17+
__version__ = "3.1.0"
1818
__email__ = "alberto@albertopettarin.it"
1919
__status__ = "Production"
2020

penelope/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
__author__ = "Alberto Pettarin"
3333
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)"
3434
__license__ = "MIT"
35-
__version__ = "3.0.1"
35+
__version__ = "3.1.0"
3636
__email__ = "alberto@albertopettarin.it"
3737
__status__ = "Production"
3838

penelope/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
__author__ = "Alberto Pettarin"
3232
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)"
3333
__license__ = "MIT"
34-
__version__ = "3.0.1"
34+
__version__ = "3.1.0"
3535
__email__ = "alberto@albertopettarin.it"
3636
__status__ = "Production"
3737

penelope/collation_default.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5-
This is the default collation function (IcuNoCase) for bookeen output format.
5+
This is the default collation function (IcuNoCase).
66
"""
77

88
__author__ = "Alberto Pettarin"
99
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)"
1010
__license__ = "MIT"
11-
__version__ = "3.0.1"
11+
__version__ = "3.1.0"
1212
__email__ = "alberto@albertopettarin.it"
1313
__status__ = "Production"
1414

1515
def collate_function(string1, string2):
1616
"""
17-
Implement IcuNoCase collation.
17+
Implement default IcuNoCase collation,
18+
by simply lowercasing the UTF-8 encoded versions
19+
of the two strings.
1820
1921
:param string1: first string
2022
:type string1: unicode

penelope/collation_german.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5-
This is a sample collation function (IcuNoCase) for German.
5+
This is a collation function (IcuNoCase) for German.
66
"""
77

88
__author__ = "Alberto Pettarin"
99
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)"
1010
__license__ = "MIT"
11-
__version__ = "3.0.1"
11+
__version__ = "3.1.0"
1212
__email__ = "alberto@albertopettarin.it"
1313
__status__ = "Production"
1414

15+
REPLACEMENTS = [
16+
[u"ä", u"a"],
17+
[u"ö", u"o"],
18+
[u"ü", u"u"],
19+
[u"ß", u"ss"]
20+
]
21+
1522
def collate_function(string1, string2):
1623
"""
1724
Implement IcuNoCase collation for German.
25+
(I do not remember where the procedure comes from.)
1826
1927
:param string1: first string
2028
:type string1: unicode
@@ -26,10 +34,9 @@ def collate_function(string1, string2):
2634
b2 = string2.lower()
2735
c1 = b1
2836
c2 = b2
29-
for f in [[u"ä", u"a"], [u"ö", u"o"], [u"ü", u"u"], [u"ß", u"ss"]]:
30-
b1 = b1.replace(f[0], f[1])
31-
b2 = b2.replace(f[0], f[1])
32-
37+
for repl in REPLACEMENTS:
38+
b1 = b1.replace(repl[0], repl[1])
39+
b2 = b2.replace(repl[0], repl[1])
3340
if b1.encode("utf-16") == b2.encode("utf-16"):
3441
if c1.encode("utf-16") == c2.encode("utf-16"):
3542
return 0

0 commit comments

Comments
 (0)