summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 33d1f5bec..d0bfee02a 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -1194,7 +1194,11 @@ def simplify_name(full_path_name, check_existing=False):
if match:
new_name = name.replace(match.group(), '')
full_new_name = os.sep.join([path, new_name + ext])
- if not check_existing or not os.path.isfile(full_new_name):
+ try:
+ is_file = os.path.isfile(full_new_name)
+ except UnicodeEncodeError:
+ is_file = os.path.isfile(full_new_name.encode('utf-8'))
+ if not check_existing or not is_file:
# do not take the place of another file
name = new_name[:]
break
@@ -1211,23 +1215,17 @@ def rename_and_simplify_media_name(full_path_name, rename=True):
:return: new full path name (or old if not changed), modified
"""
try:
- is_str = False
exists = os.path.exists(full_path_name)
is_file = os.path.isfile(full_path_name)
except UnicodeEncodeError:
- is_str = True
- full_path_name = full_path_name.encode('utf-8')
- exists = os.path.exists(full_path_name)
- is_file = os.path.isfile(full_path_name)
+ full_path_name_unicode = full_path_name.encode('utf-8')
+ exists = os.path.exists(full_path_name_unicode)
+ is_file = os.path.isfile(full_path_name_unicode)
if not exists or not is_file:
return full_path_name, False
path, current_name, name = simplify_name(full_path_name,
check_existing=True)
- if is_str:
- full_path_name = full_path_name.decode('utf-8')
- name = name.decode('utf-8')
- path = path.decode('utf-8')
if current_name == name:
return full_path_name, False