示例#1
0
    def initialize(self):
        super(TracConnector, self).initialize()

        # Verify that the configuration options are set properly
        self.config.process_list_config('alm_done_statuses')

        if not self.config['alm_done_statuses']:
            raise UsageError('Missing alm_done_statuses in configuration')

        for action_type in ['alm_close_transition', 'alm_reopen_transition']:
            action_to_take = self.config[action_type]

            if not action_to_take:
                raise UsageError('Missing %s value' % action_type)

            if ',' in action_to_take:
                action_to_take, action_args = action_to_take.split(',', 1)
            else:
                action_args = '{}'
            try:
                action_args = json.loads(action_args)
            except:
                raise UsageError('Unable to JSON decode action arguments: %s' % action_args)
            if type(action_args) is not dict:
                raise UsageError('Invalid action argument: %s' % repr(action_args))
            self.config[action_type] = (action_to_take, action_args)
示例#2
0
    def parse_error(self, result):
        # Try to parse the response as JSON
        try:
            error_response = json.loads(result)
        except ValueError:
            return result

        # Send back all the error messages in one go
        if 'message' in error_response and error_response['message']:
            return error_response['message']
        else:
            return result
示例#3
0
    def parse_error(self, result):
        # Try to parse the response as JSON
        try:
            error_response = json.loads(result)
        except ValueError:
            return result

        # Send back all the error messages in one go
        if 'exceptions' in error_response:
            error_messages = []
            for msg in error_response['exceptions']:
                error_messages.append('%s: %s' % (msg['type'], msg['message']))
            return ' '.join(error_messages)
        else:
            return result
示例#4
0
 def process_json_dict(self, key):
     try:
         if not self[key]:
             self[key] = {}
         elif isinstance(self[key], basestring):
             self[key] = json.loads(self[key])
         if type(self[key]) is not dict:
             raise TypeError('Not a dictionary: %s' % self[key])
         for name in self[key]:
             if not isinstance(name, basestring):
                 raise TypeError('Invalid key for %s: %s' % (key, str(name)))
             val = self[key][name]
             if not isinstance(val, (basestring, list, int)):
                 raise TypeError('Invalid value for %s: %s' % (key, repr(val)))
     except Exception as err:
         raise UsageError('Unable to process %s (not a JSON dictionary). Reason: %s' % (key, str(err)))
示例#5
0
    def parse_error(self, result):
        # Try to parse the response as JSON
        try:
            error_response = json.loads(result)
        except ValueError:
            return result

        # Send back all the error messages in one go
        if 'errorMessages' in error_response and error_response['errorMessages']:
            return ' '.join(error_response['errorMessages'])
        elif 'errors' in error_response:
            error_messages = []
            for field, field_message in error_response['errors'].items():
                error_messages.append('%s: %s' % (field, field_message))
            return ' '.join(error_messages)
        else:
            return result
示例#6
0
 def parse_response(self, result, headers):
     if not result or result.strip() == "":
         return {}
     else:
         return json.loads(result)