forked from shlomimatichin/Pymake3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfswatcher.py
54 lines (43 loc) · 1.6 KB
/
fswatcher.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
"""
Template make script for watching files for changes. Provides the 'watch' target
that continuously watches a list of files for changes. When one of the watched
files has been changed, a target spceified in the configuration will be made.
"""
#---------------------------------------
# IMPORTS
#---------------------------------------
from pymake3 import *
#---------------------------------------
# GLOBALS
#---------------------------------------
# Default configuration.
conf = makeconf.from_dict({ 'fswatcher': {
'extensions' : [ '*.*' ],
'interval' : 0.5,
'path' : 'src',
'target' : 'compile'
} })
#---------------------------------------
# FUNCTIONS
#---------------------------------------
def on_files_changed(conf, filenames):
"""
This function is called after watched files have been changed. It makes the
target specified in the fswatcher configuration.
:param conf: Make configuration.
:param filenames: Names of the files that have changed.
"""
if not filenames:
return True
make(conf.fswatcher.target, conf)
return True
@target(conf=conf)
def watch(conf):
"""
Watches files in a directory for changes, making a specified target when a
change has been detected in any of the files.
"""
filenames = []
for ext in conf.fswatcher.extensions:
filenames += find_files(conf.fswatcher.path, ext)
watch_files(filenames, on_files_changed, conf, conf.fswatcher.interval)