Surface NMR processing and inversion GUI
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

utils.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. try:
  2. import colorama
  3. except ImportError:
  4. has_colorama = False
  5. else:
  6. has_colorama = True
  7. import shlex
  8. try:
  9. # Python 3
  10. from shlex import quote
  11. except ImportError:
  12. # Python 2
  13. from pipes import quote
  14. def build_args(cmd, src, dst):
  15. """
  16. Build arguments list for passing to subprocess.call_check
  17. :param cmd str: Command string to interpolate src and dst filepaths into.
  18. Typically the output of `config.Config.uic_command` or `config.Config.rcc_command`.
  19. :param src str: Source filepath.
  20. :param dst str: Destination filepath.
  21. """
  22. cmd = cmd % (quote(src), quote(dst))
  23. args = shlex.split(cmd)
  24. return [arg for arg in args if arg]
  25. def write_message(text, color=None):
  26. if has_colorama:
  27. colors = {
  28. 'red': colorama.Fore.RED,
  29. 'green': colorama.Fore.GREEN,
  30. 'yellow': colorama.Fore.YELLOW,
  31. 'blue': colorama.Fore.BLUE
  32. }
  33. try:
  34. print(colors[color] + text + colorama.Fore.RESET)
  35. except KeyError:
  36. print(text)
  37. else:
  38. print(text)