diff options
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r-- | sphinx/util/osutil.py | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 0645ee46f..a56da44fe 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -17,7 +17,6 @@ import time import errno import locale import shutil -import gettext from os import path import contextlib @@ -36,6 +35,7 @@ EINVAL = getattr(errno, 'EINVAL', 0) # hangover from more *nix-oriented origins. SEP = "/" + def os_path(canonicalpath): return canonicalpath.replace(SEP, path.sep) @@ -59,7 +59,7 @@ def relative_uri(base, to): if len(b2) == 1 and t2 == ['']: # Special case: relative_uri('f/index.html','f/') should # return './', not '' - return '.' + SEP + return '.' + SEP return ('..' + SEP) * (len(b2)-1) + SEP.join(t2) @@ -147,18 +147,33 @@ def copyfile(source, dest): no_fn_re = re.compile(r'[^a-zA-Z0-9_-]') + def make_filename(string): return no_fn_re.sub('', string) or 'sphinx' -if PY2: + +def ustrftime(format, *args): # strftime for unicode strings - def ustrftime(format, *args): + if not args: + # If time is not specified, try to use $SOURCE_DATE_EPOCH variable + # See https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal + source_date_epoch = os.getenv('SOURCE_DATE_EPOCH') + if source_date_epoch is not None: + time_struct = time.gmtime(float(source_date_epoch)) + args = [time_struct] + if PY2: # if a locale is set, the time strings are encoded in the encoding # given by LC_TIME; if that is available, use it enc = locale.getlocale(locale.LC_TIME)[1] or 'utf-8' return time.strftime(text_type(format).encode(enc), *args).decode(enc) -else: - ustrftime = time.strftime + else: # Py3 + # On Windows, time.strftime() and Unicode characters will raise UnicodeEncodeError. + # http://bugs.python.org/issue8304 + try: + return time.strftime(format, *args) + except UnicodeEncodeError: + r = time.strftime(format.encode('unicode-escape').decode(), *args) + return r.encode().decode('unicode-escape') def safe_relpath(path, start=None): @@ -167,25 +182,6 @@ def safe_relpath(path, start=None): except ValueError: return path -def find_catalog(docname, compaction): - if compaction: - ret = docname.split(SEP, 1)[0] - else: - ret = docname - - return ret - - -def find_catalog_files(docname, srcdir, locale_dirs, lang, compaction): - if not(lang and locale_dirs): - return [] - - domain = find_catalog(docname, compaction) - files = [gettext.find(domain, path.join(srcdir, dir_), [lang]) - for dir_ in locale_dirs] - files = [path.relpath(f, srcdir) for f in files if f] - return files - fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() |