You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.4 KiB

  1. '''
  2. Created on Jan 23, 2014
  3. @author: Chris
  4. '''
  5. import sys
  6. from gooey.monkey_parser import ArgumentError
  7. from gooey.gui.action_sorter import ActionSorter
  8. class ClientApp(object):
  9. def __init__(self, parser, payload):
  10. self._parser = parser
  11. self.description = parser.description
  12. self.action_groups = ActionSorter(self._parser._actions)
  13. self.payload = payload
  14. def HasPositionals(self):
  15. if self.action_groups._positionals:
  16. return True
  17. return False
  18. def IsValidArgString(self, arg_string):
  19. if isinstance(self._Parse(arg_string), str):
  20. return False
  21. return True
  22. def _Parse(self, arg_string):
  23. try:
  24. print self._parser.error
  25. self._parser.parse_args(arg_string.split())
  26. return True
  27. except ArgumentError as e:
  28. return str(e)
  29. def GetErrorMsg(self, arg_string):
  30. return self._FormatMsg(self._Parse(arg_string))
  31. def _FormatMsg(self, msg):
  32. output = list(msg)
  33. if ':' in output:
  34. output[output.index(':')] = ':\n '
  35. return ''.join(output)
  36. def AddToArgv(self, arg_string):
  37. sys.argv.extend(arg_string.split())
  38. class EmptyClientApp(object):
  39. def __init__(self):
  40. '''
  41. initializes a BlankModel object
  42. As you can see. This class does nothing..
  43. '''
  44. self.description = ''
  45. if __name__ == '__main__':
  46. pass
  47. # print m2