import datetime
import errno
+import glob
import hashlib
+import io
import logging
import os
-import io
import pathlib
import re
import time
-from typing import Optional
-import glob
-from os.path import isfile, join, exists
-from typing import List
+from os.path import exists, isfile, join
+from typing import List, Optional, TextIO
from uuid import uuid4
-
logger = logging.getLogger(__name__)
def set_file_raw_atime(filename: str, atime: float):
mtime = get_file_raw_mtime(filename)
+ assert mtime is not None
os.utime(filename, (atime, mtime))
def set_file_raw_mtime(filename: str, mtime: float):
atime = get_file_raw_atime(filename)
+ assert atime is not None
os.utime(filename, (atime, mtime))
return describe_file_timestamp(filename, lambda x: x.st_mtime, brief=brief)
-def touch_file(filename: str, *, mode: Optional[int] = 0o666) -> bool:
- return pathlib.Path(filename, mode=mode).touch()
+def touch_file(filename: str, *, mode: Optional[int] = 0o666):
+ pathlib.Path(filename, mode=mode).touch()
def expand_globs(in_filename: str):
self.filename = filename
uuid = uuid4()
self.tempfile = f'{filename}-{uuid}.tmp'
- self.handle = None
+ self.handle: Optional[TextIO] = None
- def __enter__(self) -> io.TextIOWrapper:
+ def __enter__(self) -> TextIO:
assert not does_path_exist(self.tempfile)
self.handle = open(self.tempfile, mode="w")
return self.handle
- def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
+ def __exit__(self, exc_type, exc_val, exc_tb) -> Optional[bool]:
if self.handle is not None:
self.handle.close()
cmd = f'/bin/mv -f {self.tempfile} {self.filename}'