Skip to content
Snippets Groups Projects
Select Git revision
  • 24be7ca2cd2ef1f7dc3b97bdf6f0c0143d773cf8
  • master default protected
  • backslash
  • nickname-match-configs
  • genofire/leds_rgb_get_state
  • genofire/rockets-state
  • genofire/ble-follow-py
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • genofire/haule-ble-fs-deactive
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • ios-workarounds
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
34 results

display.py

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    gen-modules.py 1.47 KiB
    #!/usr/bin/env python3
    # Usage: gen-modules.py <source path> <output.h> <input.c ...>
    
    import sys
    import os
    import tempfile
    import shutil
    
    
    def main():
        # Get 'official' makemoduledefs.py
        path = sys.argv[1] + "/micropython/py"
        sys.path.insert(0, path)
        import makemoduledefs
    
        modules = set()
        for source in sys.argv[3:]:
            modules |= makemoduledefs.find_module_registrations(source)
    
        stdout = sys.stdout
        with tempfile.TemporaryFile("w+") as temp:
            sys.stdout = temp
            makemoduledefs.generate_module_table_header(sorted(modules))
            sys.stdout = stdout
    
            # Read contents of existing file and compare
            try:
                with open(sys.argv[2], "r") as f:
                    old_content = f.read()
            except FileNotFoundError:
                old_content = ""
    
            temp.seek(0)
            new_content = temp.read()
    
            if new_content == old_content:
                # If both file contain the same content, exit early
                sys.exit(0)
    
            with open(sys.argv[2], "w") as f:
                f.write(new_content)
    
            try:
                os.mkdir(os.path.dirname(sys.argv[2]) + "/genhdr")
            except FileExistsError:
                pass
    
            linkname = (
                os.path.dirname(sys.argv[2]) + "/genhdr/" + os.path.basename(sys.argv[2])
            )
            if os.path.exists(linkname):
                os.unlink(linkname)
            shutil.copy(sys.argv[2], linkname)
    
        sys.stdout = stdout
    
    
    if __name__ == "__main__":
        main()