Mercurial > hgrepos > DevTools > mercurial-extensions
view tests/lib-stat.py @ 276:5b4acabe2c9e
Use the canonical "hg commit" instead of "hg ci"
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Fri, 04 Jan 2019 22:39:38 +0100 |
| parents | 6abd41f7d879 |
| children | 7ec353866f70 |
line wrap: on
line source
from __future__ import absolute_import, print_function import sys import os import datetime class FloatTimesInStat(object): """Context manager to ensure that stat returns float values. For 3.7 <= Mercurial < 4.6: Mercurial calls :func:`os.stat_float_times` for `stat` and friends to return :class:`int` values. Temporarily fix this. """ __slots__ = ("_do_reset",) def __init__(self): self._do_reset = False def __enter__(self): if not os.stat_float_times(): os.stat_float_times(True) self._do_reset = True return self def __exit__(self, *args): if self._do_reset: os.stat_float_times(False) def to_isoformat(t): """Return the POSIX timestamp `t` formatted in full ISO format. `t` is expected to be in the UTC timezone. """ dt = datetime.datetime.utcfromtimestamp(t) if dt.utcoffset() is None: return dt.isoformat() + "Z" else: return dt.isoformat() def main(): with FloatTimesInStat(): for f in sys.argv[1:]: st = os.lstat(f) print(to_isoformat(st.st_mtime)) if __name__ == "__main__": main()
