mkdocs_builder_wrapper.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from __future__ import unicode_literals
  2. import os
  3. import subprocess
  4. import sys
  5. def main():
  6. cmd = []
  7. build_root = sys.argv[1]
  8. length = len(build_root)
  9. is_dep = False
  10. for arg in sys.argv[2:]:
  11. if is_dep:
  12. is_dep = False
  13. if not arg.endswith('.tar.gz'):
  14. continue
  15. basename = os.path.basename(arg)
  16. assert arg.startswith(build_root) and len(arg) > length + len(basename) and arg[length] in ('/', '\\')
  17. cmd.extend([str('--dep'), str('{}:{}:{}'.format(build_root, os.path.dirname(arg[length + 1 :]), basename))])
  18. elif arg == '--dep':
  19. is_dep = True
  20. else:
  21. cmd.append(arg)
  22. assert not is_dep
  23. p = subprocess.Popen(cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  24. out, err = p.communicate()
  25. if p.returncode:
  26. if out:
  27. sys.stderr.write('stdout:\n{}\n'.format(out.decode('utf-8')))
  28. if err:
  29. sys.stderr.write('stderr:\n{}\n'.format(err.decode('utf-8')))
  30. sys.exit(p.returncode)
  31. if __name__ == '__main__':
  32. main()