Skip to content

Commit

Permalink
WIP Refactoring RepoManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hilst committed Feb 11, 2025
1 parent 3a90032 commit f202b6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
17 changes: 7 additions & 10 deletions include/cloysterhpc/repos.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,18 @@ class /* [[deprecated("refactoring")]] */ RepoManager {
public:
RepoManager(Runner& runner, const OS& osinfo);
void loadFiles(const std::filesystem::path& basedir = "/etc/yum.repos.d");
void loadCustom(inifile& file, const std::filesystem::path& path);

// BUG: Enable and EnableMultiple are the same method. Overload it.
void enable(const std::string& id);
void enableMultiple(std::vector<std::string> ids);
void disable(const std::string& id);

void commitStatus();

void enable(const std::string& repo);
void enableMultiple(std::vector<std::string> repos);
void disable(const std::string& repo);
const std::vector<Repository>& listRepos() const;

std::vector<std::string> getxCATOSImageRepos() const;
[[nodiscard]] std::vector<std::string> getxCATOSImageRepos() const;

private:
void loadCustom(inifile& file, const std::filesystem::path& path);
// BUG: Enable and EnableMultiple are the same method. Overload it.
std::vector<Repository> m_repos;

BaseRunner& m_runner;
const OS& m_os;

Expand Down
19 changes: 7 additions & 12 deletions src/repos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,15 @@ static std::string buildPackageName(std::string stem)
}

static std::vector<std::string> getDependenciesEL(
const OS& os, OS::Platform platform)
const OS& os)
{
const auto platform = os.getPlatform();
std::vector<std::string> dependencies;

// BUG: Bad code. We should use the OS::getVersion() method.
std::size_t version;
std::size_t version = os.getMajorVersion();
std::string powertools = "powertools";
if (platform == OS::Platform::el8) {
powertools = "crb";
version = 8;
}
if (platform == OS::Platform::el9) {
version = 9;
}
if (platform == OS::Platform::el10) {
version = 10;
}

switch (os.getDistro()) {
Expand Down Expand Up @@ -243,10 +236,12 @@ static std::vector<std::string> getDependenciesEL(
template <typename Repository, typename Runner>
void RepoManager<Repository, Runner>::configureEL()
{
std::vector<std::string> deps = getDependenciesEL(m_os, m_os.getPlatform());
std::vector<std::string> deps = getDependenciesEL(m_os);

std::for_each(
deps.begin(), deps.end(), [this](const auto& id) { this->enable(id); });
deps.begin(), deps.end(), [this](const auto& repo) {
this->enable(repo);
});
}

template <>
Expand Down
11 changes: 6 additions & 5 deletions src/services/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,12 @@ void Shell::install()
auto repos = *cloyster::getRepoManager(m_cluster->getHeadnode().getOS());
repos.loadFiles();

std::vector<std::string> toEnable = { "-beegfs", "-elrepo", "-epel",
"-openhpc", "-openhpc-updates", "-rpmfusion-free-updates" };
for (auto& package : toEnable) {
package = cloyster::productName + package;
}
const auto toEnable =
std::vector({ "-beegfs", "-elrepo", "-epel", "-openhpc", "-openhpc-updates", "-rpmfusion-free-updates" })
| std::views::transform([&](const std::string& pkg) {
return cloyster::productName + pkg;
})
| std::ranges::to<std::vector<std::string>>();

repos.enableMultiple(toEnable);
repos.commitStatus();
Expand Down

0 comments on commit f202b6b

Please sign in to comment.