Changeset 2446


Ignore:
Timestamp:
03/14/07 11:38:27 (13 years ago)
Author:
curtis
Message:

Only upload data once per dataset.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/ome/ImageUploader.java

    r2327 r2446  
    2424package loci.visbio.ome; 
    2525 
    26 import java.io.*; 
    2726import java.util.*; 
    28 import loci.formats.FilePattern; 
    2927import loci.formats.ome.OMEUploader; 
     28import loci.formats.ome.UploadException; 
    3029import loci.visbio.*; 
    3130 
     
    5857      OMEUploader ul = new OMEUploader(server, username, password); 
    5958      String[] ids = data.getFilenames(); 
    60       for (int i=0; i<ids.length; i++) { 
    61         ul.uploadFile(ids[0], true); 
    62       } 
     59      ul.uploadFile(ids[0], true); 
    6360    } 
    64     catch (Exception exc) { 
     61    catch (UploadException exc) { 
    6562      notifyListeners(new TaskEvent(1, 1, 
    6663        "Error uploading (see error console for details)")); 
     
    9491  } 
    9592 
    96   // -- Main method -- 
    97  
    98   /** 
    99    * A command-line tool for uploading data to an 
    100    * OME server using client-side Java tools. 
    101    */ 
    102   public static void main(String[] args) { 
    103     String server = null, user = null, pass = null; 
    104     Vector files = new Vector(); 
    105  
    106     // parse command-line arguments 
    107     boolean doUsage = false; 
    108     if (args.length == 0) doUsage = true; 
    109     for (int i=0; i<args.length; i++) { 
    110       if (args[i].startsWith("-")) { 
    111         // argument is a command line flag 
    112         String param = args[i]; 
    113         try { 
    114           if (param.equalsIgnoreCase("-s")) server = args[++i]; 
    115           else if (param.equalsIgnoreCase("-u")) user = args[++i]; 
    116           else if (param.equalsIgnoreCase("-p")) pass = args[++i]; 
    117           else if (param.equalsIgnoreCase("-h") || 
    118             param.equalsIgnoreCase("-?")) 
    119           { 
    120             doUsage = true; 
    121           } 
    122           else { 
    123             System.out.println("Error: unknown flag: " + param); 
    124             System.out.println(); 
    125             doUsage = true; 
    126             break; 
    127           } 
    128         } 
    129         catch (ArrayIndexOutOfBoundsException exc) { 
    130           if (i == args.length - 1) { 
    131             System.out.println("Error: flag " + param + 
    132               " must be followed by a parameter value."); 
    133             System.out.println(); 
    134             doUsage = true; 
    135             break; 
    136           } 
    137           else throw exc; 
    138         } 
    139       } 
    140       else { 
    141         files.add(args[i]); 
    142       } 
    143     } 
    144     if (doUsage) { 
    145       System.out.println("Usage: omeul [-s server.address] " + 
    146         "[-u username] [-p password] filename"); 
    147       System.out.println(); 
    148       System.exit(1); 
    149     } 
    150  
    151     // ask for information if necessary 
    152     BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); 
    153     if (server == null) { 
    154       System.out.print("Server address? "); 
    155       try { server = cin.readLine(); } 
    156       catch (IOException exc) { } 
    157     } 
    158     if (user == null) { 
    159       System.out.print("Username? "); 
    160       try { user = cin.readLine(); } 
    161       catch (IOException exc) { } 
    162     } 
    163     if (pass == null) { 
    164       System.out.print("Password? "); 
    165       try { pass = cin.readLine(); } 
    166       catch (IOException exc) { } 
    167     } 
    168  
    169     if (server == null || user == null || pass == null) { 
    170       System.out.println("Error: could not obtain server login information"); 
    171       System.exit(2); 
    172     } 
    173     System.out.println("Using server " + server + " as user " + user); 
    174  
    175     // create image uploader 
    176     ImageUploader uploader = new ImageUploader(); 
    177     uploader.addTaskListener(new TaskListener() { 
    178       public void taskUpdated(TaskEvent e) { 
    179         System.out.println(e.getStatusMessage()); 
    180       } 
    181     }); 
    182  
    183     for (int i=0; i<files.size(); i++) { 
    184       FilePattern fp = new FilePattern((String) files.get(i)); 
    185       int[] lengths = fp.getCount(); 
    186       if (lengths.length == 0) { 
    187         lengths = new int[1]; 
    188         lengths[0] = 1; 
    189       } 
    190        
    191       loci.visbio.data.Dataset data = new loci.visbio.data.Dataset( 
    192         (String) files.get(i), fp.getPattern(), fp.getFiles(), lengths,  
    193         new String[lengths.length]); 
    194       uploader.upload(data, server, user, pass); 
    195     } 
    196   } 
    197  
    19893} 
Note: See TracChangeset for help on using the changeset viewer.