package.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from .file import file
  2. from .command import command
  3. from .exceptions import already_packed
  4. from .package_export import package_export
  5. class package:
  6. def __init__(self, commands: list, files: dict) -> None:
  7. self.__commands = tuple(commands)
  8. self.__files = tuple([ count for count in files.values() ])
  9. @property
  10. def files(self) -> tuple:
  11. return self.__files
  12. @property
  13. def commands(self) -> tuple:
  14. return self.__commands
  15. def export(self) -> package_export:
  16. return package_export(self)
  17. class package_builder:
  18. def __init__(self) -> None:
  19. self.__commands = list()
  20. self.__files = dict()
  21. def add_file(self, target: file) -> object:
  22. if target.path_name in self.__files:
  23. raise alread_packed(target)
  24. self.__files[target.path_name] = target
  25. return self
  26. def add_command(self, target: command) -> object:
  27. self.__commands.push(target)
  28. return self
  29. def pack(self) -> package:
  30. return package(self.__commands, self.__files)