def save_configuration_to_text_file(register, configuration_file):
configuration_path, filename = os.path.split(configuration_file)<EOL>if os.path.split(configuration_path)[<NUM_LIT:1>] == '<STR_LIT>':<EOL><INDENT>configuration_path = os.path.split(configuration_path)[<NUM_LIT:0>]<EOL><DEDENT>filename = os.path.splitext(filename)[<NUM_LIT:0>].strip()<EOL>register.configuration_file = os.path.join(os.path.join(configuration_path, '<STR_LIT>'), filename + "<STR_LIT>")<EOL>if os.path.isfile(register.configuration_file):<EOL><INDENT>logging.warning("<STR_LIT>", register.configuration_file)<EOL><DEDENT>else:<EOL><INDENT>logging.info("<STR_LIT>" % register.configuration_file)<EOL><DEDENT>pixel_reg_dict = {}<EOL>for path in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>configuration_file_path = os.path.join(configuration_path, path)<EOL>if not os.path.exists(configuration_file_path):<EOL><INDENT>os.makedirs(configuration_file_path)<EOL><DEDENT>if path == "<STR_LIT>":<EOL><INDENT>dac = register.get_pixel_register_objects(name="<STR_LIT>")[<NUM_LIT:0>]<EOL>dac_config_path = os.path.join(configuration_file_path, "<STR_LIT:_>".join([dac['<STR_LIT:name>'].lower(), filename]) + "<STR_LIT>")<EOL>write_pixel_dac_config(dac_config_path, dac['<STR_LIT:value>'])<EOL>pixel_reg_dict[dac['<STR_LIT:name>']] = os.path.relpath(dac_config_path, os.path.dirname(register.configuration_file))<EOL><DEDENT>elif path == "<STR_LIT>":<EOL><INDENT>dac = register.get_pixel_register_objects(name="<STR_LIT>")[<NUM_LIT:0>]<EOL>dac_config_path = os.path.join(configuration_file_path, "<STR_LIT:_>".join([dac['<STR_LIT:name>'].lower(), filename]) + "<STR_LIT>")<EOL>write_pixel_dac_config(dac_config_path, dac['<STR_LIT:value>'])<EOL>pixel_reg_dict[dac['<STR_LIT:name>']] = os.path.relpath(dac_config_path, os.path.dirname(register.configuration_file))<EOL><DEDENT>elif path == "<STR_LIT>":<EOL><INDENT>masks = register.get_pixel_register_objects(bitlength=<NUM_LIT:1>)<EOL>for mask in masks:<EOL><INDENT>dac_config_path = os.path.join(configuration_file_path, "<STR_LIT:_>".join([mask['<STR_LIT:name>'].lower(), filename]) + "<STR_LIT>")<EOL>write_pixel_mask_config(dac_config_path, mask['<STR_LIT:value>'])<EOL>pixel_reg_dict[mask['<STR_LIT:name>']] = os.path.relpath(dac_config_path, os.path.dirname(register.configuration_file))<EOL><DEDENT><DEDENT>elif path == "<STR_LIT>":<EOL><INDENT>with open(register.configuration_file, '<STR_LIT:w>') as f:<EOL><INDENT>lines = []<EOL>lines.append("<STR_LIT>")<EOL>lines.append('<STR_LIT>' % ('<STR_LIT>', register.flavor))<EOL>lines.append("<STR_LIT>")<EOL>lines.append('<STR_LIT>' % ('<STR_LIT>', register.chip_id))<EOL>lines.append("<STR_LIT>")<EOL>global_regs = register.get_global_register_objects(readonly=False)<EOL>for global_reg in sorted(global_regs, key=itemgetter('<STR_LIT:name>')):<EOL><INDENT>lines.append('<STR_LIT>' % (global_reg['<STR_LIT:name>'], global_reg['<STR_LIT:value>']))<EOL><DEDENT>lines.append("<STR_LIT>")<EOL>for key in sorted(pixel_reg_dict):<EOL><INDENT>lines.append('<STR_LIT>' % (key, pixel_reg_dict[key]))<EOL><DEDENT>lines.append("<STR_LIT>")<EOL>for key in register.calibration_parameters:<EOL><INDENT>if register.calibration_parameters[key] is None:<EOL><INDENT>lines.append('<STR_LIT>' % (key, register.calibration_parameters[key]))<EOL><DEDENT>elif isinstance(register.calibration_parameters[key], (float, int, long)):<EOL><INDENT>lines.append('<STR_LIT>' % (key, round(register.calibration_parameters[key], <NUM_LIT:4>)))<EOL><DEDENT>elif isinstance(register.calibration_parameters[key], list):<EOL><INDENT>lines.append('<STR_LIT>' % (key, [round(elem, <NUM_LIT:2>) for elem in register.calibration_parameters[key]]))<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % type(register.calibration_parameters[key]))<EOL><DEDENT><DEDENT>if register.miscellaneous:<EOL><INDENT>lines.append("<STR_LIT>")<EOL>for key, value in register.miscellaneous.iteritems():<EOL><INDENT>lines.append('<STR_LIT>' % (key, value))<EOL><DEDENT><DEDENT>f.writelines(lines)<EOL><DEDENT><DEDENT><DEDENT>
Saving configuration to text files from register object

    Parameters
    ----------
    register : pybar.fei4.register object
    configuration_file : string
        Filename of the configuration file.