file = new File(releasePropertiesFilename);
}
- if (filename == null || !file.exists())
+ if (filename == null)
+ return null;
+ if (!file.exists())
{
System.err.println("Could not load bootstrap preferences file '"
+ filename + "'");
import jalview.gui.StructureViewer;
import jalview.gui.StructureViewer.ViewerType;
import jalview.io.AppletFormatAdapter;
+import jalview.io.BackupFiles;
import jalview.io.BioJsHTMLOutput;
import jalview.io.DataSourceType;
import jalview.io.FileFormat;
import jalview.io.FileFormatException;
import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
import jalview.io.FileLoader;
import jalview.io.HtmlSvgOutput;
import jalview.io.IdentifyFile;
{
String val = av.getValue();
SubVals subVal = av.getSubVals();
- String type = "png"; // default
String fileName = subVal.getContent();
File file = new File(fileName);
+ String name = af.getName();
String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
Arg.RENDERER, subVal);
if (renderer == null)
renderer = "text";
+ String type = "png"; // default
type = ArgParser.getValueFromSubValOrArg(avm, av, Arg.TYPE, subVal);
if (type == null && fileName != null)
{
Console.debug("Creating BioJS MSA Viwer HTML file: " + fileName);
break;
+ case "eps":
+ af.createEPS(file, name);
+ Console.debug("Creating EPS file: " + fileName);
+ break;
+
+ case "imagemap":
+ af.createImageMap(file, name);
+ Console.debug("Creating ImageMap file: " + fileName);
+ break;
+
default:
Console.warn(Arg.IMAGE.argString() + " type '" + type
+ "' not known. Ignoring");
for (ArgValue av : avm.getArgValueList(Arg.OUTPUT))
{
String val = av.getValue();
- SubVals subVal = av.getSubVals();
- String type = null; // default
- String fileName = subVal.getContent();
+ SubVals subVals = av.getSubVals();
+ String fileName = subVals.getContent();
File file = new File(fileName);
+ boolean overwrite = ArgParser.getFromSubValArgOrPref(avm,
+ Arg.OVERWRITE, subVals, null, "OVERWRITE_OUTPUT", false);
+ // backups. Use the Arg.BACKUPS or subval "backups" setting first,
+ // otherwise if headless assume false, if not headless use the user
+ // preference with default true.
+ boolean backups = ArgParser.getFromSubValArgOrPref(avm, Arg.BACKUPS,
+ subVals, null,
+ Platform.isHeadless() ? null : BackupFiles.ENABLED,
+ !Platform.isHeadless());
+
+ // if backups is not true then --overwrite must be specified
+ if (file.exists() && !(overwrite || backups))
+ {
+ Console.error("Won't overwrite file '" + fileName + "' without "
+ + Arg.OVERWRITE.argString() + " or "
+ + Arg.BACKUPS.argString() + " set");
+ return false;
+ }
+
+ String name = af.getName();
+ String format = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.FORMAT, subVals);
+ FileFormats ffs = FileFormats.getInstance();
+ List<String> validFormats = ffs.getWritableFormats(false);
+
+ FileFormatI ff = null;
+ if (format == null && fileName != null)
+ {
+ FORMAT: for (String fname : validFormats)
+ {
+ FileFormatI tff = ffs.forName(fname);
+ String[] extensions = tff.getExtensions().split(",");
+ for (String ext : extensions)
+ {
+ if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
+ {
+ ff = tff;
+ format = ff.getName();
+ break FORMAT;
+ }
+ }
+ }
+ }
+ if (ff == null && format != null)
+ {
+ ff = ffs.forName(format);
+ }
+ if (ff == null)
+ {
+ StringBuilder validSB = new StringBuilder();
+ for (String f : validFormats)
+ {
+ if (validSB.length() > 0)
+ validSB.append(", ");
+ validSB.append(f);
+ FileFormatI tff = ffs.forName(f);
+ validSB.append(" (");
+ validSB.append(tff.getExtensions());
+ validSB.append(")");
+ }
+
+ Jalview.exit("No valid format specified for "
+ + Arg.OUTPUT.argString() + ". Valid formats are "
+ + validSB.toString() + ".", 1);
+ // this return really shouldn't happen
+ return false;
+ }
+
+ String savedBackupsPreference = Cache
+ .getDefault(BackupFiles.ENABLED, null);
+ Console.debug("Setting backups to " + backups);
+ Cache.applicationProperties.put(BackupFiles.ENABLED,
+ Boolean.toString(backups));
+ af.saveAlignment(fileName, ff);
+ Console.debug("Returning backups to " + savedBackupsPreference);
+ if (savedBackupsPreference != null)
+ Cache.applicationProperties.put(BackupFiles.ENABLED,
+ savedBackupsPreference);
+ if (af.isSaveAlignmentSuccessful())
+ {
+ Console.debug("Written alignment '" + name + "' in "
+ + ff.getName() + " format to " + file);
+ }
+ else
+ {
+ Console.warn("Error writing file " + file + " in " + ff.getName()
+ + " format!");
+ }
+
}
}
return true;
{
OutputStream devNull = new OutputStream()
{
+
@Override
public void write(int b)
{
try
{
- String logLevel = bootstrapArgs.contains(Arg.DEBUG) ? "DEBUG" : null;
+ String logLevel = null;
+ if (bootstrapArgs.contains(Arg.TRACE))
+ {
+ logLevel = "TRACE";
+ }
+ else if (bootstrapArgs.contains(Arg.DEBUG))
+ {
+ logLevel = "DEBUG";
+ }
if (logLevel == null && !(bootstrapProperties == null))
{
logLevel = bootstrapProperties.getProperty(Cache.JALVIEWLOGLEVEL);
COLOUR, FEATURES, GROOVY, GROUPS, HEADLESS, JABAWS, DISPLAY, GUI, NEWS,
SORTBYTREE, USAGESTATS, APPEND, OPEN, PROPS, QUESTIONNAIRE, SETPROP, TREE,
VDOC, VSESS, OUTPUT, SSANNOTATIONS, NOTEMPFAC, TEMPFAC, TITLE, PAEMATRIX,
- WRAP, NOSTRUCTURE, STRUCTURE, STRUCTUREVIEWER, IMAGE, TYPE, RENDERER,
- QUIT, CLOSE, DEBUG("d"), QUIET("q"), ARGFILE, NEW, NPP("n++"),
- SUBSTITUTIONS, INITSUBSTITUTIONS, NIL, SPLASH, SETARGFILE, UNSETARGFILE,
- WEBSERVICEDISCOVERY, ALL;
+ WRAP, NOSTRUCTURE, STRUCTURE, STRUCTUREVIEWER, IMAGE, TYPE, FORMAT,
+ OVERWRITE, RENDERER, QUIT, CLOSE, DEBUG("d"), TRACE, QUIET("q"), ARGFILE,
+ NEW, NPP("n++"), SUBSTITUTIONS, INITSUBSTITUTIONS, NIL, SPLASH,
+ SETARGFILE, UNSETARGFILE, WEBSERVICEDISCOVERY, ALL, BACKUPS;
protected static enum Opt
{
IMAGE.setOptions(Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS,
Opt.ALLOWALL, Opt.REQUIREINPUT);
TYPE.setOptions(Opt.STRING, Opt.LINKED, Opt.ALLOWALL);
+ FORMAT.setOptions(Opt.STRING, Opt.LINKED, Opt.ALLOWALL);
RENDERER.setOptions(Opt.STRING, Opt.LINKED, Opt.ALLOWALL);
QUIT.setOptions(Opt.UNARY);
+ OVERWRITE.setOptions(Opt.BOOLEAN, Opt.LINKED, Opt.ALLOWALL);
+ BACKUPS.setOptions(true, Opt.BOOLEAN, Opt.LINKED, Opt.ALLOWALL);
CLOSE.setOptions(Opt.UNARY, Opt.LINKED, Opt.ALLOWALL);
DEBUG.setOptions(Opt.BOOLEAN, Opt.BOOTSTRAP);
+ TRACE.setOptions(Opt.BOOLEAN, Opt.BOOTSTRAP);
QUIET.setOptions(Opt.UNARY, Opt.MULTI, Opt.BOOTSTRAP);
ARGFILE.setOptions(Opt.STRING, Opt.MULTI, Opt.BOOTSTRAP, Opt.GLOB,
Opt.ALLOWSUBSTITUTIONS);
Opt.INCREMENTDEFAULTCOUNTER);
NPP.setOptions(Opt.UNARY, Opt.MULTI, Opt.NOACTION);
SUBSTITUTIONS.setOptions(Opt.BOOLEAN, Opt.MULTI, Opt.NOACTION);
- INITSUBSTITUTIONS.setOptions(Opt.BOOLEAN, Opt.BOOTSTRAP, Opt.NOACTION);
+ INITSUBSTITUTIONS.setOptions(true, Opt.BOOLEAN, Opt.BOOTSTRAP,
+ Opt.NOACTION); // defaulting substitutions to true
NIL.setOptions(Opt.UNARY, Opt.LINKED, Opt.MULTI, Opt.NOACTION);
SETARGFILE.setOptions(Opt.STRING, Opt.MULTI, Opt.PRIVATE, Opt.NOACTION);
UNSETARGFILE.setOptions(Opt.MULTI, Opt.PRIVATE, Opt.NOACTION);
public BackupFiles(File file)
{
classInit();
+ if (file.getParentFile() == null)
+ {
+ // filename probably in pwd represented with no parent -- fix this!
+ file = file.getAbsoluteFile();
+ }
this.file = file;
// add this file from the save in progress stack
if (file != null)
{
String tempfilename = file.getName();
- File tempdir = file.getParentFile();
+ File tempdir = file.getAbsoluteFile().getParentFile();
tempdir.mkdirs();
Console.trace(
"BACKUPFILES [file!=null] attempting to create temp file for "
this.setTempFile(temp);
}
- public static void classInit()
+ private static void classInit()
{
Console.initLogger();
Console.trace("BACKUPFILES classInit");
*/
package jalview.io;
-import java.util.Locale;
-
import java.io.File;
import java.io.IOException;
+import java.util.Locale;
+
+import jalview.bin.Console;
/**
* DOCUMENT ME!
}
} catch (Exception e)
{
- System.err.println("Error whilst identifying " + file);
- e.printStackTrace(System.err);
+ Console.error("Error whilst identifying " + file, e);
emessage = e.getMessage();
}
if (parser != null)
}
} catch (Exception e)
{
- System.err.println("Error whilst identifying " + file);
- e.printStackTrace(System.err);
+ Console.error("Error whilst identifying " + file, e);
emessage = e.getMessage();
}
if (parser != null)
}
} catch (Exception ex)
{
- System.err.println("File Identification failed!\n" + ex);
+ Console.error("File Identification failed!\n" + ex);
throw new FileFormatException(source.errormessage);
}
if (trimmedLength == 0)
{
- System.err.println(
- "File Identification failed! - Empty file was read.");
+ Console.error("File Identification failed! - Empty file was read.");
throw new FileFormatException("EMPTY DATA FILE");
}
- System.out.println("File format identified as " + reply.toString());
+ Console.debug("File format identified as " + reply.toString());
return reply;
}
type = ider.identify(args[i], DataSourceType.FILE);
} catch (FileFormatException e)
{
- System.err.println(
+ Console.error(
String.format("Error '%s' identifying file type for %s",
args[i], e.getMessage()));
}
- System.out.println("Type of " + args[i] + " is " + type);
+ Console.debug("Type of " + args[i] + " is " + type);
}
if (args == null || args.length == 0)
{
- System.err.println("Usage: <Filename> [<Filename> ...]");
+ Console.error("Usage: <Filename> [<Filename> ...]");
}
}
*/
package jalview.log;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public static boolean isLevel(String levelString)
{
- for (LogLevel l : LogLevel.values())
+ for (LogLevel l : EnumSet.allOf(LogLevel.class))
{
if (l.name().equals(levelString))
return true;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import jalview.bin.argparser.Arg;
import jalview.gui.AlignFrame;
import jalview.gui.Desktop;
import jalview.gui.JvOptionPane;
+ testfiles + "/{basename}.png",
new String[]
{ testfiles + "/uniref50.png" } },
- { "--append examples/uniref50.fa --image " + testfiles
- + "/{basename}.png",
+ { "--append examples/uniref50.fa --nosubstitutions --image "
+ + testfiles + "/{basename}.png",
new String[]
{ testfiles + "/{basename}.png" } }
//
}
@Test(groups = "Functional", dataProvider = "allLinkedIdsData")
- public void allLinkedIdsTest(String cmdLine, Arg a, String[] filenames)
+ public void allLinkedIdsTest(String cmdLine, String[] filenames)
{
String[] args = cmdLine.split("\\s+");
Jalview.main(args);
"test/jalview/bin/argparser/testfiles/test3.stk", } },
*/
{ "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close",
- Arg.IMAGE, new String[]
+ new String[]
{ "test/jalview/bin/argparser/testfiles/test1.png",
"test/jalview/bin/argparser/testfiles/test2.png",
"test/jalview/bin/argparser/testfiles/test3.png", } },
+ { "--open=test/jalview/bin/argparser/testfiles/*.fa --all --output={dirname}/{basename}.stk --close",
+ new String[]
+ { "test/jalview/bin/argparser/testfiles/test1.stk",
+ "test/jalview/bin/argparser/testfiles/test2.stk",
+ "test/jalview/bin/argparser/testfiles/test3.stk", } },
//
};
}
import org.testng.Assert;
import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import jalview.gui.AlignFrame;
import jalview.gui.JvOptionPane;
+@Test(singleThreaded = true)
public class BackupFilesTest
{
@BeforeClass(alwaysRun = true)
// check no backup files
File[] backupFiles = getBackupFiles();
- Assert.assertTrue(backupFiles.length == 0);
+ Assert.assertEquals(backupFiles.length, 0, "Number of backup files is "
+ + backupFiles.length + ", not " + 0);
}
// save with no numbers in the backup file names
}
// this deletes the newFile (if it exists) and any saved backup file for it
+ @AfterTest(alwaysRun = true)
@AfterClass(alwaysRun = true)
private void cleanupTmpFiles()
{
newfile.delete();
}
File[] tmpFiles = getBackupFiles(file, mysuffix, mydigits);
+ boolean a = true;
for (int i = 0; i < tmpFiles.length; i++)
{
if (actuallyDeleteTmpFiles)