Пример #1
0
 def test_parse_bad_json(self):
     with self.assertLogs(logging.getLogger(), logging.ERROR):
         with self.assertRaises(json.decoder.JSONDecodeError):
             result = read_json.parse_json(BAD_JSON1)
     with self.assertLogs(logging.getLogger(), logging.ERROR):
         with self.assertRaises(json.decoder.JSONDecodeError):
             result = read_json.parse_json(BAD_JSON2)
Пример #2
0
    def __init__(self,
                 json=None,
                 data_id=None,
                 message_type=None,
                 timestamp=0,
                 fields={},
                 metadata={}):
        """
    If a json string is passed, it is parsed into a dictionary and its
    values for timestamp, fields and metadata are copied in. Otherwise,
    the DASRecord object is initialized with the passed-in values for
    instrument, timestamp, fields (a dictionary of fieldname-value pairs)
    and metadata.

    If timestamp is not specified, the instance will use the current time.
    """
        if json:
            parsed = parse_json(json)
            self.data_id = parsed.get('data_id', None)
            self.message_type = parsed.get('message_type', None)
            self.timestamp = parsed.get('timestamp', None)
            self.fields = parsed.get('fields', {})
            self.metadata = parsed.get('metadata', {})
        else:
            #self.source =
            self.data_id = data_id
            self.message_type = message_type
            self.timestamp = timestamp or timestamp_method()
            self.fields = fields
            self.metadata = metadata
Пример #3
0
def load_cruise_config(request):
    global api
    if api is None:
        api = DjangoServerAPI()

    # If not a POST, just draw the page
    if not request.method == 'POST':
        return render(request, 'django_gui/load_cruise_config.html', {})

    # If POST, we've expect there to be a file to process
    else:
        errors = []

        # Did we get a configuration file?
        if request.FILES.get('config_file', None):
            config_file = request.FILES['config_file']
            config_contents = config_file.read()
            logging.warning('Uploading file "%s"...', config_file.name)

            try:
                config = parse_json(config_contents.decode('utf-8'))
                api.load_cruise(config, config_file.name)
            except JSONDecodeError as e:
                errors.append(str(e))
            except ValueError as e:
                errors.append(str(e))

            # If no errors, close window - we're done.
            if not errors:
                return HttpResponse('<script>window.close()</script>')

        else:
            errors.append('No configuration file selected')

        # If here, there were errors
        return render(request, 'django_gui/load_cruise_config.html',
                      {'errors': ';'.join(errors)})
Пример #4
0
 def test_parse_json(self):
     result = read_json.parse_json(SAMPLE_JSON)
     self.assertEqual(result['gyr1']['port'], '/tmp/tty_gyr1')
     self.assertEqual(len(result), 4)
Пример #5
0
modes['off'] = {}
modes['file'] = {}
modes['db'] = {}
modes['file/db'] = {}

for line in lines:
    (inst, port) = line.split('\t', maxsplit=2)

    if ALL_USE_SAME_PORT:
        port = PORT

    config = file_db_config
    config = config.replace('INST', inst)
    config = config.replace('PORT', port)
    config = config.replace('CRUISE', cruise)
    configs['%s->file/db' % inst] = parse_json(config)

    config = file_config
    config = config.replace('INST', inst)
    config = config.replace('PORT', port)
    config = config.replace('CRUISE', cruise)
    configs['%s->file' % inst] = parse_json(config)

    config = db_config
    config = config.replace('INST', inst)
    config = config.replace('PORT', port)
    config = config.replace('CRUISE', cruise)
    configs['%s->db' % inst] = parse_json(config)

    loggers[inst] = {}
    loggers[inst]['configs'] = [