#!/usr/bin/env python
#
# program to parse the files in the /etc/sudoers.d
#
# python 2.x only

path_fn='/etc/sudoers.d'

import os
for fn in os.listdir(path_fn):
    full_path=path_fn + "/" + fn
    #   if os.path.isfile(fn):        # doesn't work - why?
    # print (full_path)

    with open(full_path) as file:
        line_lst = []
        for line in file:
            if not ( line.startswith(('Defau', '\n', '#'), 0, 5) ) :
                line_lst = line_lst + [ line ]
        print ('{\n\t"sudodirs": [')
        map_list=[]
        for x,y in enumerate(line_lst):
            map_list.append(y)
            print('\t{{\n\t\t"sudodir_file": "{}"').format(map_list[x].rstrip())
            if (x + 1 != len(line_lst)) :
                print('\t},')
            else:
                print('\t}')
        print ('\t]\n}')

