process_command_files.py 832 B

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