Esempio n. 1
0
def parse_domains(contents):
    domains = {}

    portion = get_portion(contents, '[Domains]')
    lines = parse_portion(portion)
    for id, fqdn in lines:
        validate.integer(id)
        id = int(id)

        domains[id] = (fqdn)
    return domains
Esempio n. 2
0
def parse_services(contents):
    services = {}

    portion = get_portion(contents, '[Services]')
    lines = parse_portion(portion)
    for id, args in lines:
        host, port = args

        validate.integer(host)
        validate.integer(port)

        services[id] = (host, port)
    return services
Esempio n. 3
0
def parse_poll_inputs(contents):
    poll_inputs = {}
    portion = get_portion(contents, '[PollInputs]')
    lines = parse_portion(portion)
    for id, args in lines:
        validate.integer(id)
        id = int(id)

        input_class_str = 'polling.' + args[0]
        args = ','.join(args[1:])

        validate.input_class(input_class_str)
        validate.jsondata(args)

        input_class = load_module(input_class_str)
        args = json.loads(args)
        input = input_class(*args)

        poll_inputs[id] = pickle.dumps(input)
    return poll_inputs
Esempio n. 4
0
def parse_users(contents, teams):
    users = {}
    portion = get_portion(contents, '[Users]')
    lines = parse_portion(portion)
    for id, args in lines:
        id = int(id)
        team_id, username, password, is_admin = args

        validate.integer(team_id)
        validate.integer(is_admin)

        team_id = int(team_id)
        is_admin = int(is_admin)

        if team_id != 0:
            validate.id_exists(team_id, teams)
        validate.boolean(is_admin)

        user = (team_id, username, password, is_admin)
        users[id] = user
    return users
Esempio n. 5
0
def parse_credentials(contents, domains, check_ios):
    credentials = {}

    portion = get_portion(contents, '[Credentials]')
    lines = parse_portion(portion)
    for id, args in lines:
        validate.integer(id)
        id = int(id)
        domain_id = None
        if '[' not in args[2]:
            domain_id = args[0]
            args = args[1:]

        user, passwd = args[0], args[1]
        check_io_ids = json.loads(','.join(args[2:]))

        if domain_id is not None:
            validate.integer(domain_id)
            domain_id = int(domain_id)
            validate.id_exists(domain_id, domains)
        for check_io_id in check_io_ids:
            validate.integer(check_io_id)
            check_io_id = int(check_io_id)
            validate.id_exists(check_io_id, check_ios)

        credentials[id] = (user, passwd, domain_id, check_io_ids)
    return credentials
Esempio n. 6
0
def parse_checks(contents, services):
    checks = {}

    portion = get_portion(contents, '[Checks]')
    lines = parse_portion(portion)
    for id, args in lines:
        validate.integer(id)
        id = int(id)

        name, check_function, poller, service_id = args
        check_function = 'checker.' + check_function
        poller = 'polling.' + poller

        validate.check_function(check_function)
        validate.poller(poller)

        validate.integer(service_id)
        service_id = int(service_id)
        validate.id_exists(service_id, services)

        checks[id] = (name, check_function, poller, service_id)
    return checks
Esempio n. 7
0
def parse_check_ios(contents, poll_inputs, checks):
    check_ios = {}

    portion = get_portion(contents, '[CheckIOs]')
    lines = parse_portion(portion)
    for id, args in lines:
        validate.integer(id)
        id = int(id)

        input_id, check_id = args[0], args[1]
        expected = ','.join(args[2:])

        validate.integer(input_id)
        input_id = int(input_id)
        validate.id_exists(input_id, poll_inputs)

        validate.jsondata(expected)

        validate.integer(check_id)
        check_id = int(check_id)
        validate.id_exists(check_id, checks)

        check_ios[id] = (input_id, expected, check_id)
    return check_ios
Esempio n. 8
0
 def set_volume(self, volume):
     validate.integer(volume, 'Volume')
     validate.midi_range(volume, 'Volume')
     self.__volume = volume
Esempio n. 9
0
 def set_instrument(self, instrument):
     validate.integer(instrument, 'Instrument')
     validate.midi_range(instrument, 'Instrument')
     self.__instrument = instrument
Esempio n. 10
0
 def set_number(self, number):
     validate.integer(number, 'Note number')
     validate.midi_range(number, 'Note number')
     self.__number = number