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

Commit

Permalink
Fixed bug in collation_default. PEP 8. v3.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Pettarin committed Sep 23, 2016
1 parent 7682dc1 commit fce6dcf
Show file tree
Hide file tree
Showing 25 changed files with 266 additions and 246 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
*.pyd
*.pyo
*.swp
penelope.egg-info
penelope/build
penelope/__pycache__
bak
build
dist
docs/build
penelope.egg-info
penelope/__pycache__
penelope/build
tmp
venvs

# service scripts
zzz_*.py
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

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

* Version: 3.1.2
* Date: 2016-02-16
* Version: 3.1.3
* Date: 2016-09-23
* Developer: [Alberto Pettarin](http://www.albertopettarin.it/)
* License: the MIT License (MIT)
* Contact: [click here](http://www.albertopettarin.it/contact.html)
Expand Down Expand Up @@ -377,6 +377,3 @@ Many thanks to:
* _Stephan Lichtenhagen_ for suggesting forcing UTF-8 encoding on Python 3;
* _niconavarrete_ for pointing out the dependency from $CWD (issue #1), solved in v2.0.1;
* _elchamaco_ for providing a StarDict dictionary with a `.syn` file for testing.
24 changes: 15 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Penelope
**Penelope** is a multi-tool for creating, editing and converting
dictionaries, especially for eReader devices.

- Version: 3.1.2
- Date: 2016-02-16
- Version: 3.1.3
- Date: 2016-09-23
- Developer: `Alberto Pettarin <http://www.albertopettarin.it/>`__
- License: the MIT License (MIT)
- Contact: `click here <http://www.albertopettarin.it/contact.html>`__
Expand All @@ -31,14 +31,20 @@ With the current version you can:
lack of a search function of your eReader)
- output a MOBI (Kindle) dictionary

Important updates
~~~~~~~~~~~~~~~~~
Important Update
~~~~~~~~~~~~~~~~

- 2015-11-24 Penelope is now available on
`PyPI <https://pypi.python.org/pypi/penelope/>`__, bumped version to
**3.0.1**
- 2015-11-22 **The command line interface has changed with v3.0.0**, as
I performed a huge code refactoring.
- 2016-04-17 Sadly, I can no longer afford to spend time working on
Penelope, as my other FLOSS projects take 100% of my FLOSS time, and
I still need to pay rent and bills, spend time with family and
friends, etc., as anyone else. Therefore, I will not work on issues
or pull requests, **please do not expect they will be dealt with at
all**. I am actively **looking for other developers to take this
project over**. (This notice should be removed when the changeover
happens.) If you need to convert a dictionary and the current version
of Penelope does not work for you, you might want to have a look at
`**PyGlossary** <https://github.com/ilius/pyglossary>`__. My most
sincere apologies for the inconvenience.

Installation
------------
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.2
3.1.3
8 changes: 3 additions & 5 deletions bin/penelope
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ This is the main Penelope script, intended to be run from command line.

from __future__ import absolute_import

from penelope import main as package_main
from penelope.__main__ import main as package_main

__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "3.1.2"
__version__ = "3.1.3"
__email__ = "[email protected]"
__status__ = "Production"


def main():
package_main()


if __name__ == '__main__':
main()



27 changes: 1 addition & 26 deletions penelope/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,9 @@
This is the main Penelope script, intended to be run from command line.
"""

from __future__ import absolute_import
import argparse
import sys

from penelope.__main__ import main
from penelope.command_line import COMMAND_LINE_PARAMETERS
from penelope.command_line import DESCRIPTION
from penelope.command_line import EPILOG
from penelope.command_line import INPUT_FORMATS
from penelope.command_line import OUTPUT_FORMATS
from penelope.command_line import REQUIRED_PARAMETERS
from penelope.command_line import USAGE
from penelope.command_line import check_arguments
from penelope.command_line import set_default_values
from penelope.dictionary import read_dictionary
from penelope.dictionary import write_dictionary
from penelope.utilities import get_uuid
from penelope.utilities import load_input_parser
from penelope.utilities import print_debug
from penelope.utilities import print_error
from penelope.utilities import print_info

__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "3.1.2"
__version__ = "3.1.3"
__email__ = "[email protected]"
__status__ = "Production"



6 changes: 2 additions & 4 deletions penelope/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "3.1.2"
__version__ = "3.1.3"
__email__ = "[email protected]"
__status__ = "Production"


def main():
parser = argparse.ArgumentParser(
usage=USAGE,
Expand Down Expand Up @@ -144,6 +145,3 @@ def main():

if __name__ == "__main__":
main()



16 changes: 9 additions & 7 deletions penelope/collation_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
This is the default collation function (IcuNoCase).
"""

from __future__ import absolute_import

from penelope.utilities import utf_lower

__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "3.1.2"
__version__ = "3.1.3"
__email__ = "[email protected]"
__status__ = "Production"


def collate_function(string1, string2):
"""
Implement default IcuNoCase collation,
Expand All @@ -24,13 +29,10 @@ def collate_function(string1, string2):
:type string2: unicode
:rtype: int
"""
b1 = string1.encode("utf-8").lower()
b2 = string2.encode("utf-8").lower()
b1 = utf_lower(string1, encoding="utf-8", lower=True)
b2 = utf_lower(string2, encoding="utf-8", lower=True)
if b1 == b2:
return 0
if b1 < b2:
elif b1 < b2:
return -1
return 1



41 changes: 26 additions & 15 deletions penelope/collation_german.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
This is a collation function (IcuNoCase) for German.
"""

from __future__ import absolute_import

from penelope.utilities import PY2
from penelope.utilities import utf_lower

__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "3.1.2"
__version__ = "3.1.3"
__email__ = "[email protected]"
__status__ = "Production"


REPLACEMENTS = [
[u"ä", u"a"],
[u"ö", u"o"],
[u"ü", u"u"],
[u"ß", u"ss"]
]
if PY2:
REPLACEMENTS = [(r.encode("utf-8"), s.encode("utf-8")) for (r, s) in REPLACEMENTS]


def collate_function(string1, string2):
"""
Expand All @@ -32,20 +41,22 @@ def collate_function(string1, string2):
"""
b1 = string1.lower()
b2 = string2.lower()
c1 = b1
c2 = b2
for repl in REPLACEMENTS:
b1 = b1.replace(repl[0], repl[1])
b2 = b2.replace(repl[0], repl[1])
if b1.encode("utf-16") == b2.encode("utf-16"):
if c1.encode("utf-16") == c2.encode("utf-16"):
for (r, s) in REPLACEMENTS:
b1 = b1.replace(r, s)
b2 = b2.replace(r, s)
b1 = utf_lower(b1, encoding="utf-8", lower=True)
b2 = utf_lower(b2, encoding="utf-8", lower=True)
c1 = utf_lower(string1, encoding="utf-8", lower=True)
c2 = utf_lower(string2, encoding="utf-8", lower=True)
d1 = utf_lower(b1, encoding="utf-16", lower=False)
d2 = utf_lower(b2, encoding="utf-16", lower=False)
if d1 == d2:
e1 = utf_lower(c1, encoding="utf-16", lower=False)
e2 = utf_lower(c2, encoding="utf-16", lower=False)
if e1 == e2:
return 0
if c1.encode("utf-16") < c2.encode("utf-16"):
return -1
else:
if b1.encode("utf-16") < b2.encode("utf-16"):
if e1 < e2:
return -1
if d1 < d2:
return -1
return 1



23 changes: 11 additions & 12 deletions penelope/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "3.1.2"
__version__ = "3.1.3"
__email__ = "[email protected]"
__status__ = "Production"

Expand Down Expand Up @@ -370,14 +370,14 @@
]

EXAMPLES = [
#{
# "options": "-h",
# "description": "Print this message and exit"
#},
#{
# "options": "-v",
# "description": "Print the version and exit"
#},
# {
# "options": "-h",
# "description": "Print this message and exit"
# },
# {
# "options": "-v",
# "description": "Print the version and exit"
# },
{
"options": "-i dict.csv -j csv -f en -t it -p stardict -o output.zip",
"description": "Convert en->it dictionary dict.csv (in CSV format) into output.zip (in StarDict format)"
Expand Down Expand Up @@ -450,6 +450,7 @@
EPILOG += u" %s\n" % (example["description"])
EPILOG += u" \n"


def check_arguments(args):
"""
Check that we have all the required command line arguments,
Expand All @@ -468,6 +469,7 @@ def check_arguments(args):
print_error("Valid output formats: %s" % OUTPUT_FORMATS)
sys.exit(4)


def set_default_values(args):
def set_default_value(key, value):
if not args.__contains__(key):
Expand Down Expand Up @@ -519,6 +521,3 @@ def set_default_value(key, value):
set_default_value("title", u"Dictionary %s to %s" % (args.language_from, args.language_to))
set_default_value("website", u"https://goo.gl/EB5XSR")
set_default_value("year", str(datetime.datetime.now().year))



Loading

0 comments on commit fce6dcf

Please sign in to comment.