Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove accents from file names #406

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ v3.2.1
------

*Release date: In development*

- Allow negative indexes for list elements in context searches. Example: [CONTEXT:element.-1]
- Add support for JSON strings to the `DICT` and `LIST`` replacement. Example: [DICT:{"key": true}], [LIST:[null]]
- Add `REPLACE` replacement, to replace a substring with another. Example: [REPLACE:[CONTEXT:some_url]::https::http]
- Add `TITLE` replacement, to apply Python's title() function. Example: [TITLE:the title]
- Add `ROUND` replacement, float number to a string with the indicated number of decimals. Example: [ROUND:3.3333::2]
- Remove accents from generated file names to avoid errors in some filesystems

v3.2.0
------
Expand Down
1 change: 1 addition & 0 deletions toolium/test/utils/test_path_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
('successful login -- @1.1 john.doe', 'successful_login_1_1_john_doe'),
('successful login -- @1.2 Mark options: {Length=10 Mark=mark File=file_name.jpg}',
'successful_login_1_2_Mark_options___Length_10_Mark_mark_File_file_name_jpg'),
('successful login -- @1.3 acción', 'successful_login_1_3_accion'),
)


Expand Down
6 changes: 5 additions & 1 deletion toolium/utils/path_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
limitations under the License.
"""

from os import makedirs
import errno
import re
import unicodedata
from os import makedirs

FILENAME_MAX_LENGTH = 100

Expand All @@ -34,6 +35,9 @@ def get_valid_filename(s, max_length=FILENAME_MAX_LENGTH):
"""
s = str(s).strip().replace(' -- @', '_')
s = re.sub(r'(?u)[^-\w]', '_', s).strip('_')
# Remove accents to avoid errors in some filesystems
nfkd_form = unicodedata.normalize('NFKD', s)
s = ''.join([c for c in nfkd_form if not unicodedata.combining(c)])
return s[:max_length]


Expand Down
Loading