Skip to content

Commit

Permalink
Add directories to the python.directories
Browse files Browse the repository at this point in the history
This change makes the scripts available for the next time Mantid plot
starts.

re #7097
  • Loading branch information
gesnerpassos authored and OwenArnold committed May 29, 2013
1 parent 9c52454 commit 05e0aec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ namespace API
std::string local_path = std::string(local_repository).append(file_path);
g_log.debug() << "ScriptRepository download url_path: " << url_path << " to " << local_path << std::endl;

std::string dir_path;

try{

Expand All @@ -639,7 +640,7 @@ namespace API
size_t slash_pos = local_path.rfind('/');
Poco::File file_out(local_path);
if (slash_pos != std::string::npos){
std::string dir_path = std::string(local_path.begin(),local_path.begin()+slash_pos);
dir_path = std::string(local_path.begin(),local_path.begin()+slash_pos);
if (!dir_path.empty()){
Poco::File dir_parent(dir_path);
if (!dir_parent.exists()){
Expand All @@ -650,7 +651,7 @@ namespace API

if (!file_out.exists())
file_out.createFile();

tmpFile.copyTo(local_path);

}catch(Poco::FileAccessDeniedException &){
Expand All @@ -667,6 +668,24 @@ namespace API
entry.status = BOTH_UNCHANGED;
}

// Update pythonscripts.directories if necessary (TEST_DOWNLOAD_ADD_FOLDER_TO_PYTHON_SCRIPTS)
if (!dir_path.empty()){
const char * python_sc_option = "pythonscripts.directories";
ConfigServiceImpl & config = ConfigService::Instance();
std::string python_dir = config.getString(python_sc_option);
if (python_dir.find(dir_path) == std::string::npos){
// this means that the directory is not inside the pythonscripts.directories
// add to the repository
python_dir.append(";").append(dir_path);
config.setString(python_sc_option,python_dir);
config.saveConfig(config.getUserFilename());

// the previous code make the path available for the following
// instances of Mantid, but, for the current one, it is necessary
// do add to the python path...
}
}

updateLocalJson(file_path, entry); ///FIXME: performance!
g_log.debug() << "ScriptRepository download " << local_path << " success!"<<std::endl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,6 @@ void test_downloading_locally_modified_file(){
}







void test_list_files_after_download_repository(){
TS_ASSERT_THROWS_NOTHING(repo->install(local_rep));
TS_ASSERT_THROWS_NOTHING(repo->listFiles());
Expand All @@ -690,6 +685,24 @@ void test_downloading_locally_modified_file(){
TS_ASSERT_THROWS_NOTHING(repo->download("TofConv/TofConverter.py"));
}

void test_download_add_folder_to_python_scripts(){
ConfigServiceImpl & config = ConfigService::Instance();
std::string backup_python_directories = config.getString("pythonscripts.directories");

TS_ASSERT_THROWS_NOTHING(repo->install(local_rep));
TS_ASSERT_THROWS_NOTHING(repo->listFiles());
TS_ASSERT_THROWS_NOTHING(repo->download("TofConv/TofConverter.py"));

std::string curr_python_direc = config.getString("pythonscripts.directories");
std::string direc = std::string(local_rep).append("TofConv/");
std::cout << "find for direc " << direc << std::endl;
TS_ASSERT(curr_python_direc.find(direc) != string::npos);


config.setString("pythonscripts.directories", backup_python_directories);
config.saveConfig(config.getUserFilename());
}

/*************************************
* SET IGNORE FILES
*************************************/
Expand Down

0 comments on commit 05e0aec

Please sign in to comment.