Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/RemoteInitialiseUser.java

114 lines
4.8 KiB
Java
Raw Normal View History

package Visual_DVM_2021.Passes.All;
2023-09-17 22:13:42 +03:00
import Common.Current;
import Common.Utils.Utils;
import GlobalData.RemoteFile.RemoteFile;
import Visual_DVM_2021.Passes.PassException;
import Visual_DVM_2021.Passes.SSH.ConnectionPass_2023;
2023-12-20 16:56:18 +03:00
import javafx.util.Pair;
2023-09-17 22:13:42 +03:00
import java.io.File;
import java.util.Vector;
public class RemoteInitialiseUser extends ConnectionPass_2023<RemoteFile> {
RemoteFile modulesDirectory;
2023-09-17 22:13:42 +03:00
@Override
protected boolean needsAnimation() {
return true;
}
@Override
protected boolean canStart(Object... args) {
return Current.Check(Log, Current.User);
}
@Override
protected void Connect() throws Exception {
machine = Current.getMachine();
user = Current.getUser();
super.Connect();
}
void put_resource(String res_name, RemoteFile dst_directory) throws Exception {
user.connection.putSingleFile(Utils.CreateTempResourceFile(res_name), new RemoteFile(dst_directory, res_name));
}
2023-12-20 16:56:18 +03:00
void compileModule(String module_name, String flags) throws Exception{
String command = "g++ " + flags+" "+ Utils.DQuotes(module_name + ".cpp") + " -o "+ Utils.DQuotes(module_name);
ShowMessage2(command);
user.connection.performScript(modulesDirectory, command);
RemoteFile binary = new RemoteFile(modulesDirectory, module_name);
if (!user.connection.Exists(binary)){
throw new PassException("Не удалось собрать модуль "+Utils.Brackets(module_name));
}else {
user.connection.sftpChannel.chmod(0777, binary.full_name);
}
2023-09-17 22:13:42 +03:00
}
2023-12-20 16:56:18 +03:00
String getPlannerFlags() throws Exception{
String command = "g++ -v --help 2> /dev/null | sed -n '/^ *-std=\\([^<][^ ]\\+\\).*/ {s//\\1/p}' | grep c++";
System.out.println(command);
Pair<RemoteFile, RemoteFile> res = user.connection.performScript(modulesDirectory, command);
RemoteFile out = res.getKey();
System.out.println(user.connection.readFromFile(out));
return "";
}
2023-09-17 22:13:42 +03:00
@Override
protected void ServerAction() throws Exception {
String workspace_name = Utils.getDateName("visual_sapfor_workspace");
ShowMessage1("Создание рабочего пространства...");
target = new RemoteFile(user.connection.sftpChannel.getHome(), workspace_name);
user.connection.sftpChannel.mkdir(target.full_name);
Vector<RemoteFile> subdirectories = new Vector<>();
subdirectories.add(new RemoteFile(target, "projects"));
subdirectories.add(modulesDirectory = new RemoteFile(target, "modules"));
subdirectories.add(new RemoteFile(target, "tests"));
2023-09-17 22:13:42 +03:00
//-------------------------------------
for (RemoteFile remoteFile : subdirectories)
user.connection.sftpChannel.mkdir(remoteFile.full_name);
2023-09-17 22:13:42 +03:00
//----------------------------------
String[] resourses_names = new String[]{
//--
"Process_r.h",
"starter.cpp",
"launcher.cpp",
//--
"Array.h",
"CompilationSupervisor.h",
"CompilationTask.h",
"File.h",
"Global.h",
"Planner.cpp",
"RunSupervisor.h",
"RunTask.h",
"String.h",
"Supervisor.h",
"Task.h",
"Text.h",
"Utils.h"
2023-09-17 22:13:42 +03:00
};
2023-12-20 16:56:18 +03:00
ShowMessage1("Закачка кода модулей...");
for (String resource_name : resourses_names) {
ShowMessage2(resource_name);
File src = Utils.CreateTempResourceFile(resource_name);
RemoteFile dst = new RemoteFile(modulesDirectory, resource_name);
user.connection.putSingleFile(src, dst);
2023-09-17 22:13:42 +03:00
}
//-------------------------------------
ShowMessage1("Сборка модулей...");
2023-12-20 16:56:18 +03:00
compileModule("launcher","");
compileModule("starter","");
getPlannerFlags();
//compileModule("planner", getPlannerFlags());
/*
2023-09-17 22:13:42 +03:00
//канал на исполнение независим, поэтому переход в папку отдельный
Command(
"cd " + Utils.DQuotes(sftpChannel.pwd()), //нужны ли тут кавычки?
"g++ " + starter_code + " -o " + starter,
"g++ " + launcher_code + " -o " + launcher,
"g++ -O3 -std=c++17 Planner.cpp -o " + planner,
2023-09-17 22:13:42 +03:00
"chmod 0777 " + starter,
"chmod 0777 " + launcher,
"chmod 0777 " + planner
);
*/
2023-09-17 22:13:42 +03:00
//--------------------------------------
RemoteFile info = new RemoteFile(target, Current.getAccount().email);
user.connection.writeToFile("", info);
2023-09-17 22:13:42 +03:00
}
}