36
36
import scriptmanager .util .FileSelection ;
37
37
import scriptmanager .objects .LogItem ;
38
38
import scriptmanager .objects .ToolDescriptions ;
39
+ import scriptmanager .objects .Exceptions .ScriptManagerException ;
39
40
40
41
/**
41
42
* Store, update, and manage the set of LogItems that make up a ScriptManager
@@ -77,10 +78,8 @@ public class LogManagerWindow extends JFrame {
77
78
78
79
private ArrayList <LogItem > logItems ;
79
80
private Timestamp logStart ;
80
- private int verbosity = 0 ;
81
81
82
82
private File odir = null ;
83
- private String ofilename ;
84
83
85
84
private boolean on = true ;
86
85
@@ -93,7 +92,6 @@ public LogManagerWindow() {
93
92
// Initilize log timestamp
94
93
logStart = new Timestamp (new Date ().getTime ());
95
94
logItems = new ArrayList <LogItem >();
96
- ofilename = logStart .toString ().replace (' ' , '_' ).replace (':' , '-' ) + "_logfile.sh" ;
97
95
initialize ();
98
96
}
99
97
@@ -200,7 +198,7 @@ public void actionPerformed(ActionEvent e) {
200
198
sl_pnlSettings .putConstraint (SpringLayout .NORTH , txtOutputFilename , 0 , SpringLayout .NORTH , lblFileSeparator );
201
199
sl_pnlSettings .putConstraint (SpringLayout .WEST , txtOutputFilename , 10 , SpringLayout .EAST , lblFileSeparator );
202
200
sl_pnlSettings .putConstraint (SpringLayout .EAST , txtOutputFilename , -10 , SpringLayout .EAST , pnl_Settings );
203
- txtOutputFilename .setText (getFilename () );
201
+ txtOutputFilename .setText (logStart . toString (). replace ( ' ' , '_' ). replace ( ':' , '-' ) + "_logfile.sh" );
204
202
pnl_Settings .add (txtOutputFilename );
205
203
txtOutputFilename .setColumns (100 );
206
204
@@ -211,6 +209,8 @@ public void actionPerformed(ActionEvent e) {
211
209
public void actionPerformed (ActionEvent e ) {
212
210
try {
213
211
writeLogShell ();
212
+ } catch (ScriptManagerException sme ) {
213
+ JOptionPane .showMessageDialog (null , sme .getMessage ());
214
214
} catch (IOException ioe ) {
215
215
JOptionPane .showMessageDialog (null , ioe .getMessage ());
216
216
}
@@ -289,15 +289,11 @@ public void drawTable() {
289
289
public ArrayList <LogItem > getLogItems () { return logItems ; }
290
290
public LogItem getLogItem (int i ) { return logItems .get (i ); }
291
291
public Timestamp getLogStart () { return logStart ; }
292
- public int getVerbosity () { return verbosity ; }
293
- public String getFilename () { return ofilename ; }
294
292
public File getOutputDirectory () { return odir ; }
295
293
296
294
// Setters
297
295
public void setToggleOn (boolean toggle ) { on = toggle ; }
298
296
public void setLogStart (Timestamp time ) { logStart = time ; }
299
- public void setVerbosity (int v ) { verbosity = v ; }
300
- public void setFilename (String o ) { ofilename = o ; }
301
297
public void setOutputDirectory (File o ) { odir = o ; }
302
298
303
299
// Status - getters, setters, and Comparators
@@ -333,25 +329,44 @@ public void removeLogItems(int[] r_idxs) {
333
329
}
334
330
}
335
331
332
+ /**
333
+ * Get the verbosity value from the radio buttons
334
+ *
335
+ * @return verbosity level (1, 2, or 3)
336
+ */
337
+ public short getLogVerbosity () throws ScriptManagerException {
338
+ if (verbosity1 .isSelected ()) {
339
+ return 1 ;
340
+ } else if (verbosity2 .isSelected ()) {
341
+ return 2 ;
342
+ } else if (verbosity3 .isSelected ()) {
343
+ return 3 ;
344
+ }
345
+ throw new ScriptManagerException ("Unrecognized verbosity level. This should never throw" );
346
+ }
347
+
336
348
/**
337
349
* Write the contents of the log as a shell script
338
350
*
339
351
* @throws IOException Invalid file or parameters
340
352
*/
341
- public void writeLogShell () throws IOException {
353
+ public void writeLogShell () throws IOException , ScriptManagerException {
342
354
// Create File & initialize stream
343
- PrintStream OUT = new PrintStream (new File (OUT_DIR + File .separator + ofilename ));
355
+ PrintStream OUT = new PrintStream (new File (OUT_DIR + File .separator + txtOutputFilename .getText ()));
356
+
357
+ // Determine verbosity of output
358
+ short verbosity = getLogVerbosity ();
344
359
345
360
// Write Header (V=1+)
346
- OUT .println ("# VERSION\t " + ToolDescriptions .VERSION );
361
+ OUT .println ("# VERSION\t " + ToolDescriptions .VERSION + " \t Verbosity Level:" + verbosity );
347
362
OUT .println ("SCRIPTMANAGER=/path/to/ScriptManager.jar" );
348
363
OUT .println ("PICARD=/path/to/picard.jar" );
349
364
OUT .println ();
350
365
351
366
// Write LogInfo start time (V=1+)
352
367
OUT .println ("# Log start time: " + logStart .toString ());
353
368
354
- // Sort LogItems for writing--not needed unless fireproperty adding out of order
369
+ // Add later: Sort LogItems for writing--not needed unless fireproperty adding out of order
355
370
356
371
// Record each LogItem
357
372
for (int i = 0 ; i <logItems .size (); i ++) {
@@ -364,16 +379,19 @@ public void writeLogShell() throws IOException {
364
379
}
365
380
366
381
// Write LogItem command string (V=1+)
382
+ if (item .getStopTime ()==null ) {
383
+ OUT .print ("# " );
384
+ }
367
385
OUT .println (item .getCommand ());
368
386
369
387
if (verbosity >=2 ) {
370
388
// Write LogItem status (V=2+)
371
- OUT .println ("# " + item .getStatus ());
389
+ OUT .println ("# Exit status: " + item .getStatus ());
372
390
// Write LogItem end time (V=2+)
373
- OUT .println ("# " + item .getStopTime ().toString ());
391
+ OUT .println (item . getStopTime ()== null ? "#Incomplete" : "# " + item .getStopTime ().toString ());
374
392
// Write LogItem runtime (V=3+)
375
393
if (verbosity >=3 ) {
376
- OUT .println ("# Runtime: " + (item .getStopTime ().getTime () - item .getStartTime ().getTime ()));
394
+ OUT .println (item . getStopTime ()== null ? "# Runtime: -" : "# Runtime: " + (item .getStopTime ().getTime () - item .getStartTime ().getTime ()));
377
395
}
378
396
}
379
397
// TODO: Write Toggle Log info
0 commit comments