-
Notifications
You must be signed in to change notification settings - Fork 23
/
shaderwatch.py
executable file
·85 lines (56 loc) · 1.69 KB
/
shaderwatch.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""Instant GLSL.
Usage:
shaderwatch.py watch <file>
Options:
"""
from docopt import docopt
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import time
import subprocess
import os
file_path = ""
file_dir = ""
push_dir = "/sdcard"
def sh(command):
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print(p.stdout.read())
def push_shader():
command = "adb push " + file_path + " " + push_dir
sh(command)
def send_broadcast():
command = "adb shell am broadcast " \
+ "-a com.glumes.instant.image.shader " \
+ "--es shaderPath " \
+ os.path.basename(file_path)
print(command)
sh(command)
class ShaderHandler(FileSystemEventHandler):
create_path = ""
modified_path = ""
def on_modified(self, event):
self.modified_path = event.src_path
if self.modified_path == file_path or self.create_path == file_path:
push_shader()
send_broadcast()
def on_created(self, event):
self.create_path = event.src_path
if __name__ == '__main__':
arguments = docopt(__doc__, version='Instant GLSL 2.0')
file_path = os.path.abspath(arguments['<file>'])
file_dir = os.path.dirname(file_path) + "/"
print(file_path)
print(file_dir)
event_handler = ShaderHandler()
observer = Observer()
observer.schedule(event_handler, file_dir, recursive=True)
observer.start()
print("start watch!!!")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
print("\nstop watch~~~")