utils.py 1020 B

12345678910111213141516171819202122232425262728
  1. import os
  2. from datetime import datetime, timezone
  3. from typing import List, Optional, Text, Union
  4. def file_exists(path: Union[bytes, str, "os.PathLike[Text]"]) -> bool:
  5. """Validates file path as existing local file"""
  6. return os.path.isfile(path)
  7. def get_file_modtime(path: Union[bytes, str, "os.PathLike[Text]"]) -> Text:
  8. """Returns ISO formatted file modification time in local system timezone"""
  9. return (
  10. datetime.fromtimestamp(os.stat(path).st_mtime, timezone.utc)
  11. .astimezone()
  12. .isoformat()
  13. )
  14. def get_tables_argument_list(table_list: Optional[List[Text]]) -> Optional[List[Text]]:
  15. """Converts a list of OpenType table string into a Python list or
  16. return None if the table_list was not defined (i.e., it was not included
  17. in an option on the command line). Tables that are composed of three
  18. characters must be right padded with a space."""
  19. if table_list is None:
  20. return None
  21. else:
  22. return [table.ljust(4) for table in table_list]