Skip to content

Commit d58ca98

Browse files
committed
initial source code commit for python advanced course
1 parent 105b3ea commit d58ca98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+8016
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
index.html

autocompile.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python
2+
#
3+
# Usage:
4+
# ./autocompile.py path ext1,ext2,extn cmd
5+
#
6+
# Blocks monitoring |path| and its subdirectories for modifications on
7+
# files ending with suffix |extk|. Run |cmd| each time a modification
8+
# is detected. |cmd| is optional and defaults to 'make'.
9+
#
10+
# Example:
11+
# ./autocompile.py /my-latex-document-dir .tex,.bib "make pdf"
12+
#
13+
# Dependancies:
14+
# Linux, Python 2.6, Pyinotify
15+
#
16+
import subprocess
17+
import sys
18+
import pyinotify
19+
20+
class OnWriteHandler(pyinotify.ProcessEvent):
21+
def __init__(self, cwd, extension, cmd):
22+
self.cwd = cwd
23+
self.extensions = extension.split(',')
24+
self.cmd = cmd
25+
26+
def _run_cmd(self):
27+
print '==> Modification detected'
28+
subprocess.call(self.cmd.split(' '), cwd=self.cwd)
29+
30+
def _do_notify(self):
31+
subprocess.call(["notify-send", "doc updated"], cwd=self.cwd)
32+
33+
def process_default(self, event): pass
34+
35+
def process_IN_MODIFY(self, event):
36+
if all(not event.name.endswith(ext) for ext in self.extensions):
37+
return
38+
self._run_cmd()
39+
fname = event.name
40+
cmd = self.cmd
41+
self._do_notify()
42+
print '==> detected change in "%s", ran "%s" -- done!' % (fname, cmd)
43+
44+
def auto_compile(path, extension, cmd):
45+
wm = pyinotify.WatchManager()
46+
handler = OnWriteHandler(cwd=path, extension=extension, cmd=cmd)
47+
notifier = pyinotify.Notifier(wm, default_proc_fun=handler)
48+
wm.add_watch(path, 4095, rec=True, auto_add=True)
49+
50+
print '==> Started monitoring "%s" for changes (type ^C to exit)' % path
51+
while True:
52+
try:
53+
if notifier.check_events():
54+
notifier.read_events()
55+
notifier.process_events()
56+
except KeyboardInterrupt:
57+
notifier.stop()
58+
break
59+
print '==> Stopped monitoring'
60+
61+
if __name__ == '__main__':
62+
if len(sys.argv) < 3:
63+
print >> sys.stderr, "Command line error: missing argument(s)."
64+
sys.exit(1)
65+
66+
# Required arguments
67+
path = sys.argv[1]
68+
extension = sys.argv[2]
69+
70+
# Optional argument
71+
cmd = 'make'
72+
if len(sys.argv) == 4:
73+
cmd = sys.argv[3]
74+
75+
# Blocks monitoring
76+
auto_compile(path, extension, cmd)

build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
NAME=index
2+
python rst-directive.py \
3+
--stylesheet=pygments.css \
4+
--theme-url=ui/small-black \
5+
${NAME}.rst > ${NAME}.html

img/01_prog.png

31.4 KB
Loading

img/02_ide.png

157 KB
Loading

img/03_flow.png

16.9 KB
Loading

img/04_import.png

28.9 KB
Loading

img/05_methodchain.png

16.8 KB
Loading

img/06_devcurve.png

12.8 KB
Loading

img/07_lists.png

16.3 KB
Loading

img/08_listalter.png

44.1 KB
Loading

img/09_listconcat.png

18.4 KB
Loading

img/10_listslice.png

29.8 KB
Loading

img/11_listalias.png

22.1 KB
Loading

img/12_listnest.png

25.3 KB
Loading

img/13_truthtable.png

19.1 KB
Loading

img/15_debugger.png

297 KB
Loading

img/16_callstack.png

24.6 KB
Loading

img/17_sets.png

27.4 KB
Loading

img/18_dicts.png

22.4 KB
Loading

img/19_exhandling.png

22.7 KB
Loading

img/20_exheirarchy.png

18.7 KB
Loading

img/21_oo.png

30.8 KB
Loading

img/23_python.png

17.8 KB
Loading

img/24_slicing.png

2.07 KB
Loading

img/Thumbs.db

15 KB
Binary file not shown.

img/babyturtles.png

197 KB
Loading

img/magicturtle.jpg

34.5 KB
Loading

0 commit comments

Comments
 (0)