| Total Complexity | 5 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from distutils.core import Command |
||
| 7 | class BuildDbusService(Command): |
||
| 8 | """ |
||
| 9 | Add a ``build_dbus`` command to your setup.py. |
||
| 10 | To use this Command class add a command to call this class:: |
||
| 11 | |||
| 12 | # For setuptools |
||
| 13 | setup( |
||
| 14 | entry_points={ |
||
| 15 | "distutils.commands": [ |
||
| 16 | "build_dbus = " |
||
| 17 | "coalib.misc.BuildDbusService:BuildDbusService" |
||
| 18 | ] |
||
| 19 | } |
||
| 20 | ) |
||
| 21 | |||
| 22 | # For distutils |
||
| 23 | from coalib.misc.BuildDbusService import BuildDbusService |
||
| 24 | setup( |
||
| 25 | cmdclass={'build_dbus': BuildDbusService} |
||
| 26 | ) |
||
| 27 | |||
| 28 | You can then use the following setup command to produce a dbus service:: |
||
| 29 | |||
| 30 | $ python setup.py build_dbus |
||
| 31 | """ |
||
| 32 | user_options = [('output=', 'O', 'output file')] |
||
| 33 | |||
| 34 | def initialize_options(self): |
||
| 35 | self.output = None |
||
| 36 | |||
| 37 | def finalize_options(self): |
||
| 38 | if self.output is None: |
||
| 39 | raise DistutilsOptionError('\'output\' option is required') |
||
| 40 | self.announce('Writing dbus service %s' % self.output) |
||
| 41 | |||
| 42 | def run(self): |
||
| 43 | dist = self.distribution |
||
| 44 | dbus_service = ("[D-BUS Service]\n" |
||
| 45 | "Names=" + BUS_NAME + "\n" |
||
| 46 | "Exec=coala-dbus") |
||
| 47 | |||
| 48 | with open(self.output, 'w') as f: |
||
| 49 | f.write(dbus_service) |
||
| 50 |