Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit 96932e7

Browse files
committed
Deduplicate code (not compiling yet)
1 parent 781360e commit 96932e7

27 files changed

Lines changed: 452 additions & 504 deletions

include/cloysterhpc/functions.h

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#include <cloysterhpc/models/cluster.h>
66
#include <cloysterhpc/services/log.h>
77
#include <cloysterhpc/patterns/singleton.h>
8-
#include <boost/process/child.hpp>
9-
#include <boost/process/pipe.hpp>
108
#include <cloysterhpc/services/repos.h>
119
#include <filesystem>
1210
#include <list>
@@ -31,73 +29,8 @@ constexpr std::unique_ptr<B> makeUniqueDerived(Args... args)
3129
using cloyster::services::IRunner;
3230
using cloyster::models::OS;
3331

34-
/**
35-
* A command proxy, to us to be able to get the
36-
* command output while the command is running
37-
*
38-
* We will use this in the progress dialog
39-
*/
40-
/**
41-
* @struct CommandProxy
42-
* @brief A command proxy to capture the command output while the command is
43-
* running.
44-
*
45-
* This structure is used to capture the output of a command in real-time,
46-
* useful for displaying progress in a dialog.
47-
*/
48-
struct CommandProxy {
49-
bool valid = false;
50-
boost::process::child child;
51-
boost::process::ipstream pipe_stream;
52-
53-
/**
54-
* @brief Gets a line of output from the command.
55-
*
56-
* @return An optional string containing a line of output if available,
57-
* otherwise std::nullopt.
58-
*/
59-
std::optional<std::string> getline();
60-
61-
std::optional<std::string> getUntil(char c);
62-
};
63-
64-
enum class Stream { Stdout, Stderr };
65-
6632
/* shell execution */
6733

68-
/**
69-
* @brief Executes a command and captures its output.
70-
*
71-
* @param command The command to execute.
72-
* @param output A list to store the output lines of the command.
73-
* @param overrideDryRun A flag to override the dryRun setting.
74-
* @return The exit code of the command.
75-
*/
76-
int runCommand(const std::string& command, std::list<std::string>& output,
77-
bool overrideDryRun = false);
78-
79-
/**
80-
* @brief Executes a command.
81-
*
82-
* @param command The command to execute.
83-
* @param overrideDryRun A flag to override the dryRun setting.
84-
* @return The exit code of the command.
85-
*/
86-
int runCommand(const std::string& command, bool overrideDryRun = false);
87-
88-
/**
89-
* @brief Executes a command and provides a proxy to capture its output
90-
* iteratively.
91-
*
92-
* @param command The command to execute.
93-
* @param overrideDryRun A flag to override the dryRun setting.
94-
* @return A CommandProxy to capture the command's output.
95-
*/
96-
CommandProxy runCommandIter(const std::string& command,
97-
Stream out = Stream::Stdout, bool overrideDryRun = false);
98-
99-
/* environment variables helper functions */
100-
10134
/**
10235
* @brief Retrieves the value of an environment variable.
10336
*

include/cloysterhpc/models/answerfile.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#include <boost/asio.hpp>
1010
#include <cloysterhpc/inifile.h>
11+
#include <cloysterhpc/utils/enums.h>
1112
#include <cloysterhpc/mailsystem/postfix.h>
1213
#include <cloysterhpc/models/os.h>
13-
#include <cloysterhpc/tools/ITool.h>
1414
#include <cloysterhpc/ofed.h>
1515
#include <optional>
1616
#include <vector>
@@ -135,8 +135,6 @@ class AnswerFile {
135135
std::vector<AFNode> nodes;
136136
};
137137

138-
std::vector<std::shared_ptr<ITool>> m_tools;
139-
140138
struct AFPostfix {
141139
struct SASL {
142140
std::string username;
@@ -360,7 +358,6 @@ class AnswerFile {
360358
*/
361359
void loadFile(const std::filesystem::path& path);
362360
void dumpFile(const std::filesystem::path& path);
363-
std::vector<std::shared_ptr<ITool>> getTools();
364361

365362
AnswerFile();
366363
explicit AnswerFile(const std::filesystem::path& path);

