-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmanage.py
More file actions
37 lines (31 loc) · 945 Bytes
/
manage.py
File metadata and controls
37 lines (31 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import typer, subprocess, sys, time, os
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
app = typer.Typer()
class RH(FileSystemEventHandler):
def __init__(self, s):
self.s = s
self.p = None
self.st()
def st(self):
if self.p: self.p.kill()
self.p = subprocess.Popen([sys.executable, '-m', self.s], env=os.environ.copy())
def on_modified(self, e):
if e.src_path.endswith('.py'):
print(f'Reloading...')
self.st()
@app.command()
def run(r: bool = typer.Option(False, "--reload")):
if r:
o = Observer()
o.schedule(RH('Bot'), 'Bot', recursive=True)
o.start()
try:
while True: time.sleep(1)
except KeyboardInterrupt: o.stop()
o.join()
else:
import runpy
runpy.run_module("Bot", run_name="__main__")
if __name__ == "__main__":
app()