| import clean_spice_files |
| import argparse |
| from pathlib import Path |
| import common |
| from collections import defaultdict |
| from pprint import pprint as pp |
| |
| includeforms = ['.include', '.inc', 'include'] |
| |
| if __name__ == '__main__': |
| parser = argparse.ArgumentParser() |
| |
| parser.add_argument( |
| 'input', |
| help='Input JSON file containing the product of spice2mods.py script', |
| type=Path) |
| parser.add_argument( |
| 'outputdir', |
| help='Directory containing cleaned Spice sources', |
| type=Path) |
| parser.add_argument( |
| "--path-prefix-to-remove", |
| help="The substring that needs to be removed before generating subdirectories for Liberty files", |
| type=Path) |
| |
| args = parser.parse_args() |
| |
| with open(args.input, 'r') as infile: |
| spicefiles = infile.readlines() |
| spicefiles = [f.strip() for f in spicefiles] |
| |
| counts = defaultdict(lambda: [0,0,0]) |
| #numnoincludes = defaultdict((0,0,0)) |
| #numboth = defaultdict((0,0,0)) |
| |
| libnames = set() |
| modnames = set() |
| |
| mods2files = defaultdict(list) |
| |
| allprocessedfiles = 0 |
| |
| noincludesnames = set() |
| allincludesnames = set() |
| bothnames = set() |
| |
| for spicefile in spicefiles: |
| allprocessedfiles += 1 |
| with open(spicefile, 'r') as spice: |
| spicelines = spice.readlines() |
| spicelines = clean_spice_files.basic_cleaning(spicelines) |
| onlyincludes = True |
| noincludes = True |
| for line in spicelines: |
| if line.strip() and not any([line.strip().startswith(include) for include in includeforms]): |
| onlyincludes = False |
| elif line.strip(): |
| noincludes = False |
| else: |
| lib, mod = common.mod_extract_from_path(spicefile) |
| # print(f"{spicefile} -> {(lib, mod)}") |
| mods2files[mod].append((lib, spicefile)) |
| libnames.add(lib) |
| modnames.add(mod) |
| if noincludes: |
| counts[(lib,common.version_extract_from_path(spicefile))][0] += 1 |
| noincludesnames.add(Path(spicefile).name) |
| elif onlyincludes: |
| counts[(lib,common.version_extract_from_path(spicefile))][1] += 1 |
| allincludesnames.add(Path(spicefile).name) |
| else: |
| counts[(lib,common.version_extract_from_path(spicefile))][2] += 1 |
| bothnames.add(Path(spicefile).name) |
| if noincludes: |
| # print(f'no includes: {spicefile}') |
| pass |
| |
| # print(f'{numonlyincludes} out of {allprocessedfiles} contain only includes') |
| # print(f'{numnoincludes} out of {allprocessedfiles} contain no includes') |
| |
| for k, l in counts.items(): |
| print(f'{k}: no includes {l[0]}, only includes {l[1]}, both {l[2]}') |
| |
| print('\n\nFiles without includes') |
| for el in noincludesnames: |
| print(el) |
| print('\n\nFiles with only includes') |
| for el in allincludesnames: |
| print(el) |
| print('\n\nFiles with includes and parameters') |
| for el in bothnames: |
| print(el) |
| |
| # print('Files without includes') |
| # pp(numnoincludes) |
| # print('Files with only includes') |
| # pp(numonlyincludes) |
| # print('Files with both') |
| # pp(numboth) |
| |
| # print('Files without includes') |
| # for k, l in numnoincludes.items(): |
| # print(f'{k}: {len(l)}') |
| # print('Files with only includes') |
| # for k, l in numonlyincludes.items(): |
| # print(f'{k}: {len(l)}') |
| # print('Files with both') |
| # for k, l in numboth.items(): |
| # print(f'{k}: {len(l)}') |
| |
| # print('LIBS') |
| # print(libnames) |
| # print('MODS') |
| # print('\n'.join([str(mod) for mod in modnames])) |
| |
| # pp(mods2files, indent=2) |
| # for mod, l in mods2files.items(): |
| # extlist = set() |
| # for li in l: |
| # extlist.add(li[1].split('.')[-1]) |
| # if len(extlist) > 1: |
| # print(f'{mod} : {extlist}') |