process_command_files.py 985 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. def is_cmdfile_arg(arg):
  2. # type: (str) -> bool
  3. return arg.startswith('@')
  4. def cmdfile_path(arg):
  5. # type: (str) -> str
  6. return arg[1:]
  7. def read_from_command_file(arg):
  8. # type: (str) -> list[str]
  9. with open(arg) as afile:
  10. return afile.read().splitlines()
  11. def skip_markers(args):
  12. # type: (list[str]) -> list[str]
  13. res = []
  14. for arg in args:
  15. if arg == '--ya-start-command-file' or arg == '--ya-end-command-file':
  16. continue
  17. res.append(arg)
  18. return res
  19. def iter_args(
  20. args, # type: list[str]
  21. ):
  22. for arg in args:
  23. if not is_cmdfile_arg(arg):
  24. if arg == '--ya-start-command-file' or arg == '--ya-end-command-file':
  25. continue
  26. yield arg
  27. else:
  28. for cmdfile_arg in read_from_command_file(cmdfile_path(arg)):
  29. yield cmdfile_arg
  30. def get_args(args):
  31. # type: (list[str]) -> list[str]
  32. return list(iter_args(args))