Ejemplo n.º 1
0
Archivo: config.py Proyecto: gcr/plover
def verify_config(config):
    """Checks that the configuration contains values for all parameters.

    Arguments:

    config -- A ConfigParser.RawConfigParser object.

    Returns True if all parameters were found. Otherwise returns False and adds
    default values for all parameters.

    """
    config_file = CONFIG_FILE
    # Verify options exist.
    for section, option, default in (
      (LOGGING_CONFIG_SECTION, LOG_FILE_OPTION,
                               DEFAULT_LOG_FILE),
      (LOGGING_CONFIG_SECTION, ENABLE_TRANSLATION_LOGGING_OPTION,
                               DEFAULT_ENABLE_TRANSLATION_LOGGING),
      (LOGGING_CONFIG_SECTION, ENABLE_STROKE_LOGGING_OPTION,
                               DEFAULT_ENABLE_STROKE_LOGGING),
      (DICTIONARY_CONFIG_SECTION, DICTIONARY_FILE_OPTION,
                                  DEFAULT_DICTIONARY_FILE),
      (MACHINE_CONFIG_SECTION, MACHINE_TYPE_OPTION,
                               DEFAULT_MACHINE_TYPE),
      (MACHINE_CONFIG_SECTION, MACHINE_AUTO_START_OPTION,
                               DEFAULT_MACHINE_AUTO_START),
      ):
        if not config.has_section(section):
            config.add_section(section)
        if not config.has_option(section, option):
            config.set(section, option, default)

    # Write the file to disk.
    with open(config_file, 'w') as f:
        config.write(f)
Ejemplo n.º 2
0
Archivo: config.py Proyecto: gcr/plover
def verify_config(config):
    """Checks that the configuration contains values for all parameters.

    Arguments:

    config -- A ConfigParser.RawConfigParser object.

    Returns True if all parameters were found. Otherwise returns False and adds
    default values for all parameters.

    """
    config_file = CONFIG_FILE
    # Verify options exist.
    for section, option, default in (
        (LOGGING_CONFIG_SECTION, LOG_FILE_OPTION, DEFAULT_LOG_FILE),
        (LOGGING_CONFIG_SECTION, ENABLE_TRANSLATION_LOGGING_OPTION,
         DEFAULT_ENABLE_TRANSLATION_LOGGING),
        (LOGGING_CONFIG_SECTION, ENABLE_STROKE_LOGGING_OPTION,
         DEFAULT_ENABLE_STROKE_LOGGING),
        (DICTIONARY_CONFIG_SECTION, DICTIONARY_FILE_OPTION,
         DEFAULT_DICTIONARY_FILE),
        (MACHINE_CONFIG_SECTION, MACHINE_TYPE_OPTION, DEFAULT_MACHINE_TYPE),
        (MACHINE_CONFIG_SECTION, MACHINE_AUTO_START_OPTION,
         DEFAULT_MACHINE_AUTO_START),
    ):
        if not config.has_section(section):
            config.add_section(section)
        if not config.has_option(section, option):
            config.set(section, option, default)

    # Write the file to disk.
    with open(config_file, 'w') as f:
        config.write(f)
Ejemplo n.º 3
0
def set_serial_params(serial_port, section, config):
    """Writes a serial.Serial object to a section of a ConfigParser object.

    Arguments:

    serial_port -- A serial.Serial object or an object with the same
    constructor parameters. The parameters of this object will be
    written to the configuration. If None, no action is taken.

    section -- A string representing the section name in which to
    write the serial port parameters.

    config -- The ConfigParser object containing to which to write.

    """
    if serial_port is None:
        return
    if not config.has_section(section):
        config.add_section(section)
    for opt in SERIAL_ALL_OPTIONS:
        config.set(section, opt, serial_port.__getattribute__(opt))
Ejemplo n.º 4
0
Archivo: config.py Proyecto: gcr/plover
def set_serial_params(serial_port, section, config):
    """Writes a serial.Serial object to a section of a ConfigParser object.

    Arguments:

    serial_port -- A serial.Serial object or an object with the same constructor
    parameters. The parameters of this object will be written to the
    configuration. If None, no action is taken.

    section -- A string representing the section name in which to write the
    serial port parameters.

    config -- The ConfigParser object containing to which to write.

    """
    if serial_port is None:
        return
    if not config.has_section(section):
        config.add_section(section)
    for opt in SERIAL_ALL_OPTIONS:
        config.set(section, opt, serial_port.__getattribute__(opt))