guruguru.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. import asyncio
  3. import os
  4. from flipper.app import App
  5. class Main(App):
  6. def init(self):
  7. self.parser.add_argument("watch_list", nargs="+", help="Directories to watch")
  8. self.is_building = False
  9. def clearConsole(self):
  10. os.system("cls" if os.name in ("nt", "dos") else "clear")
  11. async def rebuild(self, line):
  12. self.clearConsole()
  13. self.logger.info(f"Triggered by: {line}")
  14. proc = await asyncio.create_subprocess_exec("make")
  15. await proc.wait()
  16. await asyncio.sleep(1)
  17. self.is_building = False
  18. async def run(self):
  19. proc = await asyncio.create_subprocess_exec(
  20. "fswatch", *self.args.watch_list, stdout=asyncio.subprocess.PIPE
  21. )
  22. while True:
  23. data = await proc.stdout.readline()
  24. line = data.decode().strip()
  25. if not self.is_building:
  26. self.is_building = True
  27. asyncio.create_task(self.rebuild(line))
  28. def call(self):
  29. try:
  30. asyncio.run(self.run())
  31. except KeyboardInterrupt:
  32. pass
  33. return 0
  34. if __name__ == "__main__":
  35. Main()()