mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Fixes for shells
This commit is contained in:
parent
c15c1204f0
commit
1982661aa1
10 changed files with 78 additions and 42 deletions
|
@ -47,7 +47,7 @@ public interface OsType {
|
|||
|
||||
@Override
|
||||
public String getTempDirectory(ShellProcessControl pc) throws Exception {
|
||||
return pc.executeSimpleCommand(ShellTypes.CMD, pc.getShellType().getPrintVariableCommand("TEMP"));
|
||||
return pc.executeSimpleCommand(ShellTypes.CMD, ShellTypes.CMD.getPrintVariableCommand("TEMP"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,7 +111,7 @@ public interface OsType {
|
|||
@Override
|
||||
public String determineOperatingSystemName(ShellProcessControl pc) throws Exception {
|
||||
try (CommandProcessControl c =
|
||||
pc.command(ShellTypes.SH, "lsb_release -a").start()) {
|
||||
pc.command("lsb_release -a").start()) {
|
||||
var text = c.readOnlyStdout();
|
||||
if (c.getExitCode() == 0) {
|
||||
return PropertiesFormatsParser.parse(text, ":").getOrDefault("Description", null);
|
||||
|
@ -119,7 +119,7 @@ public interface OsType {
|
|||
}
|
||||
|
||||
try (CommandProcessControl c =
|
||||
pc.command(ShellTypes.SH, "cat /etc/*release").start()) {
|
||||
pc.command("cat /etc/*release").start()) {
|
||||
var text = c.readOnlyStdout();
|
||||
if (c.getExitCode() == 0) {
|
||||
return PropertiesFormatsParser.parse(text, "=").getOrDefault("PRETTY_NAME", null);
|
||||
|
@ -127,7 +127,7 @@ public interface OsType {
|
|||
}
|
||||
|
||||
String type = "Unknown";
|
||||
try (CommandProcessControl c = pc.command(ShellTypes.SH, "uname -o").start()) {
|
||||
try (CommandProcessControl c = pc.command("uname -o").start()) {
|
||||
var text = c.readOnlyStdout();
|
||||
if (c.getExitCode() == 0) {
|
||||
type = text.strip();
|
||||
|
@ -135,7 +135,7 @@ public interface OsType {
|
|||
}
|
||||
|
||||
String version = "?";
|
||||
try (CommandProcessControl c = pc.command(ShellTypes.SH, "uname -r").start()) {
|
||||
try (CommandProcessControl c = pc.command("uname -r").start()) {
|
||||
var text = c.readOnlyStdout();
|
||||
if (c.getExitCode() == 0) {
|
||||
version = text.strip();
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface ShellProcessControl extends ProcessControl {
|
||||
|
||||
|
@ -30,7 +29,9 @@ public interface ShellProcessControl extends ProcessControl {
|
|||
}
|
||||
|
||||
default String executeSimpleCommand(ShellType type, String command) throws Exception {
|
||||
return executeSimpleCommand(type.switchTo(command));
|
||||
try (var sub = subShell(type).start()) {
|
||||
return sub.executeSimpleCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
void restart() throws Exception;
|
||||
|
@ -53,13 +54,8 @@ public interface ShellProcessControl extends ProcessControl {
|
|||
return subShell(type.openCommand()).elevation(getElevationPassword());
|
||||
}
|
||||
|
||||
default CommandProcessControl command(@NonNull ShellType type, String command) {
|
||||
return command(type.switchTo(command));
|
||||
}
|
||||
|
||||
default ShellProcessControl subShell(@NonNull List<String> command) {
|
||||
return subShell(
|
||||
command.stream().map(s -> s.contains(" ") ? "\"" + s + "\"" : s).collect(Collectors.joining(" ")));
|
||||
return subShell(shellProcessControl -> shellProcessControl.getShellType().flatten(command));
|
||||
}
|
||||
|
||||
default ShellProcessControl subShell(@NonNull String command) {
|
||||
|
|
|
@ -23,16 +23,15 @@ public interface ShellType {
|
|||
String getOpenWithInitFileCommand(String file);
|
||||
|
||||
default String flatten(List<String> command) {
|
||||
return command.stream().map(s -> s.contains(" ") && !(s.startsWith("\"") && s.endsWith("\"")) ? "\"" + s + "\"" : s).collect(Collectors.joining(" "));
|
||||
return command.stream()
|
||||
.map(s -> s.contains(" ") && !(s.startsWith("\"") && s.endsWith("\"")) ? "\"" + s + "\"" : s)
|
||||
.collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
|
||||
default String joinCommands(String... s) {
|
||||
return String.join(getConcatenationOperator(), s);
|
||||
}
|
||||
|
||||
String escape(String input);
|
||||
|
||||
void elevate(ShellProcessControl control, String command, String displayCommand) throws Exception;
|
||||
|
||||
default String getExitCommand() {
|
||||
|
@ -57,13 +56,21 @@ public interface ShellType {
|
|||
|
||||
String elevateConsoleCommand(ShellProcessControl control, String command);
|
||||
|
||||
default String getScriptEchoCommand(String s) {
|
||||
return getEchoCommand(s, false);
|
||||
}
|
||||
|
||||
String getEchoCommand(String s, boolean toErrorStream);
|
||||
|
||||
String queryShellProcessId(ShellProcessControl control) throws Exception;
|
||||
|
||||
String getSetVariableCommand(String variableName, String value);
|
||||
|
||||
String getPrintVariableCommand(String name);
|
||||
default String getPrintVariableCommand(String name) {
|
||||
return getPrintVariableCommand("", name);
|
||||
}
|
||||
|
||||
String getPrintVariableCommand(String prefix, String name);
|
||||
|
||||
List<String> openCommand();
|
||||
|
||||
|
|
|
@ -1,28 +1,14 @@
|
|||
package io.xpipe.core.store;
|
||||
|
||||
import io.xpipe.core.process.ShellProcessControl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface MachineStore extends FileSystemStore, ShellStore {
|
||||
|
||||
@Override
|
||||
default void validate() throws Exception {
|
||||
try (ShellProcessControl pc = create().start()) {}
|
||||
}
|
||||
|
||||
public default boolean isLocal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public default String queryMachineName() throws Exception {
|
||||
try (var pc = create().start()) {
|
||||
var operatingSystem = pc.getOsType();
|
||||
return operatingSystem.determineOperatingSystemName(pc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public default InputStream openInput(String file) throws Exception {
|
||||
return create().commandListFunction(proc -> proc.getShellType().createFileReadCommand(proc.getOsType().normalizeFileName(file)))
|
||||
|
|
|
@ -21,4 +21,15 @@ public interface ShellStore extends DataStore {
|
|||
return pc.getShellType();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
default void validate() throws Exception {
|
||||
try (ShellProcessControl pc = create().start()) {}
|
||||
}
|
||||
|
||||
public default String queryMachineName() throws Exception {
|
||||
try (var pc = create().start()) {
|
||||
var operatingSystem = pc.getOsType();
|
||||
return operatingSystem.determineOperatingSystemName(pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@ import java.io.IOException;
|
|||
public class XPipeProxy {
|
||||
|
||||
public static void checkSupport(ShellStore store) throws Exception {
|
||||
if (store == null || ShellStore.isLocal(store)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var version = XPipeDaemon.getInstance().getVersion();
|
||||
try (ShellProcessControl s = store.create().start()) {
|
||||
var defaultInstallationExecutable = FileNames.join(
|
||||
|
|
|
@ -1,30 +1,28 @@
|
|||
package io.xpipe.extension.fxcomps.impl;
|
||||
|
||||
import io.xpipe.core.store.ShellStore;
|
||||
import io.xpipe.extension.XPipeProxy;
|
||||
import io.xpipe.extension.fxcomps.SimpleComp;
|
||||
import io.xpipe.extension.util.SimpleValidator;
|
||||
import io.xpipe.extension.util.Validatable;
|
||||
import io.xpipe.extension.util.Validator;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.scene.layout.Region;
|
||||
import net.synedra.validatorfx.Check;
|
||||
|
||||
public class ProxyChoiceComp extends SimpleComp implements Validatable {
|
||||
|
||||
private final Property<ShellStore> selected;
|
||||
private final Validator validator = new SimpleValidator();
|
||||
private final Check check;
|
||||
// private final Check check;
|
||||
|
||||
public ProxyChoiceComp(Property<ShellStore> selected) {
|
||||
this.selected = selected;
|
||||
check = Validator.exceptionWrapper(validator, selected, () -> XPipeProxy.checkSupport(selected.getValue()));
|
||||
// check = Validator.exceptionWrapper(validator, selected, () -> XPipeProxy.checkSupport(selected.getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Region createSimple() {
|
||||
var choice = new ShellStoreChoiceComp<>(selected, ShellStore.class, shellStore -> true, shellStore -> true);
|
||||
choice.apply(struc -> check.decorates(struc.get()));
|
||||
var choice = new ShellStoreChoiceComp<>(null, selected, ShellStore.class, shellStore -> true);
|
||||
// choice.apply(struc -> check.decorates(struc.get()));
|
||||
return choice.createRegion();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@ TODO: Integrate store validation more into this comp.
|
|||
@AllArgsConstructor
|
||||
public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
|
||||
|
||||
private final T self;
|
||||
private final Property<T> selected;
|
||||
private final Class<T> storeClass;
|
||||
private final Predicate<T> applicableCheck;
|
||||
private final Predicate<T> supportCheck;
|
||||
|
||||
private Region createGraphic(T s) {
|
||||
var provider = DataStoreProviders.byStore(s);
|
||||
|
@ -80,6 +80,7 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
|
|||
var available = Stream.concat(
|
||||
Stream.of(new LocalStore()),
|
||||
XPipeDaemon.getInstance().getNamedStores().stream()
|
||||
.filter(s -> s != self)
|
||||
.filter(s -> storeClass.isAssignableFrom(s.getClass()) && applicableCheck.test((T) s))
|
||||
.map(s -> (ShellStore) s))
|
||||
.toList();
|
||||
|
|
|
@ -8,9 +8,21 @@ import java.util.function.IntFunction;
|
|||
|
||||
public class DataStoreFormatter {
|
||||
|
||||
public static String formatSubHost(IntFunction<String> func, DataStore at, int length) {
|
||||
var atString = at instanceof ShellStore shellStore && !ShellStore.isLocal(shellStore)
|
||||
? XPipeDaemon.getInstance().getStoreName(at).orElse(null)
|
||||
: null;
|
||||
if (atString == null) {
|
||||
return func.apply(length);
|
||||
}
|
||||
|
||||
var fileString = func.apply(length - atString.length() - 1);
|
||||
return String.format("%s/%s", atString, fileString);
|
||||
}
|
||||
|
||||
public static String formatAtHost(IntFunction<String> func, DataStore at, int length) {
|
||||
var atString = at instanceof ShellStore shellStore && !ShellStore.isLocal(shellStore)
|
||||
? DataStoreProviders.byStore(at).toSummaryString(at, length)
|
||||
? XPipeDaemon.getInstance().getStoreName(at).orElse(null)
|
||||
: null;
|
||||
if (atString == null) {
|
||||
return func.apply(length);
|
||||
|
@ -20,7 +32,22 @@ public class DataStoreFormatter {
|
|||
return String.format("%s @ %s", fileString, atString);
|
||||
}
|
||||
|
||||
public static String format(DataStore input, int length) {
|
||||
public static String formatViaProxy(IntFunction<String> func, DataStore at, int length) {
|
||||
var atString = at instanceof ShellStore shellStore && !ShellStore.isLocal(shellStore)
|
||||
? XPipeDaemon.getInstance().getStoreName(at).orElse(null)
|
||||
: null;
|
||||
if (atString == null) {
|
||||
return func.apply(length);
|
||||
}
|
||||
|
||||
var fileString = func.apply(length - atString.length() - 4);
|
||||
return String.format("%s -> %s", atString, fileString);
|
||||
}
|
||||
|
||||
public static String toName(DataStore input) {
|
||||
return toName(input, Integer.MAX_VALUE);
|
||||
}
|
||||
public static String toName(DataStore input, int length) {
|
||||
var named = XPipeDaemon.getInstance().getStoreName(input);
|
||||
if (named.isPresent()) {
|
||||
return cut(named.get(), length);
|
||||
|
@ -29,6 +56,11 @@ public class DataStoreFormatter {
|
|||
return DataStoreProviders.byStore(input).toSummaryString(input, length);
|
||||
}
|
||||
|
||||
public static String split(String left, String separator, String right, int length) {
|
||||
var half = (length / 2) - separator.length();
|
||||
return cut(left, half) + separator + cut(right, length - half);
|
||||
}
|
||||
|
||||
public static String cut(String input, int length) {
|
||||
if (input == null) {
|
||||
return "";
|
||||
|
@ -54,7 +86,7 @@ public class DataStoreFormatter {
|
|||
var region = split[2];
|
||||
var lengthShare = (length - 3) / 2;
|
||||
return String.format(
|
||||
"%s @ %s",
|
||||
"%s.%s",
|
||||
DataStoreFormatter.cut(name, lengthShare), DataStoreFormatter.cut(region, length - lengthShare));
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ missingStore=$NAME$ does not exist
|
|||
namedHostFeatureUnsupported=$HOST$ does not support this feature
|
||||
namedHostNotActive=$HOST$ is not active
|
||||
noInformationAvailable=No information available
|
||||
localMachine=Local Machine
|
||||
input=Input
|
||||
output=Output
|
||||
inout=Input and Output
|
||||
|
|
Loading…
Reference in a new issue