def add_lines_to_file()

in cicd-deployers/metadata_deployer.py [0:0]


def add_lines_to_file(filename, new_lines):
    """Appends new lines to the end of a file, handling potential errors.
    Args:
        filename (str): The path to the flat file.
        new_lines (list): A list of strings representing the new lines to add.
    """
    try:
        with open(filename, 'a') as file:
            file.write('\n')
            for line in new_lines:
                file.write(line + '\n')
        print("Lines added successfully!")
        with open(filename, 'r') as file:
            file_content = file.read()
            new_content = file_content.replace("requests>=2.32.*", "requests==2.32.*")
        with open(filename, 'w') as file:
            file.write(new_content)
    except FileNotFoundError:
        print(f"Error: File '{filename}' not found.")
    except IOError:
        print(f"Error: An I/O error occurred while working with '{filename}'.")