You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

base_file_system.py 1.9 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Base file system."""
  16. from abc import ABC, abstractmethod
  17. from collections import namedtuple
  18. StatInfo = namedtuple("Info", ["size", "mtime"])
  19. class BaseFileSystem(ABC):
  20. """Base class for file systems."""
  21. @abstractmethod
  22. def list_dir(self, path):
  23. """
  24. Abstract method for listing directories by path.
  25. Args:
  26. path (str): Directory path or file path.
  27. """
  28. @abstractmethod
  29. def is_dir(self, path):
  30. """
  31. Abstract method for determining if it is a directory.
  32. Args:
  33. path (str): Directory path or file path.
  34. """
  35. @abstractmethod
  36. def exists(self, path):
  37. """
  38. Abstract method for determining if it exists.
  39. Args:
  40. path (str): Directory path or file path.
  41. """
  42. @abstractmethod
  43. def file_stat(self, file_path):
  44. """
  45. Abstract method for getting file stat information.
  46. Args:
  47. file_path (str): File path.
  48. """
  49. @abstractmethod
  50. def join(self, path, *paths):
  51. """
  52. Abstract method for combining paths.
  53. Args:
  54. path (str): Directory path.
  55. *paths (str): Path or paths.
  56. """