Commit a1c47bf3 authored by Romain Therville's avatar Romain Therville 🐭

Bug concerning file paths fixed

issue #129

There was a problem with file's paths. Fixed.
parent f9366424
......@@ -41,12 +41,13 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
self.add_parameter('space_id', 'The new space_id', required = True)
def process(self):
logging.getLogger("SwitchProjectSpaceId.process").debug("Begin SwitchProjectSpaceId workflow.")
#self.space_id = self.space_id
#self.project_id = self.project_id
self.project_id = int(self.project_id)
if self.project_id and self.space_id :
logging.getLogger("SwitchProjectSpaceId.process").debug("project_id =" + str(self.project_id) + " , new space_id = " + str(self.space_id) )
self.project = Project.get_from_id(self.project_id)
old_space_id = self.project.space_id
......@@ -55,35 +56,41 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
raise Exception("The project " + self.project.name + " already belongs to the space_id '" + str(self.space_id) + "'" )
return None
#Update to the projcet's space_id
t3mysql = t3MySQLdb()
t3mysql.update_fields('tx_nG6_project', str(self.project_id), ['space_id'], [str(self.space_id)] )
#Retrieve the old and new directories
ng6conf = NG6ConfigReader()
old_directory = ng6conf.get_space_directory(old_space_id)
new_directory = ng6conf.get_space_directory(self.space_id)
try:
new_directory = ng6conf.get_space_directory(self.space_id)
except Exception as err:
logging.getLogger("SwitchProjectSpaceId.process").error("Error while searching space_id '" + str(self.space_id) + "' in application.properties, it certainly doesn't exist. \n" + str(err))
raise Exception("Error while searching space_id '" + str(self.space_id) + "' in application.properties, it certainly doesn't exist. \n" + str(err))
#new_retention = ng6conf.get_retention_date(self.space_id)
#new_retention = ng6conf.compute_new_retention_date(self.space_id, old_retention)
#Update to the projcet's space_id
t3mysql = t3MySQLdb()
t3mysql.update_fields('tx_nG6_project', str(self.project_id), ['space_id'], [str(self.space_id)] )
base_path = ng6conf.get_save_directory()
#Process for the project's runs
runs_ids = t3mysql.get_project_runs_ids(self.project_id)
for run_id in runs_ids :
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating run " + str(run_id) )
path_old_run_directory = base_path + t3mysql.select_run_directory(run_id)
path_new_run_directory = path_old_run_directory.replace(old_directory,new_directory)
logging.getLogger("SwitchProjectSpaceId.process").debug("path_old_run_directory = " + str(path_old_run_directory) )
logging.getLogger("SwitchProjectSpaceId.process").debug("path_new_run_directory = " + str(path_new_run_directory) )
#Update the directory in DB
new_run_directory = t3mysql.select_run_directory(run_id)
new_run_directory = new_run_directory.replace(old_directory, new_directory)
logging.getLogger("SwitchProjectSpaceId.process").debug("new_run_directory (DB) = " + str(new_run_directory) )
t3mysql.update_fields('tx_nG6_run', str(run_id), ['directory'], [str(new_run_directory)] )
#Moving the files
if not os.path.isdir(path_new_run_directory) :
os.mkdir(path_new_run_directory)
#if not os.path.isdir(path_new_run_directory) :
# os.mkdir(path_new_run_directory,0o775)
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating run files from " + str(path_old_run_directory) + " to " + str(path_new_run_directory) )
try:
shutil.move(path_old_run_directory, path_new_run_directory)
except Exception as err:
......@@ -102,6 +109,7 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
#Process for the project's analyzes
analyzes_ids = t3mysql.get_project_analysis_ids(self.project_id)
for analysis_id in analyzes_ids :
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating analysis " + str(analysis_id) )
path_old_analysis_directory = base_path + t3mysql.select_analysis_directory(analysis_id)
path_new_analysis_directory = path_old_analysis_directory.replace(old_directory,new_directory)
......@@ -111,9 +119,10 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
t3mysql.update_fields('tx_nG6_analyze', str(analysis_id), ['directory'], [str(new_analysis_directory)] )
#Moving the files
if not os.path.isdir(path_new_run_directory) :
os.mkdir(path_new_analysis_directory)
#if not os.path.isdir(path_new_analysis_directory) :
# os.mkdir(path_new_analysis_directory,0o775)
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating analysis files from " + str(path_old_analysis_directory) + " to " + str(path_new_analysis_directory) )
try:
shutil.move(path_old_analysis_directory, path_new_analysis_directory)
except Exception as err:
......@@ -132,6 +141,7 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
#Process for the project's run's analyzes
run_analyzes_ids = t3mysql.get_run_analyzes_id_from_project(self.project_id)
for analysis_id in run_analyzes_ids :
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating analysis " + str(analysis_id) )
path_old_analysis_directory = base_path + t3mysql.select_analysis_directory(analysis_id)
path_new_analysis_directory = path_old_analysis_directory.replace(old_directory,new_directory)
......@@ -141,9 +151,10 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
t3mysql.update_fields('tx_nG6_analyze', str(analysis_id), ['directory'], [str(new_analysis_directory)] )
#Moving the files
if not os.path.isdir(path_new_analysis_directory) :
os.mkdir(path_new_analysis_directory)
#if not os.path.isdir(path_new_analysis_directory) :
# os.mkdir(path_new_analysis_directory,0o775)
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating analysis files from " + str(path_old_analysis_directory) + " to " + str(path_new_analysis_directory) )
try:
shutil.move(path_old_analysis_directory, path_new_analysis_directory)
except Exception as err:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment