Unverified Commit 7b9abda6 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

refactor to use a function to process files with lists of styles

parent c93ee104
Loading
Loading
Loading
Loading
+53 −101
Original line number Original line Diff line number Diff line
@@ -90,6 +90,25 @@ def add_suffix(list,style):
    else:
    else:
        return style
        return style


def check_style(file,dir,pattern,list,name,suffix=False,skip=()):
    f = os.path.join(dir, file)
    fp = open(f)
    text = fp.read()
    fp.close()
    matches = re.findall(pattern,text,re.MULTILINE)
    counter = 0
    for c in list.keys():
        # known undocumented aliases we need to skip
        if c in skip: continue
        s = c
        if suffix: s = add_suffix(list,c)
        if not s in matches:
            if not list[c]['removed']:
                print("%s style entry %s" % (name,s),
                      "is missing or incomplete in %s" % file)
                counter += 1
    return counter

for h in headers:
for h in headers:
    if verbose: print("Checking ", h)
    if verbose: print("Checking ", h)
    fp = open(h)
    fp = open(h)
@@ -170,7 +189,7 @@ for h in headers:
            print("Skipping over: ",m)
            print("Skipping over: ",m)




print("""Parsed styles from C++ tree in %s:
print("""Parsed style names w/o suffixes from C++ tree in %s:
   Angle styles:     %3d    Atom styles:      %3d
   Angle styles:     %3d    Atom styles:      %3d
   Body styles:      %3d    Bond styles:      %3d
   Body styles:      %3d    Bond styles:      %3d
   Command styles:   %3d    Compute styles:   %3d
   Command styles:   %3d    Compute styles:   %3d
@@ -186,106 +205,39 @@ print("""Parsed styles from C++ tree in %s:




counter = 0
counter = 0
# check main commands lists
f = os.path.join(doc, 'Commands_all.rst')
fp = open(f)
text = fp.read()
fp.close()
matches = re.findall(":doc:`(.+) <.+>`",text,re.MULTILINE)
for c in command.keys():
    if not c in matches:
        if not command[c]['removed']:
            print("Command %s is missing in Commands_all.rst" % c)
            counter += 1

f = os.path.join(doc, 'Commands_compute.rst')
fp = open(f)
text = fp.read()
fp.close()
matches = re.findall(":doc:`(.+) <compute.+>`",text,re.MULTILINE)
for c in compute.keys():
    if not add_suffix(compute,c) in matches:
        if not compute[c]['removed']:
            print("Compute style entry %s is missing or" % c,
                  "incomplete in Commands_compute.rst")
            counter += 1

f = os.path.join(doc, 'Commands_fix.rst')
fp = open(f)
text = fp.read()
fp.close()
matches = re.findall(":doc:`(.+) <fix.+>`",text,re.MULTILINE)
for c in fix.keys():
    # known undocumented aliases we need to skip
    if c in ('python'): continue
    if not add_suffix(fix,c) in matches:
        if not fix[c]['removed']:
            print("Fix style entry %s is missing or" % c,
                  "incomplete in Commands_fix.rst")
            counter += 1


f = os.path.join(doc, 'Commands_pair.rst')
counter += check_style('Commands_all.rst',doc,":doc:`(.+) <.+>`",
fp = open(f)
                       command,'Command',suffix=False)
text = fp.read()
counter += check_style('Commands_compute.rst',doc,":doc:`(.+) <compute.+>`",
fp.close()
                       compute,'Compute',suffix=True)
matches = re.findall(":doc:`(.+) <pair.+>`",text,re.MULTILINE)
counter += check_style('compute.rst',doc,":doc:`(.+) <compute.+>` -",
for c in pair.keys():
                       compute,'Compute',suffix=False)
    # known undocumented aliases we need to skip
counter += check_style('Commands_fix.rst',doc,":doc:`(.+) <fix.+>`",
    if c in ('meam','lj/sf'): continue
                       fix,'Fix',skip=('python'),suffix=True)
    if not add_suffix(pair,c) in matches:
counter += check_style('fix.rst',doc,":doc:`(.+) <fix.+>` -",
        if not pair[c]['removed']:
                       fix,'Fix',skip=('python'),suffix=False)
            print("Pair style entry %s is missing or" % c,
counter += check_style('Commands_pair.rst',doc,":doc:`(.+) <pair.+>`",
                  "incomplete in Commands_pair.rst")
                       pair,'Pair',skip=('meam','lj/sf'),suffix=True)
            counter += 1
counter += check_style('pair_style.rst',doc,":doc:`(.+) <pair.+>` -",

                       pair,'Pair',skip=('meam','lj/sf'),suffix=False)
f = os.path.join(doc, 'Commands_bond.rst')
counter += check_style('Commands_bond.rst',doc,":doc:`(.+) <bond.+>`",
fp = open(f)
                       bond,'Bond',suffix=True)
text = fp.read()
counter += check_style('bond_style.rst',doc,":doc:`(.+) <bond.+>` -",
fp.close()
                       bond,'Bond',suffix=False)
matches = re.findall(":doc:`(.+) <bond.+>`",text,re.MULTILINE)
counter += check_style('Commands_bond.rst',doc,":doc:`(.+) <angle.+>`",
for c in bond.keys():
                       angle,'Angle',suffix=True)
    if not add_suffix(bond,c) in matches:
counter += check_style('angle_style.rst',doc,":doc:`(.+) <angle.+>` -",
        if not bond[c]['removed']:
                       angle,'Angle',suffix=False)
            print("Bond style entry %s is missing or" % c,
counter += check_style('Commands_bond.rst',doc,":doc:`(.+) <dihedral.+>`",
                  "incomplete in Commands_bond.rst")
                       dihedral,'Dihedral',suffix=True)
            counter += 1
counter += check_style('dihedral_style.rst',doc,":doc:`(.+) <dihedral.+>` -",

                       dihedral,'Dihedral',suffix=False)
matches = re.findall(":doc:`(.+) <angle.+>`",text,re.MULTILINE)
counter += check_style('Commands_bond.rst',doc,":doc:`(.+) <improper.+>`",
for c in angle.keys():
                       improper,'Improper',suffix=True)
    if not add_suffix(angle,c) in matches:
counter += check_style('improper_style.rst',doc,":doc:`(.+) <improper.+>` -",
        if not angle[c]['removed']:
                       improper,'Improper',suffix=False)
            print("Angle style entry %s is missing or" % c,
counter += check_style('Commands_kspace.rst',doc,":doc:`(.+) <kspace_style>`",
                  "incomplete in Commands_bond.rst")
                       kspace,'KSpace',suffix=True)
            counter += 1

matches = re.findall(":doc:`(.+) <dihedral.+>`",text,re.MULTILINE)
for c in dihedral.keys():
    if not add_suffix(dihedral,c) in matches:
        if not dihedral[c]['removed']:
            print("Dihedral style entry %s is missing or" % c,
                  "incomplete in Commands_bond.rst")
            counter += 1

matches = re.findall(":doc:`(.+) <improper.+>`",text,re.MULTILINE)
for c in improper.keys():
    if not add_suffix(improper,c) in matches:
        if not improper[c]['removed']:
            print("Improper style entry %s is missing or" % c,
                  "incomplete in Commands_bond.rst")
            counter += 1

f = os.path.join(doc, 'Commands_kspace.rst')
fp = open(f)
text = fp.read()
fp.close()
matches = re.findall(":doc:`(.+) <kspace_style>`",text,re.MULTILINE)
for c in kspace.keys():
    if not add_suffix(kspace,c) in matches:
        if not kspace[c]['removed']:
            print("KSpace style entry %s is missing or" % c,
                  "incomplete in Commands_kspace.rst")
            print(kspace[c])
            counter += 1


if counter:
if counter:
    print("Found %d issue(s) with style lists" % counter)
    print("Found %d issue(s) with style lists" % counter)