update.py 903 B

1234567891011121314151617181920212223242526
  1. import os
  2. import re
  3. import shutil
  4. import subprocess
  5. # versions will be a list of all #, ## and ##.## directories
  6. versions = [p for p in os.listdir() if os.path.isdir(p) and re.match(r"^\d+(\.\d+)?$", p)]
  7. with open(os.path.join("template", "Dockerfile.template"), "r", encoding="utf-8") as f:
  8. dockerfile_template = f.read()
  9. for version in versions:
  10. # write Dockerfile in version directory
  11. with open(os.path.join(version, "Dockerfile"), "w", encoding="utf-8") as f:
  12. f.write(dockerfile_template % {"VERSION":version})
  13. # copy other files into version directory
  14. for file_name in os.listdir("template"):
  15. if file_name == "Dockerfile.template":
  16. continue
  17. # we use system cp in order to preserve file permissions
  18. p = subprocess.Popen(['cp', os.path.join("template", file_name), os.path.join(version, file_name)])
  19. p.wait()