use of org.opentripplanner.standalone.OTPMain in project OpenTripPlanner by opentripplanner.
the class OtpsEntryPoint method fromArgs.
/**
* Create an OTP scripting entry point using the same command-line parameters as used by the OTP
* application. This is useful when using scripting from an outside environment, using OTP as a
* library. For example in jython the following script 'myscript.py':
*
* <pre>
* #!/usr/bin/jython
* from org.opentripplanner.scripting.api import OtpsEntryPoint
* otp = OtpsEntryPoint.fromArgs([ "-g", "." ])
* ...
* </pre>
*
* One can then run jython with:
*
* <pre>
* CLASSPATH=otp.jar jython myscript.py
* </pre>
*
* @param args Command-line arguments, as used by the application.
* @return The "otp" scripting facade bean.
* @throws Exception
*/
public static OtpsEntryPoint fromArgs(String[] args) throws Exception {
if (args == null)
args = new String[0];
CommandLineParameters params = new CommandLineParameters();
@SuppressWarnings("unused") JCommander jc = new JCommander(params, args);
// Force analyst
params.analyst = true;
params.infer();
OTPMain otpMain = new OTPMain(params);
if (// TODO Enable this
params.build != null)
throw new IllegalArgumentException("Building from script is not yet supported.");
if (// This would be weird
params.scriptFile != null)
throw new IllegalArgumentException("Scripting from script is not supported.");
if (// Useless
params.visualize)
throw new IllegalArgumentException("Vizualizer from script is not supported.");
if (// Why not?
params.server)
throw new IllegalArgumentException("Server from script is not supported.");
otpMain.run();
return new OtpsEntryPoint(otpMain.otpServer);
}
Aggregations