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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
7
1697
5c04a54df635 fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents: 1512
diff changeset
8 def fixSysPath():
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
9 root = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
17 importlib = has_mfs and __import__('importlib.util')
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
20 'zope',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
21 importlib.util.module_from_spec(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
22 importlib.machinery.PathFinder.find_spec('zope',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
23 [os.path.dirname(p)])))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
24 m = m or sys.modules.setdefault('zope', types.ModuleType('zope'))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
29 importlib = has_mfs and __import__('importlib.util')
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
30 has_mfs and __import__('importlib.machinery')
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
31 m = has_mfs and sys.modules.setdefault(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
32 'greplin',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
33 importlib.util.module_from_spec(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
34 importlib.machinery.PathFinder.find_spec('greplin',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
35 [os.path.dirname(p)])))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
36 m = m or sys.modules.setdefault('greplin', types.ModuleType('greplin'))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
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
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
61 try:
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
62 import Tkinter
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
63 except ImportError:
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
64 pass
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
65 else:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
66
1239
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
67 def rce(self, exc, val, tb):
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
68 sys.stderr.write("Exception in Tkinter callback\n")
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
69 if True:
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
70 sys.excepthook(exc, val, tb)
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
71 else:
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
72 Failure(val, exc, tb).printDetailedTraceback()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
73
1239
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
84 log = logging.getLogger() # this has to get the root logger
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
85 log.name = progName # but we can rename it for clarity
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
86
1221
3c78608a216a don't break all non-root log channels
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
87
1512
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
88 class FractionTimeFilter(logging.Filter):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
89
1512
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
90 def filter(self, record):
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
91 record.fractionTime = (
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
92 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(record.created)) +
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
93 ("%.3f" % (record.created % 1)).lstrip('0'))
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
94 # Don't filter the record.
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
95 return 1
858
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
96
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
97
1512
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
98 coloredlogs.install(
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
99 level='DEBUG',
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
100 fmt='%(fractionTime)s %(name)s[%(process)d] %(levelname)s %(message)s')
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
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
8435e3ee1ec2 put program name in terminal title
drewp@bigasterisk.com
parents: 874
diff changeset
104 def setTerminalTitle(s):
1425
8796803a1b45 show prog name in my i3 terminals
drewp@bigasterisk.com
parents: 1239
diff changeset
105 if os.environ.get('TERM', '') in ['xterm', 'rxvt', 'rxvt-unicode-256color']:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
106 print "\033]0;%s\007" % s # not escaped/protected correctly
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
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
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents: 1210
diff changeset
109 if 'listsongs' not in sys.argv[0] and 'homepageConfig' not in sys.argv[0]:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
110 setTerminalTitle(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
111 '[%s] %s' %
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
112 (socket.gethostname(), ' '.join(sys.argv).replace('bin/', '')))
934
f92550d33004 comment
drewp@bigasterisk.com
parents: 933
diff changeset
113
f92550d33004 comment
drewp@bigasterisk.com
parents: 933
diff changeset
114 # see http://www.youtube.com/watch?v=3cIOT9kM--g for commands that make
f92550d33004 comment
drewp@bigasterisk.com
parents: 933
diff changeset
115 # profiles and set background images