Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

65 linhas
1.8KB

  1. # Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import subprocess
  5. import re
  6. from .config import _AVAILABLE_MIGRATION_STEPS
  7. from .log import logger
  8. def _get_available_init_version_names():
  9. return [x["init_version_name"] for x in _AVAILABLE_MIGRATION_STEPS]
  10. def _get_available_target_version_names():
  11. return [x["target_version_name"] for x in _AVAILABLE_MIGRATION_STEPS]
  12. def _get_latest_version_name():
  13. return _AVAILABLE_MIGRATION_STEPS[-1]["target_version_name"]
  14. def _get_latest_version_code():
  15. return _AVAILABLE_MIGRATION_STEPS[-1]["target_version_code"]
  16. def _execute_shell(shell_command, path=False, raise_error=True):
  17. if path:
  18. shell_command = "cd %s && %s" % (str(path.resolve()), shell_command)
  19. logger.debug("Execute Shell:\n%s" % (shell_command))
  20. if raise_error:
  21. return subprocess.check_output(shell_command, shell=True)
  22. else:
  23. return subprocess.run(shell_command, shell=True)
  24. def _read_content(file_path):
  25. f = open(file_path, "r")
  26. text = f.read()
  27. f.close()
  28. return text
  29. def _write_content(file_path, content):
  30. f = open(file_path, "w")
  31. f.write(content)
  32. f.close()
  33. def _replace_in_file(file_path, replaces, log_message=False):
  34. current_text = _read_content(file_path)
  35. new_text = current_text
  36. for old_term, new_term in replaces.items():
  37. new_text = re.sub(old_term, new_term or "", new_text)
  38. # Write file if changed
  39. if new_text != current_text:
  40. if not log_message:
  41. log_message = "Changing content of file: %s" % file_path.name
  42. logger.info(log_message)
  43. _write_content(file_path, new_text)
  44. return new_text
上海开阖软件有限公司 沪ICP备12045867号-1