Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix repository listing and selection #71

Merged
merged 12 commits into from
Sep 20, 2024
Merged

Fix repository listing and selection #71

merged 12 commits into from
Sep 20, 2024

Conversation

arthurmco
Copy link
Collaborator

Allow the user to see and enable/disable the repositories that will be installed in the machine.

Also, change the way we handle repositories, by:

  • configuring them in memory and save every change in one go
  • use the .repos embedded in the source only as a template, instead of saving it directly

This way, we can easily discover all repos in the machine
from outside, from an interface or answerfile

Also add some tests to see if we parsed the data correctly
@arthurmco arthurmco self-assigned this Aug 30, 2024
Copy link
Collaborator

@lbgracioso lbgracioso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

src/repos.cpp Outdated
auto path = std::string { tmpnam(nullptr) };
std::filesystem::create_directory(m_path);
m_path = m_path;
char* temp = "tempdirXXXXXX";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good. If we gonna create this it would be better to be constexpr.

src/repos.cpp Outdated
m_path = m_path;
char* temp = "tempdirXXXXXX";

auto path = std::string { mkdtemp(temp) };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot create it directly? mkdtemp("tempdirXXXXXX")? And is this correct? tempdirXXXXXX? It's ugly.

@lbgracioso lbgracioso self-requested a review September 3, 2024 08:42
@viniciusferrao
Copy link
Owner

viniciusferrao commented Sep 4, 2024

SonarCloud is still upset @arthurmco.

Is there a way to just disable the specific error? I see that you added //NOSONAR, however this will disable SonarCloud completely in the line.

There's no way to select a block of code and only disable the specific bogus error?

Finally the code duplication issue, I didn't get it. It's also a bogus issue?

EDIT: https://gist.github.com/brian-ahr/a5bf071feda62ffbc5e1686c0cafb52c

@arthurmco
Copy link
Collaborator Author

Is there a way to just disable the specific error? I see that you added //NOSONAR, however this will disable SonarCloud completely in the line.

There are some ways, like specifying #pragmas and annotations, but they only seem to work in certain languages (namely C# and Java)

There's no way to select a block of code and only disable the specific bogus error?

For C++, currently, no.

Finally the code duplication issue, I didn't get it. It's also a bogus issue?

Probably yes, because I did not duplicate nothing. Sonarcloud did not tell exactly what have been duplicated

@arthurmco
Copy link
Collaborator Author

Finally

