3 "exec" "`which python`" "-tt" "$0" "$@"
11 from __future__
import print_function
13 __author__ =
'Sebastien Binet (binet@cern.ch)'
14 __doc__ =
'For details about pyroot.py, run "less `which pyroot.py`"'
22 _userlongopts = [
"batch",
"interactive",
"no-display",
"debug=",
"command=",
28 print (
"""Accepted command line options:
29 -b, --batch ... batch mode
30 -i, --interactive ... interactive mode [default]
31 --no-display prompt, but no graphics display
32 -c, --command ... one-liner, runs before any scripts
33 -h, --help ... print this help message
34 -,-- [arg1,...] ... additional arguments passed directly
35 to user scripts (left untouched)
36 [<file1>.py [<file2>.py [...]]] ... scripts to run""")
50 for arg
in sys.argv[1:]:
53 elif arg
in (
'-',
'--'):
54 userOpts += sys.argv[ sys.argv.index( arg )+1: ]
61 optlist, args = getopt.getopt( opts, _useropts, _userlongopts )
67 print (
"Unhandled arguments:", args)
70 for opt, arg
in optlist:
71 if opt
in (
"-b",
"--batch"):
73 elif opt
in (
"-i",
"--interactive"):
76 if display
is None: display = 1
77 elif opt
in (
"--no-display",):
79 elif opt
in (
"-c",
"--command"):
80 command = string.strip( arg )
81 elif opt
in (
"-h",
"--help"):
84 if optlist: del opt, arg
85 del args, optlist, opts
86 del _useropts, _userlongopts, string, getopt
89 if not display
and '-b' not in sys.argv:
90 sys.argv = sys.argv[:1] + [
'-b'] + sys.argv[1:]
95 if not os.getcwd()
in sys.path:
96 sys.path = [ os.getcwd() ] + sys.path
98 if '' not in sys.path:
99 sys.path = [
'' ] + sys.path
102 fhistory = os.path.expanduser(
'~/.pyroot.history' )
107 if os.isatty( sys.stdin.fileno() ):
108 os.close( sys.stdin.fileno() )
109 if 'PYTHONINSPECT' in os.environ:
110 os.unsetenv(
'PYTHONINSPECT')
112 os.environ[
'PYTHONINSPECT'] =
'1'
114 import rlcompleter, readline
116 readline.parse_and_bind(
'tab: complete' )
117 readline.parse_and_bind(
'set show-all-if-ambiguous On' )
120 if os.path.exists( fhistory ):
121 readline.read_history_file( fhistory )
122 readline.set_history_length( 1024 )
124 del readline, rlcompleter
127 print (sys.ps1+
"loading ROOT...")
129 print (sys.ps1+
"loading ROOT... [ok]")
130 ROOT.gROOT.SetStyle(
"Plain")
131 ROOT.gStyle.SetPalette(1)
132 ROOT.gStyle.SetOptStat(111111)
133 print (sys.ps1+
"loaded pyroot style... [ok]")
137 import atexit, readline
140 atexit.register( readline.write_history_file, fhistory )
146 print (sys.ps1+
'executing CLI (-c) command: "%s"' % command)
150 from past.builtins
import execfile
151 for script
in scripts:
154 except Exception
as e:
155 if isinstance(e,SystemExit):
159 traceback.print_exc()
178 print (sys.ps1+
"entering interactive session...")