utils.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. import re
  3. from const import REPO_ROOT
  4. def update_init_py_version(version):
  5. path = os.path.join(REPO_ROOT, 'compose', '__init__.py')
  6. with open(path, 'r') as f:
  7. contents = f.read()
  8. contents = re.sub(r"__version__ = '[0-9a-z.-]+'", "__version__ = '{}'".format(version), contents)
  9. with open(path, 'w') as f:
  10. f.write(contents)
  11. def update_run_sh_version(version):
  12. path = os.path.join(REPO_ROOT, 'script', 'run', 'run.sh')
  13. with open(path, 'r') as f:
  14. contents = f.read()
  15. contents = re.sub(r'VERSION="[0-9a-z.-]+"', 'VERSION="{}"'.format(version), contents)
  16. with open(path, 'w') as f:
  17. f.write(contents)
  18. def yesno(prompt, default=None):
  19. """
  20. Prompt the user for a yes or no.
  21. Can optionally specify a default value, which will only be
  22. used if they enter a blank line.
  23. Unrecognised input (anything other than "y", "n", "yes",
  24. "no" or "") will return None.
  25. """
  26. answer = input(prompt).strip().lower()
  27. if answer == "y" or answer == "yes":
  28. return True
  29. elif answer == "n" or answer == "no":
  30. return False
  31. elif answer == "":
  32. return default
  33. else:
  34. return None