Skip to content

Commit

Permalink
fix: remove accents from file names
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed Nov 20, 2024
1 parent 5699865 commit 7b33d32
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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

0 comments on commit 7b33d32

Please sign in to comment.