mkdocs_builder_wrapper.py 1.0 KB

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