Skip to content

Library doesn't detect syntax issues in conf files. #102

@yaroslav-nakonechnikov

Description

@yaroslav-nakonechnikov

Hello,

with help of this library i've created simple script to validate conf files:

import addonfactory_splunk_conf_parser_lib as conf_parser
import os
import argparse

def check_syntax(filename):
    parser = conf_parser.TABConfigParser()
    try:
        with open(filename, 'r') as f:
            parser.read_file(f)
        print(f"Syntax of the file '{filename}' is correct.")
    except conf_parser.Error as e:  # Catching all configparser errors with a generic class
        print(f"Syntax error in file '{filename}': {e}")
    except FileNotFoundError:
        print(f"File '{filename}' not found.")
    except Exception as e:
        print(f"An unexpected error occurred in file '{filename}': {e}")

def scan_directory_for_conf_files(directory):
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.endswith('.conf'):
                file_path = os.path.join(root, file)
                check_syntax(file_path)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Syntax checker for .conf files.')
    parser.add_argument('dir_path', type=str, help='Path to direcory to scan')

    args = parser.parse_args()

    # Determine the operation to perform
    if args.dir_path:
        scan_directory_for_conf_files(args.dir_path)
    else:
        directory_to_scan = input("Enter the directory path to scan for .conf files: ")
        scan_directory_for_conf_files(directory_to_scan)

and in that script when file has syntax error - it thinks that all good.

example:
image
as you see, empty space is there, but it should be wiped.

and it passes wrong multine search:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions