1
0

utils.py 1.3 KB

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