3 "exec" "`which python`" "-tt" "$0" "$@"
11 __author__ =
'Sebastien Binet (binet@cern.ch)'
12 __doc__ =
'For details about pyroot.py, run "less `which pyroot.py`"'
20 _userlongopts = [
"batch",
"interactive",
"no-display",
"debug=",
"command=",
26 print (
"""Accepted command line options:
27 -b, --batch ... batch mode
28 -i, --interactive ... interactive mode [default]
29 --no-display prompt, but no graphics display
30 -c, --command ... one-liner, runs before any scripts
31 -h, --help ... print this help message
32 -,-- [arg1,...] ... additional arguments passed directly
33 to user scripts (left untouched)
34 [<file1>.py [<file2>.py [...]]] ... scripts to run""")
48 for arg
in sys.argv[1:]:
51 elif arg
in (
'-',
'--'):
52 userOpts += sys.argv[ sys.argv.index( arg )+1: ]
59 optlist, args = getopt.getopt( opts, _useropts, _userlongopts )
65 print (
"Unhandled arguments:", args)
68 for opt, arg
in optlist:
69 if opt
in (
"-b",
"--batch"):
71 elif opt
in (
"-i",
"--interactive"):
74 if display
is None: display = 1
75 elif opt
in (
"--no-display",):
77 elif opt
in (
"-c",
"--command"):
78 command = string.strip( arg )
79 elif opt
in (
"-h",
"--help"):
82 if optlist: del opt, arg
83 del args, optlist, opts
84 del _useropts, _userlongopts, string, getopt
87 if not display
and '-b' not in sys.argv:
88 sys.argv = sys.argv[:1] + [
'-b'] + sys.argv[1:]
93 if not os.getcwd()
in sys.path:
94 sys.path = [ os.getcwd() ] + sys.path
96 if '' not in sys.path:
97 sys.path = [
'' ] + sys.path
100 fhistory = os.path.expanduser(
'~/.pyroot.history' )
105 if os.isatty( sys.stdin.fileno() ):
106 os.close( sys.stdin.fileno() )
107 if 'PYTHONINSPECT' in os.environ:
108 os.unsetenv(
'PYTHONINSPECT')
110 os.environ[
'PYTHONINSPECT'] =
'1'
112 import rlcompleter, readline
114 readline.parse_and_bind(
'tab: complete' )
115 readline.parse_and_bind(
'set show-all-if-ambiguous On' )
118 if os.path.exists( fhistory ):
119 readline.read_history_file( fhistory )
120 readline.set_history_length( 1024 )
122 del readline, rlcompleter
125 print (sys.ps1+
"loading ROOT...")
127 print (sys.ps1+
"loading ROOT... [ok]")
128 ROOT.gROOT.SetStyle(
"Plain")
129 ROOT.gStyle.SetPalette(1)
130 ROOT.gStyle.SetOptStat(111111)
131 print (sys.ps1+
"loaded pyroot style... [ok]")
135 import atexit, readline
138 atexit.register( readline.write_history_file, fhistory )
144 print (sys.ps1+
'executing CLI (-c) command: "%s"' % command)
148 for script
in scripts:
150 exec (
open(script).
read(), globals())
151 except Exception
as e:
152 if isinstance(e,SystemExit):
156 traceback.print_exc()
175 print (sys.ps1+
"entering interactive session...")