forked from sightmachine/SimpleCV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.py
More file actions
62 lines (50 loc) · 1.59 KB
/
Example.py
File metadata and controls
62 lines (50 loc) · 1.59 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
#!/usr/bin/python
import os
import glob
from subprocess import call
from SimpleCV import *
import sys
def listFiles(directory):
for path, dirs, files in os.walk(directory):
for f in files:
yield os.path.join(path, f)
def magic_examples(self, arg):
DIR = os.path.join(LAUNCH_PATH, 'examples')
files = [f for f in listFiles(DIR) if f.endswith('.py')]
file_names = [file.split('/')[-1] for file in files]
iarg = None
arg = str(arg)
try:
iarg = int(arg)
except:
pass
if isinstance(arg, str) and arg == "":
counter = 0
print "Available Examples:"
print "--------------------------------------------"
for file in file_names:
print "[",counter,"]:",file
counter += 1
print "Just type example #, to run the example on the list"
print "for instance: example 1"
print ""
print "Close the window or press ctrl+c to stop the example"
elif isinstance(iarg, int):
print "running example:", files[iarg]
try:
call([sys.executable, files[iarg]])
except:
print "Couldn't run example:", files[iarg]
elif isinstance(arg, str) and arg.lower() == "joshua":
print "GREETINGS PROFESSOR FALKEN"
print ""
print "HELLO"
print ""
print "A STRANGE GAME."
print "THE ONLY WINNING MOVE IS"
print "NOT TO PLAY."
print ""
print "HOW ABOUT A NICE GAME OF CHESS?"
print ""
else:
print "Example: " + arg + " does not exist, or an error occurred"