| #!/usr/bin/python |
| # -*- coding: utf-8 -*- |
| |
| from __future__ import with_statement |
| |
| import sys |
| import FSEvents |
| try: |
| import cStringIo as StringIO |
| except ImportError: |
| import StringIO |
| |
| |
| header = """# -*- coding: utf-8 -*- |
| # File generated by watchdog/scripts/dump_mac_constants.py |
| |
| class Constants(object): |
| """ |
| |
| def dump_constants(header): |
| output = StringIO.StringIO() |
| output.write(header) |
| |
| for attribute in dir(FSEvents): |
| value = getattr(FSEvents, attribute) |
| if attribute.startswith('k') and isinstance(value, int): |
| output.write(" %s = %s\n" % (attribute, hex(value))) |
| content = output.getvalue() |
| output.close() |
| return content |
| |
| def write_constants_to_file(filename): |
| content = dump_constants(header) |
| with open(filename, 'wb') as f: |
| f.write(content) |
| |
| if __name__ == "__main__": |
| if len(sys.argv) > 1: |
| output_file = sys.argv[1] |
| else: |
| print("Usage: scripts/dump_mac_constants.py <output_file>") |
| sys.exit(1) |
| |
| write_constants_to_file(output_file) |