It complains about a pseudo-RNG in a function that is rarely used, and
used only for testing, almost never in production
> @viniciusferrao: There's a class that defines version:
>  ```cpp
>  enum class Platform { el8, el9 };
>  ```
Comment on lines 67 to 73
if (es.u.co == bOk) {
retval = 1;
} else if (es.u.co == bHelp) {
this->helpMessage(help);
} else {
retval = 2;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch?

Also is this the handling of the buttons? If yes we have a standard way to handle it:

However I think that should be another method, to avoid code duplication. Not sure how to achieve that on the context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch?

The, switch only would work here if the bOk and bHelp were constexpr; and I don't think this is applicable, because the button creation function is not constexpr

Also is this the handling of the buttons? If yes we have a standard way to handle it:

Yes, but since this is a custom-built form (because we needed to select multiple repos, something that the default list form does not allow us to do), we do not have the error code treatment that the easy form functions Newt give to us

However I think that should be another method, to avoid code duplication. Not sure how to achieve that on the context.

I agree, but I need to think a little bit more about that

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok @arthurmco if you didn't came up with a solution in a timely manner I think we can accept this. I was wondering for a total overhaul of the TUI in the future.

However here, at least if you don't mind using a better naming in the variables, like button instead of b. Is good. To be hones is a little bad to read es.u.co == b0k.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Did it in the last commit

newtFormSetWidth(form, m_suggestedWidth);

auto* label = newtLabel(1, 1, message);
auto stitle = std::string { title };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get it. Is this an implicit type conversion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

The compiler can deduce the type anyway; and since this label does not leave the function, the exact type name isn't too important

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. Just use title directly no? In the end is another string. However if the plan is to store a const char* well... just use title.c_str() directly.

NEWT_GRID_FLAG_GROWX | NEWT_GRID_FLAG_GROWY);
newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttonGrid, 0, 1, 0, 0, 0,
NEWT_GRID_FLAG_GROWX);
newtGridWrappedWindow(grid, const_cast<char*>(stitle.c_str()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm do we need creating a local copy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of what? Of the string?

If you are talking about stitle, then yes. This function (newtGridWrappedWindow) is not const-correct, and I created a "sacrificial" copy to preserve the original string, in the rare case this function does change the string

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of what? Of the string?

If you are talking about stitle, then yes. This function (newtGridWrappedWindow) is not const-correct, and I created a "sacrificial" copy to preserve the original string, in the rare case this function does change the string

What if we const_cast?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will violate constness of the original value

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look on the comment on the auto implicit conversion.

Comment on lines +15 to +24
extern bool showVersion;
extern bool runAsRoot;
extern bool dryRun;
extern bool enableTUI;
extern bool enableCLI;
extern bool runAsDaemon;

extern std::string logLevelInput;
extern std::string answerfile;
extern std::string customRepofilePath;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know a better solution to this. This is not a change request and only a comment, but I don't like this either. It's not your code, the old code wasn't good at all also.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code duplicated the variable instantiations (for some reason, even though we had the include guards)

I moved them to an external file, leaving only the declarations.

I also don't like this, but I could not think about any other way

The other solution would be using a class where every variable is public and static (or a struct where every member is static), but this would take some time to refactor

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should abandon the [cloyster-{}] name on the repos. That should reflect PRODUCT_NAME or just use the default names. I'm open to suggestions here.

* SPDX-License-Identifier: Apache-2.0
*/

#pragma once
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should use #ifndef instead.

Copy link
Owner

@viniciusferrao viniciusferrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still some considerations here @arthurmco; please take a look if you can.

* SPDX-License-Identifier: Apache-2.0
*/

#pragma once
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should use #ifndef instead.

src/runner.cpp Outdated
int DryRunner::executeCommand(const std::string& cmd)
{
LOG_INFO("Would execute command: {}", cmd);
return 0;
Copy link
Owner

@viniciusferrao viniciusferrao Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0;
return OK;

Does this return is even necessary? It always return 0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes (see below)

src/runner.cpp Outdated
int MockRunner::executeCommand(const std::string& cmd)
{
m_cmds.push_back(cmd);
return 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the only return does it makes sense? It always return 0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

This class descends from the BaseRunner. One of its child is the normal Runner, which really runs a command and returns a value depending on said command return code

auto repos = m_cluster->getRepoManager();
repos.loadFiles();
repos.enableMultiple({ "cloyster-beegfs", "cloyster-elrepo",
"cloyster-epel", "cloyster-openhpc",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the names here? We have mentioned to use PRODUCT_NAME instead or just use the default distribution names.

src/tempdir.cpp Outdated
#include <fmt/format.h>
#include <random>

static char value_to_char(unsigned long value)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static char value_to_char(unsigned long value)
static char value_to_char(std::uint64_t value)

This would make more sense because it express intent.

company_name=cloyster-enterprises
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
company_name=cloyster-enterprises
company_name=example-enterprise

[another]
another_key=123
second_key=ABC
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
second_key=ABC
second_key=ABC

Signed-off-by: Vinícius Ferrão <[email protected]>
Copy link

Copy link
Owner

@viniciusferrao viniciusferrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally this one make through.

@viniciusferrao viniciusferrao merged commit 9867da5 into master Sep 20, 2024
3 checks passed
@viniciusferrao viniciusferrao deleted the feat/fix-repos branch January 18, 2025 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants