Commit bf9e34c8 authored by Andrey Filippov's avatar Andrey Filippov

Added commands to remove old state/log files

parent e24caf8d
......@@ -66,6 +66,13 @@ public class ToolLogFile {
return project.getFolder((logDir==null)?DEFAULT_LOG_FOLDER:logDir);
}
public static String getLinkOutName(String logTool, String logName){
return getBaseLogName(logTool, logName)+OUTPUT_LOG_SUFFIX+"."+LOG_EXTENSION;
}
public static String getLinkErrName(String logTool, String logName){
return getBaseLogName(logTool, logName)+ERROR_LOG_SUFFIX+"."+LOG_EXTENSION;
}
public static String getBaseLogName(String logTool, String logName){
String baseName=logTool;
if ((logName!=null) && (logName.length()>0))baseName+=TOOL_TO_LINE_SEPARATOR+logName;
......@@ -78,6 +85,8 @@ public class ToolLogFile {
return logTool+REGEX_SEP_TO_END;
}
public static String getTimeStamp(String logTool, String name){
if (name==null) return null;
// remove prefix
......
......@@ -102,12 +102,75 @@ public class ToolSequence {
}
toolFinished(null);
}
public void clearStateFiles(){
MessageUI.error("TODO: implement clearStateFiles()");
public Set<IFile> getOldFiles(Set<String> dirs){
IProject project = SelectedResourceManager.getDefault().getSelectedProject(); // should not be null when we got here
Set<String> linkFilesTargets=new HashSet<String>();
Set<IFile> nonLinkFiles=new HashSet<IFile>();
for (String dir:dirs){
IFolder stateDir= project.getFolder(dir);
if (stateDir.exists()){
IResource [] files;
try {
files=stateDir.members();
} catch (CoreException e) {
System.out.println("Error getting member resources in directory "+stateDir.getLocation().toOSString());
continue;
}
for (IResource file:files){
if (file.getType()==IResource.FILE) {
if (file.isLinked()){
// System.out.println("Got linked file: "+file.getLocation().toOSString());
linkFilesTargets.add(file.getRawLocation().toString());
} else {
// System.out.println("Got non=link file: "+file.getLocation().toOSString());
nonLinkFiles.add((IFile) file);
}
}
}
}
}
DEBUG_PRINT("Got "+linkFilesTargets.size()+" links, "+nonLinkFiles.size()+" regular files");
Set<IFile> fileToRemove=new HashSet<IFile>(nonLinkFiles);
for (IFile file:nonLinkFiles){
String fileString=file.getLocation().toString();
for (String linkTarget:linkFilesTargets){
if (linkTarget.equals(fileString)){
fileToRemove.remove(file);
break;
}
}
public void clearLogFiles(){
MessageUI.error("TODO: implement clearLogFiles()");
}
DEBUG_PRINT("Left "+fileToRemove.size()+" to remove:");
for (IFile file:fileToRemove){
DEBUG_PRINT("---- "+file.getLocation().toOSString());
}
return fileToRemove;
}
public Set<String> getStateDirs(){
Set <String> dirs = new HashSet<String>();
for (Tool tool : ToolsCore.getConfig().getContextManager().getToolList()){
String dir=tool.getStateDir();
if (dir!=null){
dirs.add(dir);
}
}
return dirs;
}
public Set<String> getLogDirs(){
Set <String> dirs = new HashSet<String>();
for (Tool tool : ToolsCore.getConfig().getContextManager().getToolList()){
String dir=tool.getLogDir();
if (dir!=null){
dirs.add(dir);
}
}
return dirs;
}
public void setUnfinishedBoot(IMemento memento){
......
......@@ -28,7 +28,7 @@ abstract public class ClearAction extends Action {
private String message;
private static final String[] buttonText = new String[]{"Delete", "Cancel"};
protected static final String[] buttonText = new String[]{"Delete", "Cancel"};
public ClearAction(String message) {
this.message = message;
......
......@@ -16,7 +16,13 @@
*******************************************************************************/
package com.elphel.vdt.ui.views;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import com.elphel.vdt.core.tools.params.ToolSequence;
import com.elphel.vdt.veditor.VerilogPlugin;
public class ClearLogFiles extends ClearAction {
private ToolSequence toolSequence;
......@@ -26,9 +32,40 @@ public class ClearLogFiles extends ClearAction {
this. toolSequence= toolSequence;
}
// public void clear() {
// toolSequence.clearLogFiles();
// }
public void clear() {
toolSequence.clearLogFiles();
String msg="The following files will be deleted:\n\n";
Set<IFile> toRemove=toolSequence.getOldFiles(toolSequence.getLogDirs());
int index=0;
for (IFile file:toRemove){
index++;
// msg+=file.getLocation().toOSString()+"\n";
msg+=file.getName()+"\n";
if (index>25){
msg+="\n... and more";
break;
}
}
if (toRemove.size()==0){
msg="There are no files to be deleted";
}
Shell shell = VerilogPlugin.getActiveWorkbenchShell();
MessageDialog messageBox = new MessageDialog( shell, "Warning", null
, msg
, MessageDialog.QUESTION
, buttonText, 1);
messageBox.open();
if (messageBox.getReturnCode() == 0) {
for (IFile file:toRemove){
try {
file.delete(0,null);
} catch (CoreException e) {
System.out.println("Could not delete "+file.getLocation().toOSString());
}
}
}
}
} // class ContextsAction
......@@ -16,19 +16,52 @@
*******************************************************************************/
package com.elphel.vdt.ui.views;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import com.elphel.vdt.core.tools.params.ToolSequence;
import com.elphel.vdt.veditor.VerilogPlugin;
public class ClearStateFiles extends ClearAction {
private ToolSequence toolSequence;
public ClearStateFiles(String message, ToolSequence toolSequence) {
super(message);
this. toolSequence= toolSequence;
this.toolSequence= toolSequence;
}
public void clear() {
toolSequence.clearStateFiles();
String msg="The following files will be deleted:\n\n";
Set<IFile> toRemove=toolSequence.getOldFiles(toolSequence.getStateDirs());
int index=0;
for (IFile file:toRemove){
index++;
msg+=file.getName()+"\n";
if (index>25){
msg+="\n... and more";
break;
}
}
if (toRemove.size()==0){
msg="There are no files to be deleted";
}
Shell shell = VerilogPlugin.getActiveWorkbenchShell();
MessageDialog messageBox = new MessageDialog( shell, "Warning", null
, msg
, MessageDialog.QUESTION
, buttonText, 1);
messageBox.open();
if (messageBox.getReturnCode() == 0) {
for (IFile file:toRemove){
try {
file.delete(0,null);
} catch (CoreException e) {
System.out.println("Could not delete "+file.getLocation().toOSString());
}
}
}
}
} // class ContextsAction
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment