Beispiel #1
0
    def print_service_details(self, json_data, format='text', ansi=True):
        '''Print details of a service
        format: text OR json
        ansi: True OR False (ansi colored text)
        '''
        if format == 'json':
            print json_data
            return
        elif format == 'text':
            for key in SERVICE_KEYS:
                if key == 'ipAddresses':
                    print camel_to_human(key, ansi) + ":"
                    for ip in json_data['service']['ipAddresses']:
                        print "    " + ip
                elif key == 'addons':
                    print camel_to_human(key, ansi) + ":"
                    for addon in json_data['service']['addons']:
                        print "    " + addon['description']

                elif key == 'billingStatus' or key == 'serviceType' or key == 'operatingSystem':
                    #These are integers, we show the text instead
                    #We'll only show if ---debug
                    logger.debug(camel_to_human(key, ansi) + ":")
                    logger.debug(json_data['service'][key])
                else:
                    if json_data['service'][key]:
                        print camel_to_human(key, ansi) + ":"
                        print '    ' + json_data['service'][key]
                    else:
                        #We are skipping a field that doesn't apply, such as
                        #alternateDomain for a (dv) Dedicated-Virtual Server
                        #DEBUG
                        pass
        else:
            print "Error: No such format: %s" % format
Beispiel #2
0
    def print_response_details(self, json_data, format='text', ansi=True):
        '''Prints the response all pretty like'''
        if format == 'json':
            print json_data
            return
        elif format == 'text':
            for key in RESPONSE_KEYS:
                if key == 'statusCode':
                    print camel_to_human(key, ansi) + ":"
                    print "    " + str(json_data['response'][key]) + " " + RESPONSE_CODES[json_data['response'][key]]

                elif key == 'timeStamp':
                   self.logger.debug(camel_to_human(key) + ":", ansi)
                   self.logger.debug(json_data['response'][key])

                elif key == 'errors':
                    print camel_to_human(key, ansi) + ":"
                    for error in json_data['response']['errors']:
                        print "    " + error['message']

                elif key == 'custom':
                    pass

                else:
                    if json_data['response'][key]:
                        print camel_to_human(key, ansi) + ":"
                        print '    ' + json_data['response'][key]
                    else:
                        pass
        else:
            print "Error: No such format: %s" % format
Beispiel #3
0
def print_service_details(json_data, format='text'):
    '''Print details of a service'''
    if format == 'json':
        print json_data
        return
    elif format == 'text':
        for key in SERVICE_KEYS:
            if key == 'ipAddresses':
                print camel_to_human(key) + ":"
                for ip in json_data['service']['ipAddresses']:
                    print "    " + ip
            elif key == 'addons':
                print camel_to_human(key) + ":"
                for addon in json_data['service']['addons']:
                    print "    " + addon['description']

            elif key == 'billingStatus' or key == 'serviceType' or key == 'operatingSystem':
                #These are integers, we use the text instead
                #Maybe show it if verbose?
                pass
            else:
                if json_data['service'][key]:
                    print camel_to_human(key) + ":"
                    print '    ' + json_data['service'][key]
                else:
                    #We are skipping a field that doesn't apply, such as
                    #alternateDomain for a (dv) Dedicated-Virtual Server
                    #DEBUG
                    pass
    else:
        print "Error: No such format: %s" % format
Beispiel #4
0
def test_camel_to_human():
    assert camel_to_human("thisWasCamelCase") == "This was camel case"
    assert camel_to_human("thisIsCamelCase") == "This is camel case"
    assert camel_to_human("oneTwo") == "One two"
    assert camel_to_human("oneTwoThree") == "One two three"