diff --git a/src/files/Planner/Array.h b/src/files/Planner/Array.h index 492f57e4..8ed85af6 100644 --- a/src/files/Planner/Array.h +++ b/src/files/Planner/Array.h @@ -1,37 +1,37 @@ -#pragma once - -#include -#include -#include -#include - -template -class Array { -private: - std::vector elements; - -public: - Array() { } - - virtual ~Array() { - for (auto& elem : elements) - delete elem; - elements.clear(); - } - - void add(T* new_line) { - elements.push_back(new_line); - } - - long getLength() const { - return (long)elements.size(); - } - - T* get(long i) { - return elements[i]; - } - - const std::vector& getElements() const { - return elements; - } +#pragma once + +#include +#include +#include +#include + +template +class Array { +private: + std::vector elements; + +public: + Array() { } + + virtual ~Array() { + for (auto& elem : elements) + delete elem; + elements.clear(); + } + + void add(T* new_line) { + elements.push_back(new_line); + } + + long getLength() const { + return (long)elements.size(); + } + + T* get(long i) { + return elements[i]; + } + + const std::vector& getElements() const { + return elements; + } }; \ No newline at end of file diff --git a/src/files/Planner/CompilationSupervisor.h b/src/files/Planner/CompilationSupervisor.h index 4bc7b44f..4694fe65 100644 --- a/src/files/Planner/CompilationSupervisor.h +++ b/src/files/Planner/CompilationSupervisor.h @@ -1,24 +1,24 @@ -#pragma once - -#include "Supervisor.h" -#include "CompilationTask.h" - -class CompilationSupervisor : public Supervisor { -public: - CompilationSupervisor() { - this->init("compilationTasks", 4); - } - - CompilationTask* getTaskById(long task_id) { - for (long i = 0; i < getLength(); ++i) { - CompilationTask* task = get(i); - if (task->getId() == task_id) - return task; - } - return NULL; - } - - String getStatePrefix() override { - return String("Compilation"); - } +#pragma once + +#include "Supervisor.h" +#include "CompilationTask.h" + +class CompilationSupervisor : public Supervisor { +public: + CompilationSupervisor() { + this->init("compilationTasks", 4); + } + + CompilationTask* getTaskById(long task_id) { + for (long i = 0; i < getLength(); ++i) { + CompilationTask* task = get(i); + if (task->getId() == task_id) + return task; + } + return NULL; + } + + String getStatePrefix() override { + return String("Compilation"); + } }; \ No newline at end of file diff --git a/src/files/Planner/CompilationTask.h b/src/files/Planner/CompilationTask.h index 588eb909..555180c0 100644 --- a/src/files/Planner/CompilationTask.h +++ b/src/files/Planner/CompilationTask.h @@ -1,51 +1,52 @@ -#pragma once - -#include "Task.h" -#include "Text.h" - -class CompilationTask : public Task { - String test_id; - String makefile_text; -public: - void setTestId(String* test_id_in) { - test_id = String(test_id_in->getCharArray()); - } - void setMakefileText(String* makefile_text_in) { - makefile_text = String(makefile_text_in->getCharArray(), '|'); - } - virtual void print() const { - printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime, - test_id.getCharArray()); - printf("makefile_text=%s\n", makefile_text.getCharArray()); - } - - CompilationTask(Text* lines, int offset) :Task(lines, offset) { - setTestId(lines->get(offset + 2)); - setMakefileText(lines->get(offset + 3)); - setState(Waiting); - kernels = 1; - } - - virtual void prepareWorkspace() { - String makeFilePath = String(id) + "/Makefile"; - File makeFileFile = File(makeFilePath, this->makefile_text); - String tests = userWorkspace + "/projects"; - String testPath = tests + "/" + test_id; - Utils::CopyDirectory(testPath, workspace); - } - virtual String getLaunchScriptText() { - String modules = userWorkspace + "/modules"; - String starterCall = modules + "/starter"; - String launcherCall = modules + "/launcher"; - return String::DQuotes(starterCall) + " " + - String::DQuotes(launcherCall) + " " + - String(maxtime) + " " + - String::DQuotes("") + " " + - "make -j -f Makefile"; - } - virtual void analyseResults() { - Task::analyseResults(); - String binary = workspace + "/0"; - state = Utils::Exists(binary) ? Done : DoneWithErrors; - } +#pragma once + +#include "Task.h" +#include "Text.h" + +class CompilationTask : public Task { + String test_id; + String makefile_text; +public: + void setTestId(String* test_id_in) { + test_id = String(test_id_in->getCharArray()); + } + + void setMakefileText(String* makefile_text_in) { + makefile_text = String(makefile_text_in->getCharArray(), '|'); + } + + virtual void print() const { + printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime, test_id.getCharArray()); + printf("makefile_text=%s\n", makefile_text.getCharArray()); + } + + CompilationTask(Text* lines, int offset) :Task(lines, offset) { + setTestId(lines->get(offset + 2)); + setMakefileText(lines->get(offset + 3)); + setState(Waiting); + kernels = 1; + } + + virtual void prepareWorkspace() { + String makeFilePath = String(id) + "/Makefile"; + File makeFileFile = File(makeFilePath, this->makefile_text); + String tests = userWorkspace + "/projects"; + String testPath = tests + "/" + test_id; + Utils::CopyDirectory(testPath, workspace); + } + virtual String getLaunchScriptText() { + String modules = userWorkspace + "/modules"; + String starterCall = modules + "/starter"; + String launcherCall = modules + "/launcher"; + return String::DQuotes(starterCall) + " " + + String::DQuotes(launcherCall) + " " + + String(maxtime) + " " + + String::DQuotes("") + " " + + "make -j -f Makefile"; + } + virtual void analyseResults() { + Task::analyseResults(); + String binary = workspace + "/0"; + state = Utils::Exists(binary) ? Done : DoneWithErrors; + } }; \ No newline at end of file diff --git a/src/files/Planner/File.h b/src/files/Planner/File.h index fbac2fb4..d0f7a127 100644 --- a/src/files/Planner/File.h +++ b/src/files/Planner/File.h @@ -1,70 +1,70 @@ -#pragma once -#include "String.h" -#include "Text.h" - -class File { - FILE* ptr; -public: - File(String* name) { - ptr = fopen(name->getCharArray(), "r"); - } - File(const char* name) { - ptr = fopen(name, "r"); - } - File(const String& name, const String& text) { - ptr = fopen(name.getCharArray(), "w"); - fprintf(ptr, "%s", text.getCharArray()); - } - ~File() { - Close(); - } - void Close() { - if (ptr != NULL) { - fclose(ptr); - ptr = NULL; - } - } - Text* readLines() { - Text* lines = new Text(); - int c; - String* line = NULL; - bool lineStarted = false; - do { - c = fgetc(ptr); - if (lineStarted) { - switch (c) { - case '\r': - break; - case '\n': - case EOF: - lines->add(line); - line = NULL; - lineStarted = false; - break; - default: - line->addChar((char)c); - break; - } - } - else { - switch (c) { - case '\r': - break; - case '\n': - line = new String(); - lines->add(line); - line = NULL; - break; - case EOF: - break; - default: - line = new String(); - line->addChar((char)c); - lineStarted = true; - break; - } - } - } while (c != EOF); - return lines; - } +#pragma once +#include "String.h" +#include "Text.h" + +class File { + FILE* ptr; +public: + File(String* name) { + ptr = fopen(name->getCharArray(), "r"); + } + File(const char* name) { + ptr = fopen(name, "r"); + } + File(const String& name, const String& text) { + ptr = fopen(name.getCharArray(), "w"); + fprintf(ptr, "%s", text.getCharArray()); + } + ~File() { + Close(); + } + void Close() { + if (ptr != NULL) { + fclose(ptr); + ptr = NULL; + } + } + Text* readLines() { + Text* lines = new Text(); + int c; + String* line = NULL; + bool lineStarted = false; + do { + c = fgetc(ptr); + if (lineStarted) { + switch (c) { + case '\r': + break; + case '\n': + case EOF: + lines->add(line); + line = NULL; + lineStarted = false; + break; + default: + line->addChar((char)c); + break; + } + } + else { + switch (c) { + case '\r': + break; + case '\n': + line = new String(); + lines->add(line); + line = NULL; + break; + case EOF: + break; + default: + line = new String(); + line->addChar((char)c); + lineStarted = true; + break; + } + } + } while (c != EOF); + return lines; + } }; \ No newline at end of file diff --git a/src/files/Planner/Global.h b/src/files/Planner/Global.h index a3ce0faf..57f4e71a 100644 --- a/src/files/Planner/Global.h +++ b/src/files/Planner/Global.h @@ -1,10 +1,10 @@ -#pragma once - -#include "String.h" - -String userWorkspace; -String packageWorkspace; -int maxKernels; -int busyKernels; -int freeKernels; -String dvm_drv; +#pragma once + +#include "String.h" + +String userWorkspace; +String packageWorkspace; +int maxKernels; +int busyKernels; +int freeKernels; +String dvm_drv; diff --git a/src/files/Planner/Planner.cpp b/src/files/Planner/Planner.cpp index a00e9ae0..22a08e0d 100644 --- a/src/files/Planner/Planner.cpp +++ b/src/files/Planner/Planner.cpp @@ -1,134 +1,145 @@ -#define _CRT_SECURE_NO_WARNINGS -using namespace std; - -#if __cplusplus >= 201703L -#include -#else -#include -#endif - -#include "CompilationSupervisor.h" -#include "RunSupervisor.h" -#include "Global.h" -#include - -//https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D0%B3%D0%BD%D0%B0%D0%BB_(Unix) -void hdl(int sig) -{ - String file_name = "GOT_SIGNAL_AT_"+ String(Utils::getAbsoluteTime()); - FILE * res = fopen(file_name.getCharArray(),"w"); - fprintf(res,"%d\n", sig); - fclose(res); -} -void set_handlers() { -#ifndef _WIN32 - struct sigaction act; - memset(&act, 0, sizeof(act)); - act.sa_handler = hdl; - sigset_t set; - sigemptyset(&set); - //--- - sigaddset(&set, SIGABRT); - sigaddset(&set, SIGALRM); - sigaddset(&set, SIGBUS); - sigaddset(&set, SIGVTALRM); - sigaddset(&set, SIGFPE); - sigaddset(&set, SIGHUP); - sigaddset(&set, SIGILL); - sigaddset(&set, SIGINT); - sigaddset(&set, SIGPIPE); - sigaddset(&set, SIGQUIT); - sigaddset(&set, SIGSEGV); - sigaddset(&set, SIGTERM); - sigaddset(&set, SIGTSTP); - sigaddset(&set, SIGTTIN); - sigaddset(&set, SIGTTOU); - sigaddset(&set, SIGUSR1); - sigaddset(&set, SIGUSR2); - sigaddset(&set, SIGPOLL); - sigaddset(&set, SIGPROF); - sigaddset(&set, SIGSYS); - sigaddset(&set, SIGTRAP); - //sigaddset(&set, SIGURG); - //sigaddset(&set, SIGCHLD); - //sigaddset(&set, SIGCONT); - sigaddset(&set, SIGVTALRM); - sigaddset(&set, SIGXCPU); - sigaddset(&set, SIGXFSZ); - //--- - act.sa_mask = set; - //--- - sigaction(SIGABRT, &act, 0); - sigaction(SIGALRM, &act, 0); - sigaction(SIGBUS, &act, 0); - sigaction(SIGVTALRM, &act, 0); - sigaction(SIGFPE, &act, 0); - sigaction(SIGHUP, &act, 0); - sigaction(SIGILL, &act, 0); - sigaction(SIGINT, &act, 0); - sigaction(SIGPIPE, &act, 0); - sigaction(SIGQUIT, &act, 0); - sigaction(SIGSEGV, &act, 0); - sigaction(SIGTERM, &act, 0); - sigaction(SIGTSTP, &act, 0); - sigaction(SIGTTIN, &act, 0); - sigaction(SIGTTOU, &act, 0); - sigaction(SIGUSR1, &act, 0); - sigaction(SIGUSR2, &act, 0); - sigaction(SIGPOLL, &act, 0); - sigaction(SIGPROF, &act, 0); - sigaction(SIGSYS, &act, 0); - sigaction(SIGTRAP, &act, 0); - sigaction(SIGVTALRM, &act, 0); - sigaction(SIGXCPU, &act, 0); - sigaction(SIGXFSZ, &act, 0); -#endif -} - -int main(int argc, char ** argv) -{ - //+ - set_handlers(); - //- - userWorkspace = String(argv[1]); - packageWorkspace = String(argv[2]); - maxKernels = atoi(argv[3]); - dvm_drv = String(argv[4]); - //-- - freeKernels = maxKernels; - busyKernels= 0; - //-- - -#if __cplusplus >= 201703L - std::filesystem::current_path(packageWorkspace.getCharArray()); -#else - chdir(packageWorkspace.getCharArray()); -#endif - - userWorkspace.println(); - packageWorkspace.println(); - printf("%d\n", maxKernels); -#ifndef _WIN32 - int pid = getpid(); -#else - int pid = _getpid(); -#endif - - printf("PID=%d\n", pid); - File pidFile("PID", String(pid)+"\n"); - pidFile.Close(); - //--- - File startFile("STARTED", "+"); - startFile.Close(); - //--- - printf(">>>>\n"); - CompilationSupervisor * compilationSupervisor = new CompilationSupervisor(); - printf("%ld\n", compilationSupervisor->getLength()); - compilationSupervisor->DoWithSchedule(maxKernels); - - RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor); - printf("%ld\n", runSupervisor->getLength()); - runSupervisor->print(); - runSupervisor->DoWithSchedule(maxKernels); - return 0; -} +#define _CRT_SECURE_NO_WARNINGS +using namespace std; + +#if __cplusplus >= 201703L +#include +#else +#include +#endif + +#include "CompilationSupervisor.h" +#include "RunSupervisor.h" +#include "Global.h" +#include + +//https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D0%B3%D0%BD%D0%B0%D0%BB_(Unix) +void hdl(int sig) +{ + String file_name = "GOT_SIGNAL_AT_"+ String(Utils::getAbsoluteTime()); + FILE * res = fopen(file_name.getCharArray(),"w"); + fprintf(res, "%d\n", sig); + fclose(res); +} +void set_handlers() { +#ifndef _WIN32 + struct sigaction act; + memset(&act, 0, sizeof(act)); + act.sa_handler = hdl; + sigset_t set; + sigemptyset(&set); + //--- + sigaddset(&set, SIGABRT); + sigaddset(&set, SIGALRM); + sigaddset(&set, SIGBUS); + sigaddset(&set, SIGVTALRM); + sigaddset(&set, SIGFPE); + sigaddset(&set, SIGHUP); + sigaddset(&set, SIGILL); + sigaddset(&set, SIGINT); + sigaddset(&set, SIGPIPE); + sigaddset(&set, SIGQUIT); + sigaddset(&set, SIGSEGV); + sigaddset(&set, SIGTERM); + sigaddset(&set, SIGTSTP); + sigaddset(&set, SIGTTIN); + sigaddset(&set, SIGTTOU); + sigaddset(&set, SIGUSR1); + sigaddset(&set, SIGUSR2); + sigaddset(&set, SIGPOLL); + sigaddset(&set, SIGPROF); + sigaddset(&set, SIGSYS); + sigaddset(&set, SIGTRAP); + //sigaddset(&set, SIGURG); + //sigaddset(&set, SIGCHLD); + //sigaddset(&set, SIGCONT); + sigaddset(&set, SIGVTALRM); + sigaddset(&set, SIGXCPU); + sigaddset(&set, SIGXFSZ); + //--- + act.sa_mask = set; + //--- + sigaction(SIGABRT, &act, 0); + sigaction(SIGALRM, &act, 0); + sigaction(SIGBUS, &act, 0); + sigaction(SIGVTALRM, &act, 0); + sigaction(SIGFPE, &act, 0); + sigaction(SIGHUP, &act, 0); + sigaction(SIGILL, &act, 0); + sigaction(SIGINT, &act, 0); + sigaction(SIGPIPE, &act, 0); + sigaction(SIGQUIT, &act, 0); + sigaction(SIGSEGV, &act, 0); + sigaction(SIGTERM, &act, 0); + sigaction(SIGTSTP, &act, 0); + sigaction(SIGTTIN, &act, 0); + sigaction(SIGTTOU, &act, 0); + sigaction(SIGUSR1, &act, 0); + sigaction(SIGUSR2, &act, 0); + sigaction(SIGPOLL, &act, 0); + sigaction(SIGPROF, &act, 0); + sigaction(SIGSYS, &act, 0); + sigaction(SIGTRAP, &act, 0); + sigaction(SIGVTALRM, &act, 0); + sigaction(SIGXCPU, &act, 0); + sigaction(SIGXFSZ, &act, 0); +#endif +} + +int main(int argc, char ** argv) +{ + //+ + set_handlers(); + //- + userWorkspace = String(argv[1]); + packageWorkspace = String(argv[2]); + maxKernels = atoi(argv[3]); + dvm_drv = String(argv[4]); + //-- + freeKernels = maxKernels; + busyKernels= 0; + //-- + +#if __cplusplus >= 201703L + std::filesystem::current_path(packageWorkspace.getCharArray()); +#else + chdir(packageWorkspace.getCharArray()); +#endif + +#if DEB + userWorkspace.println(); + packageWorkspace.println(); + printf("%d\n", maxKernels); +#endif + +#ifndef _WIN32 + int pid = getpid(); +#else + int pid = _getpid(); +#endif + +#if DEB + printf("PID=%d\n", pid); +#endif + File pidFile("PID", String(pid)+"\n"); + pidFile.Close(); + //--- + File startFile("STARTED", "+"); + startFile.Close(); + //--- +#if DEB + printf(">>>>\n"); +#endif + CompilationSupervisor * compilationSupervisor = new CompilationSupervisor(); +#if DEB + printf("%ld\n", compilationSupervisor->getLength()); +#endif + compilationSupervisor->DoWithSchedule(maxKernels); + + RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor); +#if DEB + printf("%ld\n", runSupervisor->getLength()); + runSupervisor->print(); +#endif + runSupervisor->DoWithSchedule(maxKernels); + return 0; +} diff --git a/src/files/Planner/RunSupervisor.h b/src/files/Planner/RunSupervisor.h index c3fdfd7c..abac0fc2 100644 --- a/src/files/Planner/RunSupervisor.h +++ b/src/files/Planner/RunSupervisor.h @@ -1,26 +1,25 @@ -#pragma once - -#include "CompilationSupervisor.h" -#include "RunTask.h" - -class RunSupervisor : public Supervisor { -public: - RunSupervisor(CompilationSupervisor* compilationSupervisor) { - this->init("runTasks", 8); - //проверить отмененные задачи. - for (long i = 0; i < getLength(); ++i) { - RunTask* task = this->get(i); - CompilationTask* parent = compilationSupervisor->getTaskById(task->getTestCompilationTaskId()); - task->setState((parent->getState() == Done) ? Waiting : Canceled); - task->setParent(parent); - printf("id=%ld; parent_id = %ld; state=%s\n", - task->getId(), - task->getParent()->getId(), - task->printState().getCharArray()); - } - } - - String getStatePrefix() override { - return String("Running"); - } -}; +#pragma once + +#include "CompilationSupervisor.h" +#include "RunTask.h" + +class RunSupervisor : public Supervisor { +public: + RunSupervisor(CompilationSupervisor* compilationSupervisor) { + this->init("runTasks", 8); + //проверить отмененные задачи. + for (long i = 0; i < getLength(); ++i) { + RunTask* task = this->get(i); + CompilationTask* parent = compilationSupervisor->getTaskById(task->getTestCompilationTaskId()); + task->setState((parent->getState() == Done) ? Waiting : Canceled); + task->setParent(parent); +#if DEB + printf("id=%ld; parent_id = %ld; state=%s\n", task->getId(), task->getParent()->getId(), task->printState().getCharArray()); +#endif + } + } + + String getStatePrefix() override { + return String("Running"); + } +}; diff --git a/src/files/Planner/RunTask.h b/src/files/Planner/RunTask.h index 8f8da661..5a40e980 100644 --- a/src/files/Planner/RunTask.h +++ b/src/files/Planner/RunTask.h @@ -1,109 +1,111 @@ -#pragma once - -#include "CompilationTask.h" - -class RunTask : public Task { - long testcompilationtask_id; - String binary_name; - String matrix; - String environments; - String usr_par; - String args; - CompilationTask* parent; -public: - void print() const override { - printf("id=%ld; maxtime=%d; testcompilationtask_id=%ld; matrix=%s; environments=%s; usr_par=%s; args=%s kernels=%d\n", - id, - maxtime, - testcompilationtask_id, - matrix.getCharArray(), - environments.getCharArray(), - usr_par.getCharArray(), - args.getCharArray(), - kernels - ); - } - int setKernels(String* kernels_s) { - return kernels = atoi(kernels_s->getCharArray()); - } - long setTestCompilationTaskId(String* id_s) { - return testcompilationtask_id = strtol(id_s->getCharArray(), NULL, 10); - } - long getTestCompilationTaskId() { - return testcompilationtask_id; - } - void setMatrix(String* matrix_in) { - matrix = String(matrix_in->getCharArray()); - } - void setEnvironments(String* environments_in) { - environments = String(environments_in->getCharArray()); - } - void setUsrPar(String* usr_par_in) { - usr_par = String(usr_par_in->getCharArray(), '|'); - } - void setArgs(String* args_in) { - args = String(args_in->getCharArray()); - } - void setParent(CompilationTask* parent_in) { - parent = parent_in; - binary_name = "spf_" + String(id) + "_" + matrix.Replace(' ', '_'); - } - CompilationTask* getParent() { - return parent; - } - RunTask(Text* lines, int offset) :Task(lines, offset) { - setTestCompilationTaskId(lines->get(offset + 2)); - setMatrix(lines->get(offset + 3)); - setEnvironments(lines->get(offset + 4)); - setUsrPar(lines->get(offset + 5)); - setArgs(lines->get(offset + 6)); - setKernels(lines->get(offset + 7)); - } - - String getLaunchScriptText() override { - String modules = userWorkspace + "/modules"; - String starterCall = modules + "/starter"; - String launcherCall = modules + "/launcher"; - //- - String dvm_start = String::DQuotes(dvm_drv) + " run "; - if (!matrix.isEmpty()) - dvm_start = dvm_start + matrix + " "; - dvm_start = dvm_start + String::DQuotes("./" + binary_name); - if (!args.isEmpty()) - dvm_start = dvm_start + " " + args; - return String::DQuotes(starterCall) + " " + - String::DQuotes(launcherCall) + " " + - String(maxtime) + " " + - String::DQuotes("killall -SIGKILL " + binary_name) + " " + - dvm_start; - } - - void prepareWorkspace() override { - String binary_src = parent->getWorkspace() + "/0"; - String binary_dst = workspace + "/" + binary_name; - Utils::Copy(binary_src, binary_dst); - if (!usr_par.isEmpty()) { - String parPath = String(id) + "/usr.par"; - File parFile = File(parPath, usr_par); - } - } - - String getStartCommand() override { - String res = workspace + "/run"; - if (!environments.isEmpty()) - res = environments + " " + res; - printf("START %ld: %s\n", id, res.getCharArray()); - return res; - } - - String copyResults(const String& pathRes) override { - String resultPath = Task::copyResults(pathRes); - if (Utils::Exists(workspace + "/sts.gz+")) { - String stsPath(resultPath + "/statistic.txt"); - String dvm_start = String::DQuotes(dvm_drv) + " pa " + String::DQuotes(String(getId()) + "/sts.gz+") + " " + String::DQuotes(stsPath); - system(dvm_start.getCharArray()); - while (!Utils::Exists(stsPath)); - } - return resultPath; - } -}; +#pragma once + +#include "CompilationTask.h" + +class RunTask : public Task { + long testcompilationtask_id; + String binary_name; + String matrix; + String environments; + String usr_par; + String args; + CompilationTask* parent; +public: + void print() const override { + printf("id=%ld; maxtime=%d; testcompilationtask_id=%ld; matrix=%s; environments=%s; usr_par=%s; args=%s kernels=%d\n", + id, + maxtime, + testcompilationtask_id, + matrix.getCharArray(), + environments.getCharArray(), + usr_par.getCharArray(), + args.getCharArray(), + kernels + ); + } + int setKernels(String* kernels_s) { + return kernels = atoi(kernels_s->getCharArray()); + } + long setTestCompilationTaskId(String* id_s) { + return testcompilationtask_id = strtol(id_s->getCharArray(), NULL, 10); + } + long getTestCompilationTaskId() { + return testcompilationtask_id; + } + void setMatrix(String* matrix_in) { + matrix = String(matrix_in->getCharArray()); + } + void setEnvironments(String* environments_in) { + environments = String(environments_in->getCharArray()); + } + void setUsrPar(String* usr_par_in) { + usr_par = String(usr_par_in->getCharArray(), '|'); + } + void setArgs(String* args_in) { + args = String(args_in->getCharArray()); + } + void setParent(CompilationTask* parent_in) { + parent = parent_in; + binary_name = "spf_" + String(id) + "_" + matrix.Replace(' ', '_'); + } + CompilationTask* getParent() { + return parent; + } + RunTask(Text* lines, int offset) :Task(lines, offset) { + setTestCompilationTaskId(lines->get(offset + 2)); + setMatrix(lines->get(offset + 3)); + setEnvironments(lines->get(offset + 4)); + setUsrPar(lines->get(offset + 5)); + setArgs(lines->get(offset + 6)); + setKernels(lines->get(offset + 7)); + } + + String getLaunchScriptText() override { + String modules = userWorkspace + "/modules"; + String starterCall = modules + "/starter"; + String launcherCall = modules + "/launcher"; + //- + String dvm_start = String::DQuotes(dvm_drv) + " run "; + if (!matrix.isEmpty()) + dvm_start = dvm_start + matrix + " "; + dvm_start = dvm_start + String::DQuotes("./" + binary_name); + if (!args.isEmpty()) + dvm_start = dvm_start + " " + args; + return String::DQuotes(starterCall) + " " + + String::DQuotes(launcherCall) + " " + + String(maxtime) + " " + + String::DQuotes("killall -SIGKILL " + binary_name + " 1>/dev/null 2>/dev/null") + " " + + dvm_start; + } + + void prepareWorkspace() override { + String binary_src = parent->getWorkspace() + "/0"; + String binary_dst = workspace + "/" + binary_name; + Utils::Copy(binary_src, binary_dst); + if (!usr_par.isEmpty()) { + String parPath = String(id) + "/usr.par"; + File parFile = File(parPath, usr_par); + } + } + + String getStartCommand() override { + String res = workspace + "/run"; + if (!environments.isEmpty()) + res = environments + " " + res; +#if DEB + printf("START %ld: %s\n", id, res.getCharArray()); +#endif + return res; + } + + String copyResults(const String& pathRes) override { + String resultPath = Task::copyResults(pathRes); + if (Utils::Exists(workspace + "/sts.gz+")) { + String stsPath(resultPath + "/statistic.txt"); + String dvm_start = String::DQuotes(dvm_drv) + " pa " + String::DQuotes(String(getId()) + "/sts.gz+") + " " + String::DQuotes(stsPath); + system(dvm_start.getCharArray()); + while (!Utils::Exists(stsPath)); + } + return resultPath; + } +}; diff --git a/src/files/Planner/String.h b/src/files/Planner/String.h index f4844d99..6b52757e 100644 --- a/src/files/Planner/String.h +++ b/src/files/Planner/String.h @@ -1,71 +1,73 @@ -#pragma once - -#include -#include -#include -#include -#include - -class String { - friend String operator+(const String& a, const String& b); - string body; - -public: - String() { body = ""; } - String(const char* s) { body = s; } - - String(const char* s, char ps) { - body = s; - for (long i = 0; i < getLength(); ++i) - body[i] = (s[i] == ps) ? '\n' : s[i]; - } - - String(int s) { body = to_string(s); } - String(long s) { body = to_string(s); } - String(long long s) { body = to_string(s); } - - void println() const { printf("[%s]\n", body.c_str()); } - void addChar(char c) { body += c; } - const char* getCharArray() const { return body.c_str(); } - const string& getBody() const { return body; } - size_t getLength() const { return body.size(); } - bool isEmpty() const { return body.size() == 0; } - bool contains(const String& s) const { return body.find(s.getBody()) != string::npos; } - bool operator==(const String& s) const { return body == s.getBody(); } - - const String& operator=(const String& s) { - body = s.getBody(); - return *this; - } - - static String DQuotes(const String& s) { - string tmp = '"' + s.getBody() + '"'; - return String(tmp.c_str()); - } - - String Replace(char f, char t) { - String res(body.c_str()); - for (auto i = 0; i < getLength(); ++i) - res.body[i] = (body[i] == f) ? t : body[i]; - return res; - } - String Remove(char f) { - String res; - for (auto i = 0; i < getLength(); ++i) - if (body[i] != f) - res.addChar(body[i]); - return res; - } - - String toUpper() { - String res = String(this->getCharArray()); - for (auto i = 0; i < getLength(); ++i) - res.body[i] = toupper(body[i]); - res.println(); - return res; - } -}; - -String operator+(const String& a, const String& b) { - return String((a.getBody() + b.getBody()).c_str()); -} +#pragma once + +#include +#include +#include +#include +#include + +class String { + friend String operator+(const String& a, const String& b); + string body; + +public: + String() { body = ""; } + String(const char* s) { body = s; } + + String(const char* s, char ps) { + body = s; + for (long i = 0; i < getLength(); ++i) + body[i] = (s[i] == ps) ? '\n' : s[i]; + } + + String(int s) { body = to_string(s); } + String(long s) { body = to_string(s); } + String(long long s) { body = to_string(s); } + + void println() const { printf("[%s]\n", body.c_str()); } + void addChar(char c) { body += c; } + const char* getCharArray() const { return body.c_str(); } + const string& getBody() const { return body; } + size_t getLength() const { return body.size(); } + bool isEmpty() const { return body.size() == 0; } + bool contains(const String& s) const { return body.find(s.getBody()) != string::npos; } + bool operator==(const String& s) const { return body == s.getBody(); } + + const String& operator=(const String& s) { + body = s.getBody(); + return *this; + } + + static String DQuotes(const String& s) { + string tmp = '"' + s.getBody() + '"'; + return String(tmp.c_str()); + } + + String Replace(char f, char t) { + String res(body.c_str()); + for (auto i = 0; i < getLength(); ++i) + res.body[i] = (body[i] == f) ? t : body[i]; + return res; + } + String Remove(char f) { + String res; + for (auto i = 0; i < getLength(); ++i) + if (body[i] != f) + res.addChar(body[i]); + return res; + } + + String toUpper() { + String res = String(this->getCharArray()); + for (auto i = 0; i < getLength(); ++i) + res.body[i] = toupper(body[i]); +#if DEB + res.println(); +#endif + return res; + } +}; + +String operator+(const String& a, const String& b) { + return String((a.getBody() + b.getBody()).c_str()); +} diff --git a/src/files/Planner/Supervisor.h b/src/files/Planner/Supervisor.h index c7f3aea1..09766cf3 100644 --- a/src/files/Planner/Supervisor.h +++ b/src/files/Planner/Supervisor.h @@ -104,9 +104,8 @@ public: } map, std::greater> sortedByKernelNeeds; - - long activeTasks = 0; - long done = 0; + size_t activeTasks = 0; + for (auto& task : this->getElements()) { if (task->getState() == WorkspaceReady) { activeTasks++; @@ -126,6 +125,10 @@ public: vector emptyKeys; vector toDel; + + size_t done = 0; + size_t step = activeTasks * 0.01; // step == 1% + const double total = activeTasks; while (activeTasks) { long oldActiveTasks = activeTasks; @@ -143,8 +146,9 @@ public: activeTaskSet.insert(task); task->Start(ignoreCheck); +#if DEB printf("start task with %d kernels and id %ld\n", task->getKernels(), task->getId()); - +#endif busyKernels += task->getKernels(); freeKernels = maxKernels - busyKernels; } @@ -169,8 +173,9 @@ public: activeTasks--; done++; busyKernels -= task->getKernels(); +#if DEB printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId()); - +#endif buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n"; task->copyResults(pathRes); } @@ -180,8 +185,19 @@ public: for (auto& del : toDel) activeTaskSet.erase(del); - if (oldActiveTasks != activeTasks) - printf("done %ld / %ld\n", done, this->getLength()); + if (oldActiveTasks != activeTasks) { +#if DEB + printf("done %ld / %d\n", done, this->getLength()); +#endif + if ((done % step) == 0) { + size_t persentDone = (done / total) * 100.0; + FILE *f = fopen("progress", "w"); + if (f) { + fprintf(f, "%lld\n", persentDone); + fclose(f); + } + } + } } changeState(); diff --git a/src/files/Planner/Task.h b/src/files/Planner/Task.h index d5d124c0..6159b7e8 100644 --- a/src/files/Planner/Task.h +++ b/src/files/Planner/Task.h @@ -1,197 +1,201 @@ -#pragma once - -#include - -#include "File.h" -#include "Utils.h" -#include "Global.h" - -enum TaskState { - Inactive, //0 - Waiting, //1 - WorkspaceCreated, //2 - WorkspaceReady, //3 - Running, //4 - Canceled, //5 - Finished, //6 - FinishedAbortedByTimeout, //7 - FinishedAbortedByUser, //8 - Done, //9 - DoneWithErrors, //10 - AbortedByTimeout, //11 - AbortedByUser, //12 - Crushed, //13 - WrongTestFormat, //14 - InternalError, //15 - Queued, //16 - NoSuchTask, //17 - FailedToQueue, //18 - AbortingByUser, //19 - Unknown -}; - -enum TestType { - Default, //0 - Correctness, //1 - Performance, //2 -}; - -class Task { -protected: - long id; - - int maxtime; - int kernels; //получение зависит от типа задачи. - String workspace; - TaskState state = Unknown; - std::chrono::system_clock::time_point start_time; - double total_time; - -public: - String printState() { - switch (state) { - case Inactive: - return String("Inactive"); - case Waiting: - return String("Waiting"); - case WorkspaceCreated: - return String("WorkspaceCreated"); - case WorkspaceReady: - return String("WorkspaceReady"); - case Running: - return String("Running"); - case Canceled: - return String("Canceled"); - case Finished: - return String("Finished"); - case FinishedAbortedByTimeout: - return String("FinishedAbortedByTimeout"); - case FinishedAbortedByUser: - return String("FinishedAbortedByUser"); - case Done: - return String("Done"); - case DoneWithErrors: - return String("DoneWithErrors"); - case AbortedByTimeout: - return String("AbortedByTimeout"); - case AbortedByUser: - return String("AbortedByUser"); - case Crushed: - return String("Crushed"); - case WrongTestFormat: - return String("WrongTestFormat"); - case InternalError: - return String("InternalError"); - case Queued: - return String("Queued"); - case NoSuchTask: - return String("NoSuchTask"); - case FailedToQueue: - return String("FailedToQueue"); - case AbortingByUser: - return String("AbortingByUser"); - case Unknown: - return String("?"); - default: - return "?"; - } - } - - //-------------->> - void setStart() { start_time = std::chrono::system_clock::now(); } - double getTotalTime() const { return total_time; } - - long getId() { return id; } - long setId(String* id_s) { - return id = strtol(id_s->getCharArray(), NULL, 10); - } - int getMaxtime() { return maxtime; } - int setMaxtime(String* maxtime_s) { - return maxtime = atoi(maxtime_s->getCharArray()); - } - const String& getWorkspace() { return workspace; } - TaskState getState() { return state; } - TaskState setState(TaskState state_in) { return state = state_in; } - Task(Text* lines, int offset) { - setId(lines->get(offset)); - setMaxtime(lines->get(offset + 1)); - workspace = packageWorkspace + "/" + String(id); - } - virtual void print() const = 0; - //- - virtual void prepareWorkspace() {} - virtual String getLaunchScriptText() = 0; - virtual String getStartCommand() { - return workspace + "/run"; - } - - void createWorkspace() { - Utils::Mkdir(workspace); - } - void createLaunchScript() { - String launchScriptPath = workspace + "/run"; - String launchScriptText = - String("cd ") + String::DQuotes(workspace) + "\n" + - getLaunchScriptText(); - File launchScriptFile = File(launchScriptPath, launchScriptText); - Utils::Chmod(launchScriptPath); - } - - int getKernels() const { return kernels; } - - void Start(bool dontCheck = false) { - if (kernels <= freeKernels || dontCheck) { - setStart(); - system(getStartCommand().getCharArray()); - state = Running; - //- - busyKernels = Utils::min(busyKernels + kernels, maxKernels); - freeKernels = Utils::max(0, maxKernels - busyKernels); - //- - } - } - - //return 'true' if done, 'false' - if running - virtual bool Check() { - if (Utils::Exists(workspace + "/DONE")) - analyseResults(); - else { - if (Utils::Exists(workspace + "/TIMEOUT")) { - state = AbortedByTimeout; - //todo определить по интервалу времени на всякий случай. - } - else if (Utils::Exists(workspace + "/INTERRUPT")) { - state = AbortedByUser; - } - else { - auto end_time = std::chrono::system_clock::now(); - std::chrono::duration diff_time = end_time - start_time; - - if (maxtime * 1.1 < diff_time.count()) { - printf("SET STATUS ABORTED by timer to %ld with time %f sec / %f sec", id, diff_time.count(), maxtime * 1.1); - state = AbortedByTimeout; - } - } - } - if (state != Running) { - busyKernels = Utils::min(busyKernels - kernels, maxKernels); - freeKernels = Utils::max(0, maxKernels - busyKernels); - } - return (state != Running); - } - - virtual void analyseResults() { - auto end_time = std::chrono::system_clock::now(); - std::chrono::duration diff_time = end_time - start_time; - total_time = diff_time.count(); - printf("%ld done with time %f\n", id, total_time); - state = Finished; - } - virtual String copyResults(const String& pathRes) { - String resultPath(packageWorkspace + "/" + pathRes + "/" + getId()); - Utils::Mkdir(resultPath); - Utils::Copy(workspace + "/out.txt", resultPath + "/out.txt"); - Utils::Copy(workspace + "/err.txt", resultPath + "/err.txt"); - return resultPath; - } -}; +#pragma once + +#include + +#include "File.h" +#include "Utils.h" +#include "Global.h" + +enum TaskState { + Inactive, //0 + Waiting, //1 + WorkspaceCreated, //2 + WorkspaceReady, //3 + Running, //4 + Canceled, //5 + Finished, //6 + FinishedAbortedByTimeout, //7 + FinishedAbortedByUser, //8 + Done, //9 + DoneWithErrors, //10 + AbortedByTimeout, //11 + AbortedByUser, //12 + Crushed, //13 + WrongTestFormat, //14 + InternalError, //15 + Queued, //16 + NoSuchTask, //17 + FailedToQueue, //18 + AbortingByUser, //19 + Unknown +}; + +enum TestType { + Default, //0 + Correctness, //1 + Performance, //2 +}; + +class Task { +protected: + long id; + + int maxtime; + int kernels; //получение зависит от типа задачи. + String workspace; + TaskState state = Unknown; + std::chrono::system_clock::time_point start_time; + double total_time; + +public: + String printState() { + switch (state) { + case Inactive: + return String("Inactive"); + case Waiting: + return String("Waiting"); + case WorkspaceCreated: + return String("WorkspaceCreated"); + case WorkspaceReady: + return String("WorkspaceReady"); + case Running: + return String("Running"); + case Canceled: + return String("Canceled"); + case Finished: + return String("Finished"); + case FinishedAbortedByTimeout: + return String("FinishedAbortedByTimeout"); + case FinishedAbortedByUser: + return String("FinishedAbortedByUser"); + case Done: + return String("Done"); + case DoneWithErrors: + return String("DoneWithErrors"); + case AbortedByTimeout: + return String("AbortedByTimeout"); + case AbortedByUser: + return String("AbortedByUser"); + case Crushed: + return String("Crushed"); + case WrongTestFormat: + return String("WrongTestFormat"); + case InternalError: + return String("InternalError"); + case Queued: + return String("Queued"); + case NoSuchTask: + return String("NoSuchTask"); + case FailedToQueue: + return String("FailedToQueue"); + case AbortingByUser: + return String("AbortingByUser"); + case Unknown: + return String("?"); + default: + return "?"; + } + } + + //-------------->> + void setStart() { start_time = std::chrono::system_clock::now(); } + double getTotalTime() const { return total_time; } + + long getId() { return id; } + long setId(String* id_s) { + return id = strtol(id_s->getCharArray(), NULL, 10); + } + int getMaxtime() { return maxtime; } + int setMaxtime(String* maxtime_s) { + return maxtime = atoi(maxtime_s->getCharArray()); + } + const String& getWorkspace() { return workspace; } + TaskState getState() { return state; } + TaskState setState(TaskState state_in) { return state = state_in; } + Task(Text* lines, int offset) { + setId(lines->get(offset)); + setMaxtime(lines->get(offset + 1)); + workspace = packageWorkspace + "/" + String(id); + } + virtual void print() const = 0; + //- + virtual void prepareWorkspace() {} + virtual String getLaunchScriptText() = 0; + virtual String getStartCommand() { + return workspace + "/run"; + } + + void createWorkspace() { + Utils::Mkdir(workspace); + } + void createLaunchScript() { + String launchScriptPath = workspace + "/run"; + String launchScriptText = + String("cd ") + String::DQuotes(workspace) + "\n" + + getLaunchScriptText(); + File launchScriptFile = File(launchScriptPath, launchScriptText); + Utils::Chmod(launchScriptPath); + } + + int getKernels() const { return kernels; } + + void Start(bool dontCheck = false) { + if (kernels <= freeKernels || dontCheck) { + setStart(); + system(getStartCommand().getCharArray()); + state = Running; + //- + busyKernels = Utils::min(busyKernels + kernels, maxKernels); + freeKernels = Utils::max(0, maxKernels - busyKernels); + //- + } + } + + //return 'true' if done, 'false' - if running + virtual bool Check() { + if (Utils::Exists(workspace + "/DONE")) + analyseResults(); + else { + if (Utils::Exists(workspace + "/TIMEOUT")) { + state = AbortedByTimeout; + //todo определить по интервалу времени на всякий случай. + } + else if (Utils::Exists(workspace + "/INTERRUPT")) { + state = AbortedByUser; + } + else { + auto end_time = std::chrono::system_clock::now(); + std::chrono::duration diff_time = end_time - start_time; + + if (maxtime * 1.1 < diff_time.count()) { +#if DEB + printf("SET STATUS ABORTED by timer to %ld with time %f sec / %f sec", id, diff_time.count(), maxtime * 1.1); +#endif + state = AbortedByTimeout; + } + } + } + if (state != Running) { + busyKernels = Utils::min(busyKernels - kernels, maxKernels); + freeKernels = Utils::max(0, maxKernels - busyKernels); + } + return (state != Running); + } + + virtual void analyseResults() { + auto end_time = std::chrono::system_clock::now(); + std::chrono::duration diff_time = end_time - start_time; + total_time = diff_time.count(); +#if DEB + printf("%ld done with time %f\n", id, total_time); +#endif + state = Finished; + } + virtual String copyResults(const String& pathRes) { + String resultPath(packageWorkspace + "/" + pathRes + "/" + getId()); + Utils::Mkdir(resultPath); + Utils::Copy(workspace + "/out.txt", resultPath + "/out.txt"); + Utils::Copy(workspace + "/err.txt", resultPath + "/err.txt"); + return resultPath; + } +}; diff --git a/src/files/Planner/Text.h b/src/files/Planner/Text.h index fb759e31..06bd3c7d 100644 --- a/src/files/Planner/Text.h +++ b/src/files/Planner/Text.h @@ -1,29 +1,29 @@ -#pragma once - -#include "String.h" -#include "Array.h" - -class Text : public Array { -public: - void Print() const { - printf("text length=%ld\n", this->getLength()); - - auto elems = this->getElements(); - for (long i = 0; i < elems.size(); ++i) { - printf("i=%ld; [%s]\n", i, elems[i]->getCharArray()); - // elements[i]->println(); - } - } - - bool hasMatch(const String& s) const { - - for (auto& elem : this->getElements()) { - if (s.contains(*elem)) { - //printf("match: [%s]\n", elements[i]->getCharArray()); - return true; - } - } - //printf("no matches for [%s]\n", s.getCharArray()); - return false; - } -}; +#pragma once + +#include "String.h" +#include "Array.h" + +class Text : public Array { +public: + void Print() const { + printf("text length=%ld\n", this->getLength()); + + auto elems = this->getElements(); + for (long i = 0; i < elems.size(); ++i) { + printf("i=%ld; [%s]\n", i, elems[i]->getCharArray()); + // elements[i]->println(); + } + } + + bool hasMatch(const String& s) const { + + for (auto& elem : this->getElements()) { + if (s.contains(*elem)) { + //printf("match: [%s]\n", elements[i]->getCharArray()); + return true; + } + } + //printf("no matches for [%s]\n", s.getCharArray()); + return false; + } +}; diff --git a/src/files/Planner/Utils.h b/src/files/Planner/Utils.h index 6d6f864e..8f6134b0 100644 --- a/src/files/Planner/Utils.h +++ b/src/files/Planner/Utils.h @@ -1,84 +1,84 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#if __cplusplus >= 201703L -#include -#endif - -#include "String.h" - -class Utils { -public: - static int max(int a, int b) { - return (a > b) ? a : b; - } - static int min(int a, int b) { - return (a > b) ? b : a; - } - static void Mkdir(const String& path) { -#if __cplusplus >= 201703L - std::filesystem::create_directory(path.getCharArray()); -#else - mkdir(path.getCharArray(), 0777); -#endif - } - - //https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program - static void Chmod(const String& path) { -#if __cplusplus >= 201703L - std::filesystem::permissions(path.getCharArray(), std::filesystem::perms::all); -#else - String command = "chmod 777 " + String::DQuotes(path); - int i=system(command.getCharArray()); - printf("chmod 777 '%s' return code = %d\n", path.getCharArray(), i); -#endif - } - - //https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c - static bool Exists(const String& path) { -#if __cplusplus >= 201703L - return std::filesystem::exists(path.getCharArray()); -#else - struct stat buffer; - return (stat(path.getCharArray(), &buffer) == 0); -#endif - } - - //in seconds - static void Sleep(int s) { - std::chrono::seconds timespan(s); - std::this_thread::sleep_for(timespan); - } - static void Copy(const String& src, const String& dst) { -#if __cplusplus >= 201703L - std::filesystem::copy(src.getCharArray(), dst.getCharArray()); -#else - String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst); - int i = system(command.getCharArray()); - printf("cp '%s' return code = %d\n",src.getCharArray(), i); -#endif - } - static void CopyDirectory(const String& src, const String& dst) { -#if __cplusplus >= 201703L - std::filesystem::copy((src+ "/.").getCharArray(), dst.getCharArray(), std::filesystem::copy_options::recursive); -#else - String command = "cp -r " + String::DQuotes(src + "/.") + " " + String::DQuotes(dst); - int i = system(command.getCharArray()); - printf("cp -r '%s' return code = %d\n",src.getCharArray(),i); -#endif - } - static time_t getAbsoluteTime() { - return time(NULL); - } - static String getDate() { - auto ttime = time(NULL); - String res(ctime(&ttime)); - return res; - } -}; +#pragma once + +#include +#include +#include +#include +#include +#include + +#if __cplusplus >= 201703L +#include +#endif + +#include "String.h" + +class Utils { +public: + static int max(int a, int b) { + return (a > b) ? a : b; + } + static int min(int a, int b) { + return (a > b) ? b : a; + } + static void Mkdir(const String& path) { +#if __cplusplus >= 201703L + std::filesystem::create_directory(path.getCharArray()); +#else + mkdir(path.getCharArray(), 0777); +#endif + } + + //https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program + static void Chmod(const String& path) { +#if __cplusplus >= 201703L + std::filesystem::permissions(path.getCharArray(), std::filesystem::perms::all); +#else + String command = "chmod 777 " + String::DQuotes(path); + int i=system(command.getCharArray()); + //printf("chmod 777 '%s' return code = %d\n", path.getCharArray(), i); +#endif + } + + //https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c + static bool Exists(const String& path) { +#if __cplusplus >= 201703L + return std::filesystem::exists(path.getCharArray()); +#else + struct stat buffer; + return (stat(path.getCharArray(), &buffer) == 0); +#endif + } + + //in seconds + static void Sleep(int s) { + std::chrono::seconds timespan(s); + std::this_thread::sleep_for(timespan); + } + static void Copy(const String& src, const String& dst) { +#if __cplusplus >= 201703L + std::filesystem::copy(src.getCharArray(), dst.getCharArray()); +#else + String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst); + int i = system(command.getCharArray()); + //printf("cp '%s' return code = %d\n",src.getCharArray(), i); +#endif + } + static void CopyDirectory(const String& src, const String& dst) { +#if __cplusplus >= 201703L + std::filesystem::copy((src+ "/.").getCharArray(), dst.getCharArray(), std::filesystem::copy_options::recursive); +#else + String command = "cp -r " + String::DQuotes(src + "/.") + " " + String::DQuotes(dst); + int i = system(command.getCharArray()); + //printf("cp -r '%s' return code = %d\n",src.getCharArray(),i); +#endif + } + static time_t getAbsoluteTime() { + return time(NULL); + } + static String getDate() { + auto ttime = time(NULL); + String res(ctime(&ttime)); + return res; + } +}; diff --git a/src/files/Planner/version.h b/src/files/Planner/version.h new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/src/files/Planner/version.h @@ -0,0 +1 @@ +1 \ No newline at end of file