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