-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
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
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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) }; |
There was a problem hiding this comment.
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.
SonarCloud is still upset @arthurmco. Is there a way to just disable the specific error? I see that you added 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 |
There are some ways, like specifying
For C++, currently, no.
Probably yes, because I did not duplicate nothing. Sonarcloud did not tell exactly what have been duplicated |
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 }; > ```
ed52cad
to
b3629ae
Compare
src/view/newtListMenu.cpp
Outdated
if (es.u.co == bOk) { | ||
retval = 1; | ||
} else if (es.u.co == bHelp) { | ||
this->helpMessage(help); | ||
} else { | ||
retval = 2; | ||
} |
There was a problem hiding this comment.
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:
goto question; |
However I think that should be another method, to avoid code duplication. Not sure how to achieve that on the context.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
src/view/newtListMenu.cpp
Outdated
newtFormSetWidth(form, m_suggestedWidth); | ||
|
||
auto* label = newtLabel(1, 1, message); | ||
auto stitle = std::string { title }; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/view/newtListMenu.cpp
Outdated
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())); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
include/cloysterhpc/runner.h
Outdated
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
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.
5c3ee50
to
4f6d8b7
Compare
There was a problem hiding this 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.
include/cloysterhpc/runner.h
Outdated
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 0; | |
return OK; |
Does this return is even necessary? It always return 0
.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
src/services/shell.cpp
Outdated
auto repos = m_cluster->getRepoManager(); | ||
repos.loadFiles(); | ||
repos.enableMultiple({ "cloyster-beegfs", "cloyster-elrepo", | ||
"cloyster-epel", "cloyster-openhpc", |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
test/sample/inifile.ini
Outdated
company_name=cloyster-enterprises |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
company_name=cloyster-enterprises | |
company_name=example-enterprise |
test/sample/inifile.ini
Outdated
[another] | ||
another_key=123 | ||
second_key=ABC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
second_key=ABC | |
second_key=ABC | |
Signed-off-by: Vinícius Ferrão <[email protected]>
|
There was a problem hiding this 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.
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: