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

Commit

Permalink
Fixed problem with escape sequences in CSV files
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Pettarin committed Feb 16, 2016
1 parent 6589d13 commit d4d07dc
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 58 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2012-2015 Alberto Pettarin ([email protected])
Copyright (c) 2012-2016 Alberto Pettarin ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 3 additions & 4 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.1
* Date: 2015-12-02
* Version: 3.1.2
* Date: 2016-02-16
* 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 @@ -31,7 +31,6 @@ With the current version you can:

* 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.
* 2014-06-30 I moved Penelope to GitHub, and released it under the MIT License, with the version code v2.0.0.


## Installation
Expand Down Expand Up @@ -290,7 +289,7 @@ otherwise the correct dictionary might not be loaded.
### Kobo Devices
At the time of this writing (2015-12-02), Kobo devices will load dictionaries
At the time of this writing (2016-02-16), Kobo devices will load dictionaries
only if the files have a file name of an official Kobo dictionaries, which are:
* `dicthtml.zip` (EN)
Expand Down
16 changes: 11 additions & 5 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.1
- Date: 2015-12-02
- Version: 3.1.2
- Date: 2016-02-16
- 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 @@ -39,8 +39,6 @@ Important updates
**3.0.1**
- 2015-11-22 **The command line interface has changed with v3.0.0**, as
I performed a huge code refactoring.
- 2014-06-30 I moved Penelope to GitHub, and released it under the MIT
License, with the version code v2.0.0.

Installation
------------
Expand Down Expand Up @@ -319,7 +317,7 @@ correct dictionary might not be loaded.
Kobo Devices
~~~~~~~~~~~~

At the time of this writing (2015-12-02), Kobo devices will load
At the time of this writing (2016-02-16), Kobo devices will load
dictionaries only if the files have a file name of an official Kobo
dictionaries, which are:

Expand Down Expand Up @@ -398,6 +396,14 @@ Limitations and Missing Features
- Documentation is not complete
- Unit tests are missing

Sponsors
--------

- **December 2015**: `IngleseXpress.it <http://IngleseXpress.it>`__,
"Grazie per averci aiutato a pubblicare per Kindle il `Dizionario
Inglese-Italiano della Pronuncia Scritta
Semplificata <http://www.amazon.it/Dizionario-Inglese-Italiano-Pronuncia-Scritta-Semplificata-ebook/dp/B019BE5WVW>`__!"

Acknowledgments
---------------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.1
3.1.2
4 changes: 2 additions & 2 deletions bin/penelope
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ from __future__ import absolute_import
from penelope import main as package_main

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
from penelope.utilities import print_info

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
from penelope.utilities import print_info

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/collation_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"""

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/collation_german.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"""

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from penelope.utilities import print_error

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
from penelope.utilities import print_error

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/dictionary_ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from penelope.utilities import delete_directory

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/format_bookeen.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from penelope.utilities import delete_directory

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

Expand Down
32 changes: 26 additions & 6 deletions penelope/format_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,42 @@
from penelope.utilities import print_error

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

ASCII_ESCAPES = [
("\\a", "\a"),
("\\b", "\b"),
("\\t", "\t"),
("\\n", "\n"),
("\\v", "\v"),
("\\f", "\f"),
("\\r", "\r")
]

def escape(string):
ret = string
for s, r in ASCII_ESCAPES:
ret = ret.replace(s, r)
return ret

def read(dictionary, args, input_file_paths):
csv_fs = escape(args.csv_fs)
csv_ls = escape(args.csv_ls)
for input_file_path in input_file_paths:
print_debug("Reading from file '%s'..." % (input_file_path), args.debug)
input_file_object = open(input_file_path, "rb")
data_bytes = input_file_object.read() # bytes
data_unicode = data_bytes.decode(args.input_file_encoding) # unicode
input_file_object.close()
lines = data_unicode.split(args.csv_ls)
lines = data_unicode.split(csv_ls)
if args.csv_ignore_first_line:
lines = lines[1:]
for line in lines:
array = line.split(args.csv_fs)
array = line.split(csv_fs)
if len(array) >= 2:
headword = array[0]
definition = line[len(headword) + 1:]
Expand All @@ -40,16 +58,18 @@ def read(dictionary, args, input_file_paths):
return dictionary

def write(dictionary, args, output_file_path):
csv_fs = escape(args.csv_fs)
csv_ls = escape(args.csv_ls)
try:
print_debug("Writing to file '%s'..." % (output_file_path), args.debug)
output_file_obj = open(output_file_path, "wb")
for index in dictionary.entries_index_sorted:
entry = dictionary.entries[index]
string = u"%s%s%s%s" % (
entry.headword,
args.csv_fs,
csv_fs,
entry.definition,
args.csv_ls
csv_ls
)
output_file_obj.write(string.encode("utf-8"))
output_file_obj.close()
Expand Down
4 changes: 2 additions & 2 deletions penelope/format_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from penelope.utilities import print_info

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/format_kobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
from penelope.utilities import rename_file

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/format_mobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from penelope.utilities import delete_directory

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/format_stardict.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from penelope.utilities import print_info

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/format_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from penelope.utilities import print_error

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/input_parser_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"""

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/input_parser_webster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"""

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/prefix_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"""

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/prefix_kobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"""

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

Expand Down
4 changes: 2 additions & 2 deletions penelope/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import uuid

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

Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from setuptools import setup, Extension

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

setup(
name="penelope",
packages=["penelope"],
package_data={"penelope": ["res/*"]},
version="3.1.1.1",
version="3.1.2.0",
description="Penelope is a multi-tool for creating, editing and converting dictionaries, especially for eReader devices",
author="Alberto Pettarin",
author_email="[email protected]",
Expand Down

0 comments on commit d4d07dc

Please sign in to comment.