annotate bin/run_local.py @ 2030:aeafe7d0b033

have bin/* run via pdm's python config
author drewp@bigasterisk.com
date Thu, 07 Apr 2022 01:07:54 -0700
parents 7088d60fde7e
children 53dd7eb024c9
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
2030
aeafe7d0b033 have bin/* run via pdm's python config
drewp@bigasterisk.com
parents: 1952
diff changeset
7 from twisted.python.failure import Failure
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
8
2030
aeafe7d0b033 have bin/* run via pdm's python config
drewp@bigasterisk.com
parents: 1952
diff changeset
9 # to support 'import light9' until I rearrange things better:
aeafe7d0b033 have bin/* run via pdm's python config
drewp@bigasterisk.com
parents: 1952
diff changeset
10 sys.path.append('.')
209
1a84c5e83d3e dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff changeset
11
1239
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
12 try:
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
13 import tkinter
1239
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
14 except ImportError:
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
15 pass
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
16 else:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
17
1239
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
18 def rce(self, exc, val, tb):
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
19 sys.stderr.write("Exception in Tkinter callback\n")
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
20 if True:
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
21 sys.excepthook(exc, val, tb)
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
22 else:
0025b04a1c0a tkinter not required
drewp@bigasterisk.com
parents: 1221
diff changeset
23 Failure(val, exc, tb).printDetailedTraceback()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
24
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
25 tkinter.Tk.report_callback_exception = rce
306
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
26
1087
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
27 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
28 try:
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
29 import faulthandler
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
30 faulthandler.enable()
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
31 except ImportError:
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
32 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
33
1952
7088d60fde7e leave cool ipython exc handler in run_local.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1865
diff changeset
34 if 0:
7088d60fde7e leave cool ipython exc handler in run_local.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1865
diff changeset
35 from IPython.core import ultratb
7088d60fde7e leave cool ipython exc handler in run_local.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1865
diff changeset
36 sys.excepthook = ultratb.FormattedTB(mode='Verbose',
7088d60fde7e leave cool ipython exc handler in run_local.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1865
diff changeset
37 color_scheme='Linux',
7088d60fde7e leave cool ipython exc handler in run_local.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1865
diff changeset
38 call_pdb=1)
7088d60fde7e leave cool ipython exc handler in run_local.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1865
diff changeset
39
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
40 progName = sys.argv[0].split('/')[-1]
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
41 log = logging.getLogger() # this has to get the root logger
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
42 log.name = progName # but we can rename it for clarity
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
43
1221
3c78608a216a don't break all non-root log channels
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
44
1512
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
45 class FractionTimeFilter(logging.Filter):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
46
1512
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
47 def filter(self, record):
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
48 record.fractionTime = (
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
49 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(record.created)) +
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
50 ("%.3f" % (record.created % 1)).lstrip('0'))
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
51 # Don't filter the record.
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
52 return 1
858
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
53
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
54
1512
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
55 coloredlogs.install(
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
56 level='DEBUG',
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
57 fmt='%(fractionTime)s %(name)s[%(process)d] %(levelname)s %(message)s')
3693b226b0b8 update coloredlogs
Drew Perttula <drewp@bigasterisk.com>
parents: 1425
diff changeset
58 logging.getLogger().handlers[0].addFilter(FractionTimeFilter())
858
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
59
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
60
933
8435e3ee1ec2 put program name in terminal title
drewp@bigasterisk.com
parents: 874
diff changeset
61 def setTerminalTitle(s):
1425
8796803a1b45 show prog name in my i3 terminals
drewp@bigasterisk.com
parents: 1239
diff changeset
62 if os.environ.get('TERM', '') in ['xterm', 'rxvt', 'rxvt-unicode-256color']:
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
63 print("\033]0;%s\007" % s) # not escaped/protected correctly
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
64
874
167a61d3cfbf subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents: 873
diff changeset
65
1215
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents: 1210
diff changeset
66 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
67 setTerminalTitle(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
68 '[%s] %s' %
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1697
diff changeset
69 (socket.gethostname(), ' '.join(sys.argv).replace('bin/', '')))
934
f92550d33004 comment
drewp@bigasterisk.com
parents: 933
diff changeset
70
f92550d33004 comment
drewp@bigasterisk.com
parents: 933
diff changeset
71 # see http://www.youtube.com/watch?v=3cIOT9kM--g for commands that make
f92550d33004 comment
drewp@bigasterisk.com
parents: 933
diff changeset
72 # profiles and set background images