include/cloysterhpc/models/cluster.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <cloysterhpc/models/queuesystem.h>
2020
#include <cloysterhpc/network.h>
2121
#include <cloysterhpc/ofed.h>
22-
#include <cloysterhpc/services/locale.h>
2322
#include <cloysterhpc/services/repos.h>
2423
#include <cloysterhpc/services/runner.h>
2524
#include <cloysterhpc/services/timezone.h>
@@ -70,7 +69,7 @@ class Cluster {
7069
bool m_firewall { false };
7170
SELinuxMode m_selinux { SELinuxMode::Disabled };
7271
Timezone m_timezone;
73-
Locale m_locale; /* Default locale cluster wide */
72+
std::string m_locale; /* Default locale cluster wide */
7473
std::string m_domainName;
7574

7675
std::list<std::unique_ptr<Network>> m_network;
@@ -96,8 +95,7 @@ class Cluster {
9695
void setSELinux(SELinuxMode);
9796
[[nodiscard]] Timezone& getTimezone();
9897
void setTimezone(const std::string& tz);
99-
[[nodiscard]] const Locale& getLocale() const;
100-
void setLocale(const Locale& locale);
98+
[[nodiscard]] const std::string& getLocale() const;
10199
void setLocale(const std::string& locale);
102100
[[nodiscard]] const std::string getDomainName() const;
103101
void setDomainName(const std::string& domainName);

include/cloysterhpc/services/execution.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class Execution {
1414
public:
1515
virtual ~Execution() = default;
1616

17-
// virtual void runCommand(const std::string&) = 0;
1817
virtual void install() = 0;
1918
};
2019

include/cloysterhpc/services/locale.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

include/cloysterhpc/services/osservice.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,27 @@ class IOSService {
4040
[[nodiscard]] virtual std::string getKernelInstalled() const = 0;
4141
[[nodiscard]] virtual std::string getKernelRunning() const = 0;
4242

43+
[[nodiscard]] virtual std::string getLocale() const = 0;
44+
[[nodiscard]] virtual std::vector<std::string> getAvailableLocales() const = 0;
45+
4346
// These methods are const because the implementation is expected to be stateless
44-
// The implementation is expect to be stateless to avoid double source of true,
45-
// the internal state vs the OS runtime state
47+
// The implementation is expect to be stateless to avoid double source of true.
48+
// In-memory state should live in the OS model
4649
virtual bool install(std::string_view package) const = 0;
50+
virtual bool groupInstall(std::string_view package) const = 0;
4751
virtual bool remove(std::string_view package) const = 0;
4852
virtual bool update(std::string_view package) const = 0;
4953
virtual bool update() const = 0;
5054
virtual void check() const = 0;
5155
virtual void clean() const = 0;
5256
virtual std::vector<std::string> repolist() const = 0;
5357

58+
virtual bool enableService(std::string_view service) const = 0;
59+
virtual bool disableService(std::string_view service) const = 0;
60+
virtual bool startService(std::string_view service) const = 0;
61+
virtual bool stopService(std::string_view service) const = 0;
62+
virtual bool restartService(std::string_view service) const = 0;
63+
5464
static std::unique_ptr<IOSService> factory(const OS& osinfo);
5565
};
5666

include/cloysterhpc/services/runner.h

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,83 @@
66
#ifndef CLOYSTERHPC_RUNNER_H_
77
#define CLOYSTERHPC_RUNNER_H_
88

9+
#include <boost/process.hpp>
10+
911
#include <string>
1012
#include <vector>
1113

1214
namespace cloyster::services {
1315

16+
/**
17+
* @struct CommandProxy
18+
* @brief A command proxy to capture the command output while the command is
19+
* running.
20+
*
21+
* This structure is used to capture the output of a command in real-time,
22+
* useful for displaying progress in a dialog.
23+
*/
24+
struct CommandProxy {
25+
bool valid = false;
26+
boost::process::child child;
27+
boost::process::ipstream pipe_stream;
28+
29+
/**
30+
* @brief Gets a line of output from the command.
31+
*
32+
* @return An optional string containing a line of output if available,
33+
* otherwise std::nullopt.
34+
*/
35+
std::optional<std::string> getline();
36+
std::optional<std::string> getUntil(char chr);
37+
};
38+
39+
enum class Stream : std::uint8_t { Stdout, Stderr };
40+
1441
/**
1542
* Works as an abstraction for command execution.
1643
*/
1744
class IRunner {
1845
public:
46+
IRunner() = default;
47+
IRunner(const IRunner&) = default;
48+
IRunner(IRunner&&) = delete;
49+
IRunner& operator=(const IRunner&) = default;
50+
IRunner& operator=(IRunner&&) = delete;
51+
virtual ~IRunner() = default;
52+
1953
virtual int executeCommand(const std::string&) = 0;
54+
virtual CommandProxy executeCommandIter(const std::string&, Stream out = Stream::Stdout) = 0;
2055
virtual void checkCommand(const std::string&) = 0;
2156
virtual std::vector<std::string> checkOutput(const std::string&) = 0;
2257

2358
virtual int downloadFile(const std::string& url, const std::string& file);
24-
25-
virtual ~IRunner() = default;
2659
};
2760

28-
class Runner : public IRunner {
61+
class Runner final : public IRunner {
2962
public:
30-
int executeCommand(const std::string&) override;
31-
void checkCommand(const std::string&) override;
32-
std::vector<std::string> checkOutput(const std::string&) override;
33-
34-
virtual ~Runner() = default;
63+
CommandProxy executeCommandIter(const std::string& cmd, Stream out = Stream::Stdout) override;
64+
int executeCommand(const std::string& cmd) override;
65+
void checkCommand(const std::string& cmd) override;
66+
std::vector<std::string> checkOutput(const std::string& cmd) override;
67+
int downloadFile(const std::string& url, const std::string& file) override;
3568
};
3669

37-
class DryRunner : public IRunner {
70+
class DryRunner final : public IRunner {
3871
public:
39-
int executeCommand(const std::string&) override;
40-
void checkCommand(const std::string&) override;
41-
std::vector<std::string> checkOutput(const std::string&) override;
42-
43-
virtual ~DryRunner() = default;
72+
CommandProxy executeCommandIter(const std::string& cmd, Stream out = Stream::Stdout) override;
73+
int executeCommand(const std::string& cmd) override;
74+
void checkCommand(const std::string& cmd) override;
75+
std::vector<std::string> checkOutput(const std::string& cmd) override;
76+
int downloadFile(const std::string& url, const std::string& file) override;
4477
};
4578

46-
class MockRunner : public IRunner {
79+
class MockRunner final : public IRunner {
4780
public:
48-
int executeCommand(const std::string&) override;
49-
void checkCommand(const std::string&) override;
50-
std::vector<std::string> checkOutput(const std::string&) override;
51-
52-
virtual ~MockRunner() = default;
81+
CommandProxy executeCommandIter(const std::string& cmd, Stream out = Stream::Stdout) override;
82+
int executeCommand(const std::string& cmd) override;
83+
void checkCommand(const std::string& cmd) override;
84+
std::vector<std::string> checkOutput(const std::string& cmd) override;
85+
int downloadFile(const std::string& url, const std::string& file) override;
5386

5487
[[nodiscard]] const std::vector<std::string>& listCommands() const;
5588

include/cloysterhpc/tools/ITool.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

include/cloysterhpc/tools/nvhpc.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

include/cloysterhpc/view/newt.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <boost/lexical_cast.hpp>
1010
#include <cloysterhpc/functions.h>
11+
#include <cloysterhpc/services/runner.h>
1112
#include <cloysterhpc/services/log.h>
1213
#include <cloysterhpc/view/view.h>
1314
#include <fmt/format.h>
@@ -277,8 +278,8 @@ class Newt : public View {
277278
* into a percent (a 0 to 100 value)
278279
*/
279280
bool progressMenu(const char* title, const char* message,
280-
cloyster::CommandProxy&&,
281-
std::function<std::optional<double>(cloyster::CommandProxy&)> fPercent);
281+
cloyster::services::CommandProxy&&,
282+
std::function<std::optional<double>(cloyster::services::CommandProxy&)> fPercent);
282283

283284
// TODO:
284285
// * Optimize for std::string_view and std::string.

0 commit comments

Comments
 (0)