-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch
More file actions
executable file
·96 lines (70 loc) · 2.41 KB
/
watch
File metadata and controls
executable file
·96 lines (70 loc) · 2.41 KB
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
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
import os
import sys
import time
import subprocess
import pyinotify
package_name = 'leaflet'
javascript_directory = os.path.join(package_name, 'static/js/')
css_directory = os.path.join(package_name, 'static/css/')
coffee_cmd = ['coffee', '-wc', '-o', javascript_directory, 'coffee/']
compass_cmd = ['compass', 'watch']
coffee_proc = subprocess.Popen(coffee_cmd)
compass_proc = subprocess.Popen(compass_cmd)
wm = pyinotify.WatchManager()
# when a process completes writing a file
mask = pyinotify.IN_CLOSE_WRITE
# take a filename and create a minimized filename
def make_new_filename(basename):
if basename.endswith('.js'):
marker = '.js'
elif basename.endswith('.css'):
marker = '.css'
prefix = basename[:-len(marker)]
suffix = '.min%s' % marker
return prefix + suffix
def minimize_file(pathname):
dirname, basename = os.path.split(pathname)
newname = make_new_filename(basename)
newpath = os.path.join(dirname, newname)
cmd = ['yui-compressor', '-o', newpath, pathname]
subprocess.check_call(cmd)
def event_handler(event):
print "Finished writing", event.pathname
dirname, basename = os.path.split(event.pathname)
# check to see if these are the newly created minimized
# files, and if so, ignore them
if basename.endswith('.min.js') or basename.endswith('.min.css'):
print "Ignoring minimized file", basename
# otherwize, minimize the file
else:
print "Minimizing", basename
minimize_file(event.pathname)
print "Finished Minimization"
def notifier_callback(notifier):
try:
print notifier.read_events()
except pyinotify.NotifierError:
print "NotifierError"
wm.add_watch(javascript_directory, mask)
wm.add_watch(css_directory, mask)
notifier = pyinotify.Notifier(wm, event_handler)
#while not (coffee_proc.poll() or compass_proc.poll()):
#notifier.loop(daemonize=True, callback=notifier_callback)
#notifier.loop(callback=notifier_callback)
#time.sleep(5)
#notifier.loop()
notifier.loop()
# check which one stopped
coffee_ret = coffee_proc.returncode
compass_ret = compass_proc.returncode
if coffee_ret is None:
print "Stopping coffee"
coffee_proc.terminate()
else:
print "coffee returned", coffee_ret
if compass_ret is None:
print "Stopping compass"
compass_proc.terminate()
else:
print "compass returned", compass_ret