Search in sources :

Example 1 with ProcessUtil

use of org.onebusaway.admin.util.ProcessUtil in project onebusaway-application-modules by camsys.

the class BundleBuildingServiceImpl method prepStif.

// clean stifs via STIF_PYTHON_CLEANUP_SCRIPT
private void prepStif(BundleBuildRequest request, BundleBuildResponse response) {
    NYCFileUtils fs = new NYCFileUtils();
    // create STIF dir as well
    String stifPath = request.getTmpDirectory() + File.separator + "stif";
    File stifDir = new File(stifPath);
    _log.info("creating stif directory=" + stifPath);
    stifDir.mkdirs();
    try {
        File[] stifDirectories = stifDir.listFiles();
        if (stifDirectories != null) {
            fs = new NYCFileUtils(request.getTmpDirectory());
            String stifUtilUrl = getStifCleanupUrl();
            response.addStatusMessage("downloading " + stifUtilUrl + " to clean stifs");
            fs.wget(stifUtilUrl);
            String stifUtilName = fs.parseFileName(stifUtilUrl);
            // make executable
            fs.chmod("500", request.getTmpDirectory() + File.separator + stifUtilName);
            // for each subdirectory of stif, run the script
            for (File stifSubDir : stifDirectories) {
                String cmd = request.getTmpDirectory() + File.separator + stifUtilName + " " + stifSubDir.getCanonicalPath();
                // kick off process and collect output
                ProcessUtil pu = new ProcessUtil(cmd);
                pu.exec();
                if (pu.getReturnCode() == null || !pu.getReturnCode().equals(0)) {
                    // obanyc-1692, do not send to client
                    String returnCodeMessage = stifUtilName + " exited with return code " + pu.getReturnCode();
                    _log.info(returnCodeMessage);
                    _log.info("output=" + pu.getOutput());
                    _log.info("error=" + pu.getError());
                }
                if (pu.getException() != null) {
                    response.setException(pu.getException());
                }
            }
            response.addStatusMessage("stif cleaning complete");
        }
    } catch (Exception any) {
        response.setException(any);
    }
}
Also used : NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) ZipFile(java.util.zip.ZipFile) File(java.io.File) ProcessUtil(org.onebusaway.admin.util.ProcessUtil) RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException)

Aggregations

File (java.io.File)1 ZipFile (java.util.zip.ZipFile)1 NYCFileUtils (org.onebusaway.admin.util.NYCFileUtils)1 ProcessUtil (org.onebusaway.admin.util.ProcessUtil)1 RemoteConnectFailureException (org.springframework.remoting.RemoteConnectFailureException)1