Esempio n. 1
0
def write_delta_cnf_to_file(cnf_file_current, cnf_file_previous,
                            cnf_type_with_ext, out_file, release_note_creator,
                            server):
    try:
        file_only_name = cnf_type_with_ext.split(".cnf")[0]
        _global_val, _p_global_val = None, None
        if cnf_file_current and cnf_file_previous:
            if file_only_name == 'globalVariables':
                _cnf_current, _global_val = ParserTool.parse_global_var(
                    cnf_file_current)
                _cnf_previous, _p_global_val = ParserTool.parse_global_var(
                    cnf_file_previous)
            else:
                _cnf_current = set(
                    ParserTool.parse_cnf_file(file_only_name,
                                              cnf_file_current))
                _cnf_previous = set(
                    ParserTool.parse_cnf_file(file_only_name,
                                              cnf_file_previous))
            if _cnf_current is None and _cnf_previous is None:
                release_note_creator.signal_no_cnf(file_only_name)
                return
            diff = _cnf_current.difference(_cnf_previous)
            if len(diff) == 0:
                return 0
            else:
                if file_only_name == 'globalVariables':
                    temp_g_key, temp_g_val = list(), dict()
                    for key in _global_val:
                        # In this case we want to check if a global var is changed
                        if key not in diff and _global_val[
                                key] != _p_global_val[key]:
                            diff.add(key)
                    for el in diff:
                        temp_g_key.append(el)
                        temp_g_val[el] = _global_val[el]
                    release_note_creator.add_object_to_release_note(
                        file_only_name,
                        server,
                        objects_key=temp_g_key,
                        objects_value=temp_g_val)
                else:
                    release_note_creator.add_object_to_release_note(
                        file_only_name, server, diff)
                with open(out_file, 'w') as f:
                    for el in diff:
                        if el:
                            f.write(el + "\n")
                f.close()
        else:
            release_note_creator.signal_no_cnf(file_only_name)
            logger.warning('there is one file missing check ' +
                           cnf_file_current + ' | ' + cnf_file_previous)
    except IOError as io_e:
        logger.warning("Error for cnf file " + cnf_file_current + " or " +
                       cnf_file_previous + " strerror" + str(io_e.strerror))
        sys.exit(-1)
Esempio n. 2
0
def write_cnf_to_file(cnf_f, cnf_type_with_ext, release_note_creator, server):
    try:
        if cnf_f:
            file_only_name = cnf_type_with_ext.split(".cnf")[0]
            _global_val = None
            if file_only_name == 'globalVariables':
                _cnf_to_write, _global_val = ParserTool.parse_global_var(cnf_f)
            else:
                _cnf_to_write = ParserTool.parse_cnf_file(
                    file_only_name, cnf_f)
            if not _cnf_to_write:
                if os.path.exists(cnf_f):
                    os.remove(cnf_f)
                    return
            if file_only_name == 'globalVariables':
                release_note_creator.add_object_to_release_note(
                    file_only_name,
                    server,
                    objects_key=_cnf_to_write,
                    objects_value=_global_val)
            else:
                release_note_creator.add_object_to_release_note(
                    file_only_name, server, objects_key=_cnf_to_write)
            with open(cnf_f, 'w') as _f:
                for el in _cnf_to_write:
                    _f.write(el + "\n")
            _f.close()
    except IOError as er:
        logger.error("[ERROR]: Error for cnf file " + cnf_f + " error" +
                     str(er.strerror))
        sys.exit(-1)