Commit 9a64afbb authored by Romain Therville's avatar Romain Therville 🐭
Browse files

New log file added and tested

("/work/ng6-test/jflow_rtherville/ng6_python.log") -> has to be updated.


Issue  #219
parent 5687a776
......@@ -40,21 +40,33 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
self.add_parameter('project_id', 'The project id', type=int, required = True)
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
from datetime import datetime
#We open a log file
f = open("/work/ng6-test/jflow_rtherville/ng6_python.log", "a")
#f = open(os.path.join(os.path.dirname(__file__), '../../ng6_python.log'), "a")
now = datetime.now()
datetime = now.strftime("%d/%m/%Y %H:%M:%S")
logging.getLogger("SwitchProjectSpaceId.process").debug(datetime + " Begin SwitchProjectSpaceId workflow.")
f.write("\n\n" + datetime + " Begin SwitchProjectSpaceId workflow.\n")
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) )
f.write("project_id =" + str(self.project_id) + " , new space_id = " + str(self.space_id) +"\n")
project = Project.get_from_id(self.project_id)
old_space_id = project.space_id
#We raise an error and return None if the project already has the given space_id
#We log a message if the project already has the given space_id
if str(old_space_id) == str(self.space_id) :
raise Exception("The project " + project.name + " already belongs to the space_id '" + str(self.space_id) + "'" )
return None
logging.getLogger("SwitchProjectSpaceId.process").debug("The project " + project.name + " already belongs to the space_id '" + str(self.space_id) + "'\n" )
f.write("The project " + project.name + " already belongs to the space_id '" + str(self.space_id) + "'\n" )
#Retrieve the old and new directories
ng6conf = NG6ConfigReader()
......@@ -63,7 +75,8 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
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))
f.write("Error while searching space_id '" + str(self.space_id) + "' in application.properties, it certainly doesn't exist. \n" + str(err) + "\n")
raise Exception("Error while searching space_id '" + str(self.space_id) + "' in application.properties, it certainly doesn't exist. \n" + str(err) + "\n")
base_path = ng6conf.get_save_directory()
......@@ -71,6 +84,8 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
runs_ids = project.get_project_run_ids()
for run_id in runs_ids :
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating run " + str(run_id) )
f.write("Migrating run " + str(run_id) + "\n")
run = Run.get_from_id(run_id)
path_old_run_directory = base_path + run.get_directory()
......@@ -80,31 +95,36 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
new_run_directory = run.get_directory()
new_run_directory = new_run_directory.replace(old_directory, new_directory)
#Moving the files
#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) )
logging.getLogger("SwitchProjectSpaceId.process").debug("Beginning run files migration, from " + str(path_old_run_directory) + " to " + str(path_new_run_directory) +"\n" )
f.write("Beginning run files migration, from " + str(path_old_run_directory) + " to " + str(path_new_run_directory) +"\n" )
try:
shutil.move(path_old_run_directory, path_new_run_directory)
except Exception as err:
logging.getLogger("SwitchProjectSpaceId.process").error("Error while moving " + path_old_run_directory + " to " + path_new_run_directory + " \n" + str(err))
logging.getLogger("SwitchProjectSpaceId.process").error("Error while moving " + path_old_run_directory + " to " + path_new_run_directory + " \n" + str(err) + "\n")
f.write("Error while moving " + path_old_run_directory + " to " + path_new_run_directory + " \n" + str(err) + "\n")
raise Exception("Error while moving " + path_old_run_directory + " to " + path_new_run_directory + " \n" + str(err))
#Delete the old directory if empty
if os.path.isdir(path_old_run_directory) and not os.listdir(path_old_run_directory) :
os.rmdir(path_old_run_directory)
try:
os.rmdir(path_old_run_directory)
except Exception as err:
logging.getLogger("SwitchProjectSpaceId.process").error("Error while deleting " + path_old_run_directory + "\n" + str(err) + "\n")
f.write("Error while deleting " + path_old_run_directory + "\n" + str(err) + "\n")
raise Exception("Error while deleting " + path_old_run_directory + "\n" + str(err) + "\n")
#Update the retention in DB
old_retention = run.get_creation_date()
new_retention = ng6conf.compute_new_retention_date(self.space_id,old_retention)
run.set_retention(new_retention)
run.set_directory(new_run_directory)
run.set_directory(new_run_directory)
#Process for the project's analyzes
analyzes_ids = project.get_project_analyzes_ids()
for analysis_id in analyzes_ids :
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating analysis " + str(analysis_id) )
f.write("Migrating analysis " + str(analysis_id) + "\n")
analysis = Analysis.get_from_id(analysis_id)
path_old_analysis_directory = base_path + analysis.get_directory()
......@@ -114,20 +134,23 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
new_analysis_directory = analysis.get_directory()
new_analysis_directory = new_analysis_directory.replace(old_directory, new_directory)
#Moving the files
#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) )
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating analysis files from " + str(path_old_analysis_directory) + " to " + str(path_new_analysis_directory) + "\n" )
f.write( "Beginning analysis files migration, from " + str(path_old_analysis_directory) + " to " + str(path_new_analysis_directory) + "\n" )
try:
shutil.move(path_old_analysis_directory, path_new_analysis_directory)
except Exception as err:
logging.getLogger("SwitchProjectSpaceId.process").error("Error while moving " + path_old_analysis_directory + " to " + path_new_analysis_directory + " \n" + str(err))
raise Exception("Error while moving " + path_old_analysis_directory + " to " + path_new_analysis_directory + " \n" + str(err))
logging.getLogger("SwitchProjectSpaceId.process").error("Error while moving " + path_old_analysis_directory + " to " + path_new_analysis_directory + " \n" + str(err) + "\n")
f.write("Error while moving " + path_old_analysis_directory + " to " + path_new_analysis_directory + "\n" + str(err) + "\n")
raise Exception("Error while moving " + path_old_analysis_directory + " to " + path_new_analysis_directory + " \n" + str(err) + "\n")
#Delete the old directory if empty
if os.path.isdir(path_old_analysis_directory) and not os.listdir(path_old_analysis_directory) :
os.rmdir(path_old_analysis_directory)
try:
os.rmdir(path_old_analysis_directory)
except Exception as err:
logging.getLogger("SwitchProjectSpaceId.process").error("Error while deleting " + path_old_analysis_directory + "\n" + str(err) + "\n")
f.write("Error while deleting " + path_old_analysis_directory + "\n" + str(err) + "\n")
raise Exception("Error while deleting " + path_old_analysis_directory + "\n" + str(err) + "\n")
#Update the retention in DB
old_retention = analysis.get_creation_date()
......@@ -138,7 +161,8 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
#Process for the project's run's analyzes
run_analyzes_ids = project.get_project_runs_analyzes_ids()
for analysis_id in run_analyzes_ids :
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating analysis " + str(analysis_id) )
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating analysis " + str(analysis_id) + "\n")
f.write("Migrating analysis " + str(analysis_id) + "\n")
analysis = Analysis.get_from_id(analysis_id)
path_old_analysis_directory = base_path + analysis.get_directory()
......@@ -148,20 +172,23 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
new_analysis_directory = analysis.get_directory()
new_analysis_directory = new_analysis_directory.replace(old_directory, new_directory)
#Moving the files
#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) )
logging.getLogger("SwitchProjectSpaceId.process").debug("Migrating analysis files from " + str(path_old_analysis_directory) + " to " + str(path_new_analysis_directory) + "\n" )
f.write( "Beginning analysis files migration, from " + str(path_old_analysis_directory) + " to " + str(path_new_analysis_directory) + "\n" )
try:
shutil.move(path_old_analysis_directory, path_new_analysis_directory)
except Exception as err:
logging.getLogger("SwitchProjectSpaceId.process").error("Error while moving " + path_old_analysis_directory + " to " + path_new_analysis_directory + " \n" + str(err))
f.write("Error while moving " + path_old_analysis_directory + " to " + path_new_analysis_directory + "\n" + str(err) + "\n")
raise Exception("Error while moving " + path_old_analysis_directory + " to " + path_new_analysis_directory + " \n" + str(err))
#Delete the old directory if empty
if os.path.isdir(path_old_analysis_directory) and not os.listdir(path_old_analysis_directory) :
os.rmdir(path_old_analysis_directory)
try:
os.rmdir(path_old_analysis_directory)
except Exception as err:
logging.getLogger("SwitchProjectSpaceId.process").error("Error while deleting " + path_old_analysis_directory + "\n" + str(err) + "\n")
f.write("Error while deleting " + path_old_analysis_directory + "\n" + str(err) + "\n")
raise Exception("Error while deleting " + path_old_analysis_directory + "\n" + str(err) + "\n")
#Update the retention in DB
old_retention = analysis.get_creation_date()
......@@ -169,5 +196,8 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
analysis.set_retention(new_retention)
analysis.set_directory(new_analysis_directory)
#We close the log file
f.close()
#Update to the projcet's space_id
project.update_space_id(self.space_id)
\ No newline at end of file
project.update_space_id(self.space_id)
\ No newline at end of file
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