diff options
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | example/interfaces.d/example.yaml | 5 | ||||
-rwxr-xr-x | pimgen.py | 48 |
4 files changed, 43 insertions, 19 deletions
diff --git a/Makefile.am b/Makefile.am index 1697e2b..1243e21 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,8 +26,12 @@ libmanager_la_LIBADD = libmanagercommon.la $(SDBUSPLUS_LIBS) clean-local: clean-extra +if IFACES_PATH +PIMGEN_ARGS=-i $(IFACES_PATH) +endif + generated.cpp: - $(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py -d $(extra_yamldir)/.. -o $(builddir) generate-cpp + $(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py $(PIMGEN_ARGS) -d $(extra_yamldir)/.. -o $(builddir) generate-cpp SUBDIRS = . test diff --git a/configure.ac b/configure.ac index 526770c..83d063e 100644 --- a/configure.ac +++ b/configure.ac @@ -66,10 +66,13 @@ AC_ARG_VAR(BUSNAME, [The DBus busname to own.]) AC_ARG_VAR(INVENTORY_ROOT, [The DBus inventory namespace root.]) AC_ARG_VAR(IFACE, [The manager DBus interface.]) AC_ARG_VAR(YAML_PATH, [The path to the yaml config files.]) +AC_ARG_VAR(IFACES_PATH, [The path to the interfaces PIM can create.]) AS_IF([test "x$BUSNAME" == "x"], [BUSNAME="xyz.openbmc_project.Inventory.Manager"]) AS_IF([test "x$INVENTORY_ROOT" == "x"], [INVENTORY_ROOT="/xyz/openbmc_project/Inventory"]) AS_IF([test "x$IFACE" == "x"], [IFACE="xyz.openbmc_project.Inventory.Manager"]) AS_IF([test "x$YAML_PATH" == "x"], [YAML_PATH="$srcdir/example"]) +AM_CONDITIONAL(IFACES_PATH, [test x"$IFACES_PATH" != "x"]) + AC_DEFINE_UNQUOTED([BUSNAME], ["$BUSNAME"], [The DBus busname to own.]) AC_DEFINE_UNQUOTED([INVENTORY_ROOT], ["$INVENTORY_ROOT"], [The DBus inventory namespace root.]) AC_DEFINE_UNQUOTED([IFACE], ["$IFACE"], [The manager DBus interface.]) diff --git a/example/interfaces.d/example.yaml b/example/interfaces.d/example.yaml deleted file mode 100644 index d5d3329..0000000 --- a/example/interfaces.d/example.yaml +++ /dev/null @@ -1,5 +0,0 @@ -# An interface file defines which interfaces -# will be processed by the Notify method. - -- xyz.openbmc_project.Example.Iface1 -- xyz.openbmc_project.Example.Iface2 @@ -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.') |