summaryrefslogtreecommitdiffstats
path: root/pimgen.py
diff options
context:
space:
mode:
Diffstat (limited to 'pimgen.py')
-rwxr-xr-xpimgen.py48
1 files changed, 35 insertions, 13 deletions
diff --git a/pimgen.py b/pimgen.py
index 0223c57..353dc15 100755
--- a/pimgen.py
+++ b/pimgen.py
@@ -468,26 +468,45 @@ class Everything(Renderer):
for e in yaml.safe_load(fd.read()).get('events', {}):
events.append(e)
+ interfaces = Everything.get_interfaces(args.ifacesdir)
+ extra_interfaces = Everything.get_interfaces(
+ os.path.join(args.inputdir, 'extra_interfaces.d'))
+
return Everything(
*events,
- interfaces=Everything.get_interfaces(args))
+ interfaces=interfaces + extra_interfaces)
@staticmethod
- def get_interfaces(args):
- '''Aggregate all the interface YAML in the interfaces.d
- directory into a single list of interfaces.'''
+ def get_interfaces(targetdir):
+ '''Scan the interfaces directory for interfaces that PIM can create.'''
+ yaml_files = []
interfaces = []
- interfaces_dir = os.path.join(args.inputdir, 'interfaces.d')
- if os.path.exists(interfaces_dir):
- yaml_files = filter(
- lambda x: x.endswith('.yaml'),
- os.listdir(interfaces_dir))
- for x in yaml_files:
- with open(os.path.join(interfaces_dir, x), 'r') as fd:
- for i in yaml.safe_load(fd.read()):
- interfaces.append(i)
+ if targetdir and os.path.exists(targetdir):
+ for directory, _, files in os.walk(targetdir):
+ if not files:
+ continue
+
+ yaml_files += map(
+ lambda f: os.path.relpath(
+ os.path.join(directory, f),
+ targetdir),
+ filter(lambda f: f.endswith('.interface.yaml'), files))
+
+ for y in yaml_files:
+ with open(os.path.join(targetdir, y)) as fd:
+ i = y.replace('.interface.yaml', '').replace(os.sep, '.')
+
+ # PIM can't create interfaces with methods.
+ # PIM can't create interfaces without properties.
+ parsed = yaml.safe_load(fd.read())
+ if parsed.get('methods', None):
+ continue
+ if not parsed.get('properties', None):
+ continue
+
+ interfaces.append(i)
return interfaces
@@ -525,6 +544,9 @@ if __name__ == '__main__':
'-o', '--output-dir', dest='outputdir',
default='.', help='Output directory.')
parser.add_argument(
+ '-i', '--interfaces-dir', dest='ifacesdir',
+ help='Location of interfaces to be supported.')
+ parser.add_argument(
'-d', '--dir', dest='inputdir',
default=os.path.join(script_dir, 'example'),
help='Location of files to process.')
OpenPOWER on IntegriCloud