Skip to content

Commit

Permalink
implemented extrafqcnmapfile
Browse files Browse the repository at this point in the history
  • Loading branch information
zerwes committed Jan 7, 2025
1 parent f470e79 commit a104651
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion fqcn-fixer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python3
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 smartindent
# pylint: disable=invalid-name
# pylint: disable=invalid-name,consider-using-f-string

import sys
import os
Expand Down Expand Up @@ -187,6 +187,12 @@ def increase_indent(self, flow=False, *dargs, **dkwargs): # pylint: disable=keyw
default=False,
help="update the fqcn-map-file"
)
argparser.add_argument(
'-X', '--extra-fqcn-map-file',
dest='extrafqcnmapfile',
default='extra-fqcn-map.yml',
help="add the extra fqcn map while updating the fqcn-map-file"
)
argparser.add_argument(
'-D', '--debug',
dest='debug',
Expand Down Expand Up @@ -252,6 +258,25 @@ def increase_indent(self, flow=False, *dargs, **dkwargs): # pylint: disable=keyw
else:
fqcndict[nonfqcn].append(fqcn)
print('%s : %s -> %s' % (modname, nonfqcn, fqcn))

if args.extrafqcnmapfile:
try:
with open(args.extrafqcnmapfile, "r", encoding="utf-8") as xfqcnf:
print('loading extra fqcn map from %s ...' % args.extrafqcnmapfile)
xfqcndict = yaml.load(xfqcnf, Loader=yaml.BaseLoader)
for nonfqcn, fqcnlist in xfqcndict.items():
if nonfqcn not in fqcndict.keys():
fqcndict[nonfqcn] = []
for fqcn in fqcnlist:
if fqcn not in fqcndict[nonfqcn]:
# this defines the precedence of the replacements made
if fqcn.startswith('ansible.'):
fqcndict[nonfqcn].insert(0, fqcn)
else:
fqcndict[nonfqcn].append(fqcn)
except (FileNotFoundError, KeyError) as fqcnmapfilerror:
print(fqcnmapfilerror)

with open(args.fqcnmapfile, "w", encoding="utf-8") as fqcnmapfile:
fqcnmapfile.write(
yaml.dump(
Expand Down

0 comments on commit a104651

Please sign in to comment.