annotate bin/run_local.py @ 1221:3c78608a216a

don't break all non-root log channels Ignore-this: 2908404aef5c5040c84aa577c201ef0b
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 08 Jun 2015 06:54:08 +0000
parents 0d295af23c4b
children 0025b04a1c0a
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
209
1a84c5e83d3e dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff changeset
6 sys.path.insert(0,os.path.join(os.path.dirname(sys.argv[0]),".."))
1a84c5e83d3e dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff changeset
7
306
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
8 from twisted.python.failure import Failure
209
1a84c5e83d3e dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
diff changeset
9
306
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
10 import Tkinter
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
11 def rce(self, exc, val, tb):
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
12 sys.stderr.write("Exception in Tkinter callback\n")
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
13 if True:
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
14 sys.excepthook(exc, val, tb)
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
15 else:
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
16 Failure(val, exc, tb).printDetailedTraceback()
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
17 Tkinter.Tk.report_callback_exception = rce
41830567a8d0 bigger traceback printouts for all tools
Drew Perttula <drewp@bigasterisk.com>
parents: 209
diff changeset
18
1087
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
19 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
20 try:
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
21 import faulthandler
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
22 faulthandler.enable()
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
23 except ImportError:
1f877950ad28 new picamserve for raspberry pi camera -> http, especially with crop control
Drew Perttula <drewp@bigasterisk.com>
parents: 1072
diff changeset
24 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
25
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
26 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
27 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
28 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
29
858
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
30
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
31 class CSH(coloredlogs.ColoredStreamHandler):
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
32 def render_timestamp(self, created):
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
33 return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(created)) + (
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
34 "%.3f" % (created % 1)).lstrip('0')
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
35
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
36 def render_name(self, name):
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
37 return name
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
38
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
39 log.addHandler(CSH(show_hostname=False, show_name=True))
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
40
1f93e5d19f8a merge run_local again
Drew Perttula <drewp@bigasterisk.com>
parents: 837
diff changeset
41
933
8435e3ee1ec2 put program name in terminal title
drewp@bigasterisk.com
parents: 874
diff changeset
42 def setTerminalTitle(s):
1098
770b0d0005fc command shell title support on TERM=rxvt too
Drew Perttula <drewp@bigasterisk.com>
parents: 1087
diff changeset
43 if os.environ.get('TERM', '') in ['xterm', 'rxvt']:
933
8435e3ee1ec2 put program name in terminal title
drewp@bigasterisk.com
parents: 874
diff changeset
44 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
45
1215
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents: 1210
diff changeset
46 if 'listsongs' not in sys.argv[0] and 'homepageConfig' not in sys.argv[0]:
1156
f66586649ae3 show more process info in terminal title
drewp@bigasterisk.com
parents: 1155
diff changeset
47 setTerminalTitle('[%s] %s' % (socket.gethostname(), ' '.join(sys.argv)))
934
f92550d33004 comment
drewp@bigasterisk.com
parents: 933
diff changeset
48
f92550d33004 comment
drewp@bigasterisk.com
parents: 933
diff changeset
49 # see http://www.youtube.com/watch?v=3cIOT9kM--g for commands that make
f92550d33004 comment
drewp@bigasterisk.com
parents: 933
diff changeset
50 # profiles and set background images