shells_path is now a directory of .shell files
Matches the existing units_path pattern — shells_path points to a directory that is scanned for .shell files rather than a single monolithic definitions file.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"project_root": "$HOME/development/internal/rex/sample",
|
"project_root": "$HOME/development/internal/rex/sample",
|
||||||
"units_path": "units/",
|
"units_path": "units/",
|
||||||
"logs_path": "logs/",
|
"logs_path": "logs/",
|
||||||
"shells_path": "shells/shells.definitions",
|
"shells_path": "shells/",
|
||||||
"config_version": "5"
|
"config_version": "5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
sample/shells/shells.definitions → sample/shells/bash.shell
Executable file → Normal file
6
sample/shells/shells.definitions → sample/shells/bash.shell
Executable file → Normal file
@@ -5,12 +5,6 @@
|
|||||||
"path": "/usr/bin/bash",
|
"path": "/usr/bin/bash",
|
||||||
"execution_arg": "-c",
|
"execution_arg": "-c",
|
||||||
"source_cmd": "source"
|
"source_cmd": "source"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ksh",
|
|
||||||
"path": "/usr/bin/ksh",
|
|
||||||
"execution_arg": "-c",
|
|
||||||
"source_cmd": "source"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
10
sample/shells/ksh.shell
Normal file
10
sample/shells/ksh.shell
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"shells": [
|
||||||
|
{
|
||||||
|
"name": "ksh",
|
||||||
|
"path": "/usr/bin/ksh",
|
||||||
|
"execution_arg": "-c",
|
||||||
|
"source_cmd": "source"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -197,26 +197,44 @@ void Conf::checkPathExists( std::string keyname, const std::string &path ) {
|
|||||||
*/
|
*/
|
||||||
void Conf::load_shells() {
|
void Conf::load_shells() {
|
||||||
this->slog.log_task( E_DEBUG, "SHELLS", "Loading shells..." );
|
this->slog.log_task( E_DEBUG, "SHELLS", "Loading shells..." );
|
||||||
try {
|
|
||||||
// load the test file.
|
|
||||||
this->load_json_file( this->shell_definitions_path );
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
this->slog.log_task( E_FATAL, "SHELLS", "Unable to load shell definition file: '" + this->shell_definitions_path + "'. Error: " + e.what());
|
|
||||||
throw ConfigLoadException("Parsing error in shell definitions file.");
|
|
||||||
}
|
|
||||||
Json::Value jbuff;
|
|
||||||
|
|
||||||
if ( this-> get_serialized( jbuff, "shells" ) != 0 ) {
|
std::vector<std::string> shell_files;
|
||||||
this->slog.log_task( E_FATAL, "SHELLS", "Parsing error: '" + this->shell_definitions_path + "'. Error: 'shells' key not found." );
|
|
||||||
throw ConfigLoadException("Parsing error in shell definitions file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Shell tmp_S = Shell( this->LOG_LEVEL );
|
if ( is_dir( this->shell_definitions_path ) )
|
||||||
for ( int index = 0; index < jbuff.size(); index++ )
|
|
||||||
{
|
{
|
||||||
tmp_S.load_root( jbuff[index] );
|
get_shells_from_dir( &shell_files, this->shell_definitions_path );
|
||||||
this->shells.push_back( tmp_S );
|
}
|
||||||
this->slog.log_task( E_DEBUG, "SHELLS", "Loaded shell: '" + tmp_S.name + "' (" + tmp_S.path + ")" );
|
|
||||||
|
if ( is_file( this->shell_definitions_path ) )
|
||||||
|
{
|
||||||
|
shell_files.push_back( this->shell_definitions_path );
|
||||||
|
}
|
||||||
|
|
||||||
|
this->slog.log_task( E_INFO, "SHELLS", "Shell files found: " + std::to_string( shell_files.size() ) );
|
||||||
|
|
||||||
|
for ( int i = 0; i < shell_files.size(); i++ )
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
this->load_json_file( shell_files[i] );
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
this->slog.log_task( E_FATAL, "SHELLS", "Unable to load shell definition file: '" + shell_files[i] + "'. Error: " + e.what());
|
||||||
|
throw ConfigLoadException("Parsing error in shell definitions file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value jbuff;
|
||||||
|
|
||||||
|
if ( this->get_serialized( jbuff, "shells" ) != 0 ) {
|
||||||
|
this->slog.log_task( E_FATAL, "SHELLS", "Parsing error: '" + shell_files[i] + "'. Error: 'shells' key not found." );
|
||||||
|
throw ConfigLoadException("Parsing error in shell definitions file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Shell tmp_S = Shell( this->LOG_LEVEL );
|
||||||
|
for ( int index = 0; index < jbuff.size(); index++ )
|
||||||
|
{
|
||||||
|
tmp_S.load_root( jbuff[index] );
|
||||||
|
this->shells.push_back( tmp_S );
|
||||||
|
this->slog.log_task( E_DEBUG, "SHELLS", "Loaded shell: '" + tmp_S.name + "' (" + tmp_S.path + ")" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,4 +61,39 @@ int Shell::load_root( Json::Value loader_root )
|
|||||||
throw ShellException("No source_cmd attribute specified when loading a shell definition.");
|
throw ShellException("No source_cmd attribute specified when loading a shell definition.");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void get_shells_from_dir( std::vector<std::string> * files, std::string path )
|
||||||
|
{
|
||||||
|
DIR* dirFile = opendir( path.c_str() );
|
||||||
|
if ( dirFile )
|
||||||
|
{
|
||||||
|
struct dirent* hFile;
|
||||||
|
errno = 0;
|
||||||
|
while (( hFile = readdir( dirFile )) != NULL )
|
||||||
|
{
|
||||||
|
if ( !strcmp( hFile->d_name, "." ))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( !strcmp( hFile->d_name, ".." ))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// hidden files
|
||||||
|
if ( hFile->d_name[0] == '.' )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strstr( hFile->d_name, ".shell" ))
|
||||||
|
{
|
||||||
|
std::string full_path = path + "/" + hFile->d_name;
|
||||||
|
files->push_back( full_path );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir( dirFile );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,11 @@
|
|||||||
#define REX_SHELLS_H
|
#define REX_SHELLS_H
|
||||||
|
|
||||||
#include "../json_support/JSON.h"
|
#include "../json_support/JSON.h"
|
||||||
|
#include "../misc/helpers.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
class Shell: public JSON_Loader {
|
class Shell: public JSON_Loader {
|
||||||
public:
|
public:
|
||||||
@@ -23,4 +27,6 @@ class Shell: public JSON_Loader {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void get_shells_from_dir( std::vector<std::string> * files, std::string path );
|
||||||
|
|
||||||
#endif //REX_SHELLS_H
|
#endif //REX_SHELLS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user