
import os
import pathlib

fnlist=[]
for dir in ['../configs/ct','../configs/sh']:
    fnlist+=list(pathlib.Path(dir).glob('*8360*-?-*.cfg'))
    fnlist+=list(pathlib.Path(dir).glob('*8325*.cfg'))

#print(fnlist)
             
vlandict={}
vlannamedict={}

allfilenames=[]

for fn in fnlist:
    with fn.open() as infile:
        allfilenames.append(fn.name.split('.')[0])
        for line in infile:
            if line.startswith("vlan "):
                #print(line)
                vlan=int(line.strip().split()[1])
                try:
                    vlandict[vlan].append(os.path.basename(fn).split('.')[0])
                except KeyError:
                    vlandict[vlan]=[]
                    vlandict[vlan].append(os.path.basename(fn).split('.')[0])
            elif line.strip().startswith("name"):
                if vlan:
                    vlannamedict[vlan]=line.strip()[5:]
                    vlan=None

#print(vlandict)
#print (allfilenames)

#sys.exit()
missingdict={}
#sys.exit()
for vlan in vlandict:
    for fn in allfilenames:
        #print(vlandict[vlan])
        if fn not in vlandict[vlan]:
            #print(f"{fn} missing {vlan}")
            if fn not in missingdict:
                missingdict[fn]=[]
            missingdict[fn].append(vlan)

#print(missingdict)


for fn in missingdict:
    vlanlist=[]
    for vlan in sorted(missingdict[fn]):
        vlanlist.append(str(vlan))
    print(f"{fn} missing {','.join(vlanlist)}")

print(vlannamedict)