Mercurial > code > home > repos > light9
annotate bin/run_local.py @ 1836:0dd0b5e282b4
qsweepusa effects
Ignore-this: 651c0975777e428f35047a68083aad94
author | drewp@bigasterisk.com |
---|---|
date | Sat, 09 Jun 2018 22:40:39 +0000 |
parents | 5c04a54df635 |
children | 7772cc48e016 |
rev | line source |
---|---|
209
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff
changeset
|
1 # allows bin/* to work without installation |
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff
changeset
|
2 |
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff
changeset
|
3 # this should be turned off when the programs are installed |
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff
changeset
|
4 |
1156
f66586649ae3
show more process info in terminal title
drewp@bigasterisk.com
parents:
1155
diff
changeset
|
5 import sys, os, socket |
1697
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
6 |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
7 def fixSysPath(): |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
8 root = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..')) + '/' |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
9 |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
10 # this is site-packages/zope.interface-4.5.0-py2.7-nspkg.pth, |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
11 # slightly edited. |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
12 import types |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
13 has_mfs = sys.version_info > (3, 5); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
14 p = root + 'env/local/lib/python2.7/site-packages/zope' |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
15 importlib = has_mfs and __import__('importlib.util'); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
16 has_mfs and __import__('importlib.machinery'); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
17 m = has_mfs and sys.modules.setdefault( |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
18 'zope', importlib.util.module_from_spec( |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
19 importlib.machinery.PathFinder.find_spec( |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
20 'zope', [os.path.dirname(p)]))); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
21 m = m or sys.modules.setdefault('zope', types.ModuleType('zope')); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
22 mp = (m or []) and m.__dict__.setdefault('__path__',[]); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
23 (p not in mp) and mp.append(p) |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
24 |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
25 p = root + 'env/local/lib/python2.7/site-packages/greplin' |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
26 importlib = has_mfs and __import__('importlib.util'); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
27 has_mfs and __import__('importlib.machinery'); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
28 m = has_mfs and sys.modules.setdefault('greplin', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('greplin', [os.path.dirname(p)]))); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
29 m = m or sys.modules.setdefault('greplin', types.ModuleType('greplin')); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
30 mp = (m or []) and m.__dict__.setdefault('__path__',[]); |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
31 (p not in mp) and mp.append(p) |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
32 |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
33 sys.path = [ |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
34 root, |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
35 root + 'env/lib/python2.7', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
36 root + 'env/lib/python2.7/plat-x86_64-linux-gnu', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
37 root + 'env/lib/python2.7/lib-tk', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
38 root + 'env/lib/python2.7/lib-old', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
39 root + 'env/lib/python2.7/lib-dynload', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
40 '/usr/lib/python2.7', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
41 '/usr/lib/python2.7/plat-x86_64-linux-gnu', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
42 '/usr/lib/python2.7/lib-tk', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
43 root + 'env/local/lib/python2.7/site-packages', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
44 root + 'env/local/lib/python2.7/site-packages/gtk-2.0', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
45 root + 'env/lib/python2.7/site-packages', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
46 root + 'env/lib/python2.7/site-packages/gtk-2.0', |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
47 ] |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
48 |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1512
diff
changeset
|
49 fixSysPath() |
209
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff
changeset
|
50 |
306
41830567a8d0
bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents:
209
diff
changeset
|
51 from twisted.python.failure import Failure |
209
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff
changeset
|
52 |
1239 | 53 try: |
54 import Tkinter | |
55 except ImportError: | |
56 pass | |
57 else: | |
58 def rce(self, exc, val, tb): | |
59 sys.stderr.write("Exception in Tkinter callback\n") | |
60 if True: | |
61 sys.excepthook(exc, val, tb) | |
62 else: | |
63 Failure(val, exc, tb).printDetailedTraceback() | |
64 Tkinter.Tk.report_callback_exception = rce | |
306
41830567a8d0
bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents:
209
diff
changeset
|
65 |
1087
1f877950ad28
new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents:
1072
diff
changeset
|
66 import coloredlogs, logging, time |
1f877950ad28
new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents:
1072
diff
changeset
|
67 try: |
1f877950ad28
new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents:
1072
diff
changeset
|
68 import faulthandler |
1f877950ad28
new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents:
1072
diff
changeset
|
69 faulthandler.enable() |
1f877950ad28
new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents:
1072
diff
changeset
|
70 except ImportError: |
1f877950ad28
new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents:
1072
diff
changeset
|
71 pass |
1210
8e8d778f9e21
use program name instead of 'root' for logger channel, so it's faster to see what a terminal is running
Drew Perttula <drewp@bigasterisk.com>
parents:
1156
diff
changeset
|
72 |
8e8d778f9e21
use program name instead of 'root' for logger channel, so it's faster to see what a terminal is running
Drew Perttula <drewp@bigasterisk.com>
parents:
1156
diff
changeset
|
73 progName = sys.argv[0].split('/')[-1] |
1221
3c78608a216a
don't break all non-root log channels
Drew Perttula <drewp@bigasterisk.com>
parents:
1215
diff
changeset
|
74 log = logging.getLogger() # this has to get the root logger |
3c78608a216a
don't break all non-root log channels
Drew Perttula <drewp@bigasterisk.com>
parents:
1215
diff
changeset
|
75 log.name = progName # but we can rename it for clarity |
3c78608a216a
don't break all non-root log channels
Drew Perttula <drewp@bigasterisk.com>
parents:
1215
diff
changeset
|
76 |
1512 | 77 class FractionTimeFilter(logging.Filter): |
78 def filter(self, record): | |
79 record.fractionTime = ( | |
80 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(record.created)) + | |
81 ("%.3f" % (record.created % 1)).lstrip('0')) | |
82 # Don't filter the record. | |
83 return 1 | |
858
1f93e5d19f8a
merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents:
837
diff
changeset
|
84 |
1512 | 85 coloredlogs.install( |
86 level='DEBUG', | |
87 fmt='%(fractionTime)s %(name)s[%(process)d] %(levelname)s %(message)s') | |
88 logging.getLogger().handlers[0].addFilter(FractionTimeFilter()) | |
858
1f93e5d19f8a
merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents:
837
diff
changeset
|
89 |
1f93e5d19f8a
merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents:
837
diff
changeset
|
90 |
933 | 91 def setTerminalTitle(s): |
1425 | 92 if os.environ.get('TERM', '') in ['xterm', 'rxvt', 'rxvt-unicode-256color']: |
933 | 93 print "\033]0;%s\007" % s # not escaped/protected correctly |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
873
diff
changeset
|
94 |
1215 | 95 if 'listsongs' not in sys.argv[0] and 'homepageConfig' not in sys.argv[0]: |
1425 | 96 setTerminalTitle('[%s] %s' % (socket.gethostname(), ' '.join(sys.argv).replace('bin/', ''))) |
934 | 97 |
98 # see http://www.youtube.com/watch?v=3cIOT9kM--g for commands that make | |
99 # profiles and set background images |