Phillip J. Eby | 069159b | 2006-04-18 04:05:34 +0000 | [diff] [blame] | 1 | import distutils, os |
| 2 | from setuptools import Command |
| 3 | from setuptools.command.setopt import edit_config, option_base |
| 4 | |
| 5 | class saveopts(option_base): |
| 6 | """Save command-line options to a file""" |
| 7 | |
| 8 | description = "save supplied options to setup.cfg or other config file" |
| 9 | |
| 10 | def run(self): |
| 11 | dist = self.distribution |
| 12 | commands = dist.command_options.keys() |
| 13 | settings = {} |
| 14 | |
| 15 | for cmd in commands: |
| 16 | |
| 17 | if cmd=='saveopts': |
| 18 | continue # don't save our own options! |
| 19 | |
| 20 | for opt,(src,val) in dist.get_option_dict(cmd).items(): |
| 21 | if src=="command line": |
| 22 | settings.setdefault(cmd,{})[opt] = val |
| 23 | |
| 24 | edit_config(self.filename, settings, self.dry_run) |