Changeset 7960


Ignore:
Timestamp:
2004-08-16T22:38:03+12:00 (20 years ago)
Author:
davidb
Message:

Improvements to remoteRun code to catch and respond to errors better.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/shell/GShell.java

    r7925 r7960  
    4747import org.greenstone.gatherer.Dictionary;
    4848import org.greenstone.gatherer.Gatherer;
     49import org.greenstone.gatherer.cdm.CollectionConfiguration;
     50import org.greenstone.gatherer.cdm.CollectionDesignManager;
     51import org.greenstone.gatherer.cdm.CollectionMetaManager;
     52import org.greenstone.gatherer.cdm.CollectionMeta;
    4953import org.greenstone.gatherer.msm.GreenstoneArchiveParser;
    5054import org.greenstone.gatherer.shell.GShellListener;
     
    204208    }
    205209
     210
     211    protected int check_for_error(String line, StringBuffer error_list,
     212                  int error_count)
     213    {
     214    if (line.startsWith("ERROR:")) {
     215        error_count++;
     216        if (error_count<10) {
     217        error_list.append(line);
     218        }
     219        else if (error_count==10) {
     220        error_list.append("...\n");
     221        }
     222    }
     223    return error_count;
     224    }
     225       
     226
    206227    protected void runRemote(String[] args, BufferedOutputStream bos)
    207228    {
     
    254275        URLConnection launch_connection = launch_url.openConnection();
    255276        InputStream stdis = launch_connection.getInputStream();
    256         InputStreamReader stdisr = new InputStreamReader(stdis, "UTF-8"  );
     277        InputStreamReader stdisr = new InputStreamReader(stdis, "UTF-8");
    257278   
    258279        BufferedReader stdbr = new BufferedReader(stdisr);
    259280   
     281        StringBuffer error_list = new StringBuffer();
     282        int error_count = 0;
     283
    260284        if (type == GShell.NEW) {
    261285        while(true) {
    262286            String line = stdbr.readLine();
    263287            if (line == null) { break; }
    264         }       
     288            error_count = check_for_error(line,error_list,error_count);
     289        }
    265290        }
    266291        else {
     
    268293            String line = stdbr.readLine();
    269294            if (line == null) { break; }
     295            error_count = check_for_error(line,error_list,error_count);
    270296            fireMessage(type, typeAsString(type) + "> " + line, status, bos);
    271297        }       
     
    273299        stdbr.close();
    274300   
    275         status = OK;
    276         fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Success"), status, null);
     301        if (error_count>0) {
     302        status = ERROR;
     303        System.err.println(error_list);
     304        if (type != GShell.NEW) {
     305            fireMessage(type, typeAsString(type) + "> " + error_list, status, null);
     306        }
     307        }
     308        else {
     309        status = OK;
     310        fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Success"), status, null);
     311        }
     312
     313
    277314    }
    278315    // Exception
    279316    catch (Exception exception) {
    280         Gatherer.println("Exception in GShell.runRemove() - unexpected");
     317        System.err.println("Exception in GShell.runRemote() - unexpected");
    281318        Gatherer.printStackTrace(exception);
    282319        status = ERROR;
     
    302339        InputStreamReader eisr = new InputStreamReader( prcs.getErrorStream(), "UTF-8" );
    303340        InputStreamReader stdisr = new InputStreamReader( prcs.getInputStream(), "UTF-8"  );
    304         //BufferedReader ebr = new BufferedReader( eisr );
    305         //BufferedReader stdinbr = new BufferedReader( stdinisr );
    306         // Captures the std err of a program and pipes it into std in of java
    307341   
    308342        StringBuffer eline_buffer = new StringBuffer();
     
    438472        Utility.zipup(col_name,Utility.CONFIG_FILE);
    439473        Utility.upload_url_zip(col_name,"etc");
     474
     475
     476        String col_dir = Utility.getCollectDir(Gatherer.config.gsdl_path);
     477
     478        File img_dir = new File(Utility.getImagesDir(col_dir));
     479        if (img_dir.exists()) {
     480            // upload images/ directory to server
     481            Utility.zipup(col_name,"images");
     482            Utility.upload_url_zip(col_name,"images");
     483        }
     484
     485        // see if collection specific image needs uploading
     486        CollectionMetaManager cmm
     487            = CollectionDesignManager.collectionmeta_manager;
     488
     489        CollectionMeta icon_collection_collectionmeta
     490            = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);
     491        CollectionMeta icon_collection_small_collectionmeta
     492            = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
     493
     494        String ics_text = icon_collection_collectionmeta.getValue(CollectionMeta.TEXT);
     495        String icsc_text = icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT);
     496        if ((ics_text != null) && (ics_text != "")) {
     497            // Stub code for detecting when collectoin image changed
     498            // => need to upload images
     499            // System.err.println("**** ics_text = " + ics_text);
     500        }
     501
    440502
    441503        if (progress!=null) {
Note: See TracChangeset for help on using the changeset viewer.