add support for path execution, MiB Progress for progressbar

This commit is contained in:
HorizonCode 2022-07-01 10:35:34 +02:00
parent 232f7340f0
commit 724d303433
5 changed files with 24 additions and 18 deletions

View File

@ -1,9 +1,18 @@
import net.horizoncode.sysbackup.cli.CLIProcessor;
import java.io.File;
import java.net.URISyntaxException;
public class Bootstrapper {
public static void main(String[] args) {
public static void main(String[] args) throws URISyntaxException {
File executionPath =
new File(
new File(Bootstrapper.class.getProtectionDomain().getCodeSource().getLocation().toURI())
.getParent());
CLIProcessor cliProcessor = new CLIProcessor();
cliProcessor.startCLI(args);
cliProcessor.startCLI(args, executionPath);
}
}

View File

@ -30,7 +30,7 @@ public class CLIProcessor {
}
}
public void startCLI(String[] args) {
public void startCLI(String[] args, File executionPath) {
try {
if ((args == null) || (args.length == 0)) {
usage();
@ -46,7 +46,7 @@ public class CLIProcessor {
return;
}
String fileName = args[1];
File tasksFolder = new File("tasks");
File tasksFolder = new File(executionPath, "tasks");
if (!tasksFolder.exists())
if (!tasksFolder.mkdir()) System.err.println("Failed to create tasks folder!");
File taskFile = new File(tasksFolder, fileName + ".toml");
@ -56,7 +56,8 @@ public class CLIProcessor {
}
Config taskConfig = new Config(taskFile);
TaskBuilder taskBuilder = TaskBuilder.builder().taskConfig(taskConfig).build();
TaskBuilder taskBuilder =
TaskBuilder.builder().executionPath(executionPath).taskConfig(taskConfig).build();
taskBuilder.start();
break;
}
@ -67,7 +68,7 @@ public class CLIProcessor {
return;
}
String fileName = args[1];
File tasksFolder = new File("tasks");
File tasksFolder = new File(executionPath, "tasks");
if (!tasksFolder.exists())
if (!tasksFolder.mkdir()) System.err.println("Failed to create tasks folder!");
System.out.println("Saving task config " + fileName + ".toml...");
@ -84,7 +85,7 @@ public class CLIProcessor {
return;
}
String fileName = args[1];
File tasksFolder = new File("tasks");
File tasksFolder = new File(executionPath, "tasks");
if (!tasksFolder.exists())
if (!tasksFolder.mkdir()) System.err.println("Failed to create tasks folder!");
File taskFile = new File(tasksFolder, fileName + ".toml");

View File

@ -9,7 +9,6 @@ import org.apache.commons.io.FilenameUtils;
import org.tomlj.TomlArray;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.LinkedBlockingQueue;
@ -23,9 +22,11 @@ public class TaskBuilder {
@Builder.Default private final LinkedBlockingQueue<Task> taskList = new LinkedBlockingQueue<>();
private final File executionPath;
public void start() {
File backupDir = new File("backups");
File backupDir = new File(executionPath, "backups");
if (!backupDir.exists())
if (!backupDir.mkdir()) {
System.err.println("Failed to create backups directory!");

View File

@ -8,12 +8,9 @@ import me.tongfei.progressbar.ProgressBarStyle;
import net.horizoncode.sysbackup.tasks.Task;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.progress.ProgressMonitor;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
@ -96,7 +93,8 @@ public class DatabaseTask extends Task {
new ProgressBarBuilder()
.setStyle(ProgressBarStyle.ASCII)
.setInitialMax(progressMonitor.getTotalWork())
.setTaskName("Adding DB File...");
.setTaskName("Adding DB File...")
.setUnit("MiB", 1048576);
try (ProgressBar pb = pbb.build()) {
while (!progressMonitor.getState().equals(ProgressMonitor.State.READY)) {

View File

@ -3,16 +3,12 @@ package net.horizoncode.sysbackup.tasks.impl;
import me.tongfei.progressbar.ProgressBar;
import me.tongfei.progressbar.ProgressBarBuilder;
import me.tongfei.progressbar.ProgressBarStyle;
import me.tongfei.progressbar.TerminalUtils;
import net.horizoncode.sysbackup.tasks.Task;
import net.horizoncode.sysbackup.threading.ThreadPool;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.progress.ProgressMonitor;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
public class FileSystemTask extends Task {
@ -50,7 +46,8 @@ public class FileSystemTask extends Task {
new ProgressBarBuilder()
.setStyle(ProgressBarStyle.ASCII)
.setInitialMax(progressMonitor.getTotalWork())
.setTaskName("Adding Files...");
.setTaskName("Adding Files...")
.setUnit("MiB", 1048576);
try (ProgressBar pb = pbb.build()) {
while (!progressMonitor.getState().equals(ProgressMonitor.State.READY)) {