1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#!/bin/false
#
# Regina - A Normal Surface Theory Calculator
# Python Environment Initialisation
#
# Copyright (c) 2003-2009, Ben Burton
# For further details contact Ben Burton (bab@debian.org).
#
# Usage: runscript.py [ <library> ... ] [ -- <script> [ <script-arg> ... ]]
#
# Initialises the python environment for working with the Regina
# calculation engine. Tasks include:
#
# - Importing the 'regina' module;
# - Running a series of provided library scripts;
# - Running a selected script with the provided command-line arguments,
# or,
# printing a startup banner for working in interactive mode.
#
# This script is for internal use only and should NOT be run directly.
# Instead the wrapper script regina-python should be used.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
import sys
# --- Import the Regina calculation engine. ---
try:
import regina
except:
print 'ERROR: The calculation engine module could not be loaded.'
sys.exit(1)
# --- Parse the command-line arguments. ---
libNames = []
scriptName = None
scriptArgs = []
libsDone = 0
for i in sys.argv[1:]:
if libsDone:
if scriptName == None:
scriptName = i
else:
scriptArgs.append(i)
elif i == '--':
libsDone = 1
else:
libNames.append(i)
# --- Run each library script in turn. ---
for i in libNames:
try:
print 'Running ' + i + '...'
execfile(i)
except SystemExit:
pass
except:
sys.excepthook(*sys.exc_info())
print "ERROR: The custom library '" + i + "' could not be executed."
sys.exit(1)
# --- Run the script or print the banner as required. ---
if scriptName != None:
sys.argv = [ scriptName ] + scriptArgs
try:
execfile(scriptName)
sys.exit(0)
except SystemExit:
pass
except:
sys.excepthook(*sys.exc_info())
print 'ERROR: An error occurred whilst executing the script.'
sys.exit(1)
else:
print regina.welcome()
|