Last active
March 27, 2021 16:06
-
-
Save m516/2c62640476c2ba27c35eb05d5c65a8ac to your computer and use it in GitHub Desktop.
Automatically rebuild drivers for SGP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import time | |
import logging | |
def import_or_install(package): | |
try: | |
__import__(package) | |
print("Package " + package + " imported successfully") | |
except ImportError: | |
print("Package " + package + " isn't installed. Attempting to install automatically...") | |
os.system("pip3 install --user "+ package) | |
try: | |
__import__(package) | |
except ImportError: | |
print("Unable to install " + package + ". Please make sure to do so manually") | |
exit(1) | |
import_or_install('dirtools2') | |
from dirtools2.dirtools2 import Dir, DirState | |
import_or_install('rich') | |
from rich import print | |
owd = os.getcwd() | |
def runCommand(command): | |
print(f"[cyan]Running: [bold]{command}[/bold][/cyan]") | |
r = os.system(command) | |
if r != 0: | |
print(f"[red]Command {command} failed; exit status {r}[/red]") | |
return r | |
def build(): | |
os.chdir(owd) | |
os.chdir('utils') | |
print('[yellow][bold]Building the driver[/bold][/yellow]') | |
r = runCommand('make -j8') | |
if r != 0: | |
return | |
os.chdir(owd) | |
os.chdir('sw') | |
print('[yellow][bold]Building the software[/bold][/yellow]') | |
runCommand('make -j8') | |
if __name__ == "__main__": | |
print(f'[green]Current working directory: [bold]{owd}[/bold][/green]') | |
runCommand('source ./setup.sh') | |
d = Dir(owd, exclude_file='.gitignore') | |
previousDirState = DirState(d) | |
print(f'[green]Waiting for file changes in [bold]{owd}[/bold][/green]') | |
try: | |
while True: | |
currentDirState = DirState(d) | |
delta = currentDirState - previousDirState | |
if delta['created'] or delta['updated'] or delta['deleted']: | |
print("\033c", end="") | |
build() | |
print(f'[green]Waiting for file changes in [bold]{owd}[/bold][/green]') | |
previousDirState = currentDirState | |
# Set the thread sleep time | |
time.sleep(5) | |
except Exception as e: | |
print(f'[red]Error! [bold]{e}[/bold][/red]') | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment