Brad Bishop | d202bfd | 2016-10-31 09:51:55 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | import yaml |
| 6 | import subprocess |
| 7 | |
| 8 | |
| 9 | class SDBUSPlus(object): |
| 10 | def __init__(self, path): |
| 11 | self.path = path |
| 12 | |
| 13 | def __call__(self, *a, **kw): |
| 14 | args = [ |
| 15 | os.path.join(self.path, 'sdbus++'), |
| 16 | '-t', |
| 17 | os.path.join(self.path, 'templates') |
| 18 | ] |
| 19 | |
| 20 | subprocess.call(args + list(a), **kw) |
| 21 | |
| 22 | |
| 23 | if __name__ == '__main__': |
| 24 | sdbusplus = None |
| 25 | for p in os.environ.get('PATH', "").split(os.pathsep): |
| 26 | if os.path.exists(os.path.join(p, 'sdbus++')): |
| 27 | sdbusplus = SDBUSPlus(p) |
| 28 | break |
| 29 | |
| 30 | if sdbusplus is None: |
| 31 | sys.stderr.write('Cannot find sdbus++\n') |
| 32 | sys.exit(1) |
| 33 | |
| 34 | genfiles = { |
| 35 | 'server-cpp': lambda x: '%s.cpp' % x, |
| 36 | 'server-header': lambda x: os.path.join( |
| 37 | os.path.join(*x.split('.')), 'server.hpp') |
| 38 | } |
| 39 | with open(os.path.join('example', 'interfaces.yaml'), 'r') as fd: |
| 40 | interfaces = yaml.load(fd.read()) |
| 41 | |
| 42 | for i in interfaces: |
| 43 | for process, f in genfiles.iteritems(): |
| 44 | |
| 45 | dest = f(i) |
| 46 | parent = os.path.dirname(dest) |
| 47 | if parent and not os.path.exists(parent): |
| 48 | os.makedirs(parent) |
| 49 | |
| 50 | with open(dest, 'w') as fd: |
| 51 | sdbusplus( |
| 52 | '-r', |
| 53 | os.path.join('example', 'interfaces'), |
| 54 | 'interface', |
| 55 | process, |
| 56 | i, |
| 57 | stdout=fd) |
| 58 | |
| 59 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |