author | Radek Brich <radek.brich@devl.cz> |
Sun, 22 Feb 2015 09:53:13 +0100 | |
changeset 119 | dd91747504dd |
parent 117 | 8680c2333546 |
permissions | -rwxr-xr-x |
117
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python3 |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
from demos.base import setup |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
import sys |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
import os |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
import re |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
def list_demos(): |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
return sorted(fname for fname in os.listdir('demos') |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
if re.match(r'[0-9]+_.*\.py', fname)) |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
13 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
def print_usage(names): |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
print("Usage: %s <name>\n" % sys.argv[0]) |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
print("Where <name> is one of (or part of):") |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
print('\n'.join([' '+name for name in names])) |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
if __name__ == '__main__': |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
setup() |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
names = list_demos() |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
24 |
if len(sys.argv) != 2: |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
25 |
print_usage(names) |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
26 |
sys.exit(0) |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
arg = sys.argv[1] |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
name = None |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
30 |
for name in names: |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
31 |
if arg in name: |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
break |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
33 |
else: |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
print("Demo '%s' not found." % arg) |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
35 |
sys.exit(1) |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
|
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
print("Executing %s..." % name) |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
38 |
with open('demos/' + name, 'r') as f: |
8680c2333546
Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
exec(f.read()) |