summaryrefslogtreecommitdiff
path: root/raphodo/utilities.py
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-10-02 06:51:13 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-10-02 06:51:13 +0200
commitc5fc6c6030d7d9d1b2af3d5165bebed3decd741b (patch)
treedfacccc9ae0747e53e53e5388b2ecd0623e040c3 /raphodo/utilities.py
parent77dd64c0757c0191b276e65c24ee9874959790c8 (diff)
New upstream version 0.9.4upstream/0.9.4
Diffstat (limited to 'raphodo/utilities.py')
-rw-r--r--raphodo/utilities.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/raphodo/utilities.py b/raphodo/utilities.py
index c98f46c..a70fb56 100644
--- a/raphodo/utilities.py
+++ b/raphodo/utilities.py
@@ -41,7 +41,6 @@ import ctypes
import signal
import pkg_resources
-
import arrow
import psutil
@@ -166,7 +165,9 @@ def stdchannel_redirected(stdchannel, dest_filename):
def show_errors():
yield
-suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
+# Translators: these values are file size suffixes like B representing bytes, KB representing
+# kilobytes, etc.
+suffixes = [_('B'), _('KB'), _('MB'), _('GB'), _('TB'), _('PB'), _('EB'), _('ZB'), _('YB')]
def format_size_for_user(size_in_bytes: int,
zero_string: str='',
@@ -179,6 +180,8 @@ def format_size_for_user(size_in_bytes: int,
:param size: size in bytes
:param zero_string: string to use if size == 0
+ >>> locale.setlocale(locale.LC_ALL, ('en_US', 'utf-8'))
+ 'en_US.UTF-8'
>>> format_size_for_user(0)
''
>>> format_size_for_user(1)
@@ -441,6 +444,7 @@ def first_and_last(iterable):
for end in iterable: pass
return start, end
+
def runs(iterable):
r"""
identify adjacent elements in pre-sorted data
@@ -645,6 +649,7 @@ def remove_last_char_from_list_str(items: List[str]) -> List[str]:
items = items[:-1]
return items
+
def platform_c_maxint() -> int:
"""
See http://stackoverflow.com/questions/13795758/what-is-sys-maxint-in-python-3
@@ -653,6 +658,7 @@ def platform_c_maxint() -> int:
"""
return 2 ** (struct.Struct('i').size * 8 - 1) - 1
+
def commonprefix(*paths) -> str:
"""
Python 3.4 compatible.
@@ -662,6 +668,7 @@ def commonprefix(*paths) -> str:
return os.path.dirname(os.path.commonprefix(paths))
+
def _recursive_identify_depth(*paths, depth) -> int:
basenames = [os.path.basename(path) for path in paths]
if len(basenames) != len(set(basenames)):
@@ -673,12 +680,14 @@ def _recursive_identify_depth(*paths, depth) -> int:
depth = max(depth, _recursive_identify_depth(*chopped, depth=depth + 1))
return depth
+
def _collect_duplicates(basenames, paths):
duplicates = defaultdict(list)
for basename, path in zip(basenames, paths):
duplicates[basename].append(path)
return {basename: paths for basename, paths in duplicates.items() if len(paths) > 1}
+
def make_path_end_snippets_unique(*paths) -> List[str]:
r"""
Make list of path ends unique given possible common path endings.
@@ -747,6 +756,7 @@ def make_path_end_snippets_unique(*paths) -> List[str]:
have_logged_os_release = False
+
def log_os_release() -> None:
"""
Log the entired contents of /etc/os-release, but only if
@@ -804,3 +814,22 @@ def remove_topmost_directory_from_path(path: str) -> str:
if os.sep not in path:
return path
return path[path[1:].find(os.sep) + 1:]
+
+
+def arrow_locale() -> str:
+ """
+ Test if locale is suitable for use with Arrow.
+ :return: Return user locale if it works with Arrow, else Arrow default ('en_us')
+ """
+
+ default = 'en_us'
+ try:
+ lang = locale.getdefaultlocale()[0]
+ except Exception:
+ return default
+
+ try:
+ arrow.locales.get_locale(lang)
+ return lang
+ except (ValueError, AttributeError):
+ return default