Commit 47a18ab6 authored by Celine Noirot's avatar Celine Noirot

Merge branch 'issue#129.2' into 'master'

Big update for the switch_space_id workflow

See merge request !80
parents 34b38cac e792d387
......@@ -743,7 +743,7 @@ class Analysis (Component):
raise Exception("Error while trying to rsync " + old_path + " to " + new_absolute_path + "\n" +
"Command : " + str_cmd + "\n" + "Error code : " + str(retcode) + "\n")
else:
print ("rsync could not be launched because the source and destination are the same, from " + old_path + " to " + new_absolute_path + "\n")
str_cmd = "Source and destination directories are the same : " + old_path + " , ignored.\n"
new_retention = ng6conf.get_retention_date(space_id, self.date)
......@@ -751,4 +751,4 @@ class Analysis (Component):
t3mysql.update_fields('tx_nG6_analyze', str(self.id), ['directory','retention_date'], [str("/"+new_relative_path),new_retention] )
return [retcode, str_cmd]
\ No newline at end of file
......@@ -494,7 +494,7 @@ class Run(object):
raise Exception("Error while trying to rsync " + old_path + " to " + new_absolute_path + "\n" +
"Command : " + str_cmd + "\n" + "Error code : " + str(retcode) + "\n")
else:
print ("rsync could not be launched because the source and destination are the same, from " + old_path + " to " + new_absolute_path + "\n")
str_cmd = "Source and destination directories are the same : " + old_path + " , ignored.\n"
new_retention = ng6conf.get_retention_date(space_id, self.date)
......
......@@ -388,7 +388,6 @@ class Utils(object):
vals = prefixed_id.split('_')
prefix = vals[0]
id = vals[1]
if prefix == "data" or prefix == "run" :
run = t3mysql.select_run_informations(id)
source_dir = data_folder +'/'+ run['directory']
......@@ -398,6 +397,7 @@ class Utils(object):
run_name = Utils.get_run_dirname(id,run['name'])
raw_data_dir = os.path.join( output_folder, project_name, run_name, "RawData" )
print (run, source_dir,project_name,run_name)
if source_dir not in src_directories :
src_directories.append(source_dir)
if raw_data_dir not in dest_directories :
......@@ -451,6 +451,9 @@ class Utils(object):
@staticmethod
def rsync_getcmd( source, destination):
if source == "" or not os.path.isdir(source) :
return [ 0, "Source directory '" + source + "' doesn't exist, ignored."]
if not source.endswith("/"):
source+="/"
cmd = ["rsync", "-avh", "--perms", "--times", "--remove-sent-files", source, destination]
......
......@@ -29,53 +29,54 @@ def migrate_project (project_id, new_space_id, output):
from ng6.analysis import Analysis
from ng6.project import Project
from ng6.run import Run
with open( output,'w') as fh :
ng6conf = NG6ConfigReader()
base_path = ng6conf.get_save_directory()
project = Project.get_from_id(project_id)
logging.getLogger("migrate_project").debug("Migrating project '" + str(project.name) + "' (" + str(project.id) + ") to " + str(new_space_id) + "\n")
fh.write("Migrating project '" + str(project.name) + "' (" + str(project.id) + ") to " + str(new_space_id) + "\n")
def log_to_output_files (log_text, log_file):
fh = open(log_file, "a")
fh.write(log_text)
fh.close()
logging.getLogger("move_project.py").debug(log_text)
print( "os.path.exists("+log_file+")=" + str(os.path.exists(log_file)))
ng6conf = NG6ConfigReader()
base_path = ng6conf.get_save_directory()
old_space_id = project.space_id
logging.getLogger("migrate_project").debug("old_space_id = " + old_space_id + ", new_space_id = " + new_space_id + "\n")
fh.write("old_space_id = " + old_space_id + ", new_space_id = " + new_space_id + "\n")
project = Project.get_from_id(project_id)
old_space_id = project.space_id
str_log="MIGRATE PROJECT: '" + str(project.name) + "' (" + str(project.id) + ") from " + old_space_id + " to " + str(new_space_id) + "\n"
log_to_output_files(str_log, output)
runs = project.get_runs()
for run in runs :
str_log="\t - ##RUN '" + run.name + "' (" + str(run.id) + ") - " + run.directory + "\n"
log_to_output_files(str_log, output)
str_cmds = []
runs = project.get_runs()
for run in runs :
fh.write("Migrating run '" + run.name + "' (" + str(run.id) + ")" + " to " + str(new_space_id) + "\n")
logging.getLogger("migrate_project").debug("Migrating run '" + run.name + "' (" + str(run.id) + ")" + " to " + str(new_space_id) + "\n")
str_cmds.append(run.change_space(new_space_id) )
fh.write("Migrating successful! \n")
logging.getLogger("migrate_project").debug("Migrating successful! \n")
run_analyzes = run.get_analysis()
for analysis in run_analyzes :
fh.write("Migrating analysis '" + analysis.name + "' (" + str(analysis.id) + ")" + " to " + str(new_space_id) + "\n")
logging.getLogger("migrate_project").debug("Migrating analysis '" + analysis.name + "' (" + str(analysis.id) + ")" + " to " + str(new_space_id) + "\n")
str_cmds.append(analysis.change_space(new_space_id) )
fh.write("Migrating successful! \n")
logging.getLogger("migrate_project").debug("Migrating successful! \n")
(ret_code, ret_command) = run.change_space(new_space_id)
str_log = "\t RET CODE: " + str(ret_code) + " CMD : " + ret_command + "\n"
log_to_output_files(str_log, output)
run_analyzes = run.get_analysis()
for analysis in run_analyzes :
str_log = "\t\t - ###ANALYSE " + analysis.name+ "' (" + str(analysis.id) + ") - " + analysis.directory + "\n"
log_to_output_files(str_log, output)
analyzes = project.get_analysis()
for analysis in analyzes :
fh.write("Migrating analysis '" + analysis.name + "' (" + str(analysis.id) + ")" + " to " + str(new_space_id) + "\n")
logging.getLogger("migrate_project").debug("Migrating analysis '" + analysis.name + "' (" + str(analysis.id) + ")" + " to " + str(new_space_id) + "\n")
str_cmds.append(analysis.change_space(new_space_id) )
fh.write("Migrating successful! \n")
logging.getLogger("migrate_project").debug("Migrating successful! \n")
for command in str_cmds:
fh.write("Command launched : "+ str(command[1]) + "\n" )
logging.getLogger("migrate_project").debug("Command launched : "+ str(command[1]) + "\n" )
fh.write("Returned code : "+ str(command[0]) + "\n" )
logging.getLogger("migrate_project").debug("Returned code : "+ str(command[0]) + "\n" )
project.update_space_id(new_space_id)
(ret_code, ret_command) = analysis.change_space(new_space_id)
str_log = "\t\t RET CODE: " + str(ret_code) + " CMD : " + ret_command + "\n"
log_to_output_files(str_log, output)
analyzes = project.get_analysis()
for analysis in analyzes :
str_log="\t - ##ANALYSE PROJECT '" + analysis.name + "' (" + str(analysis.id) + ") - " + analysis.directory + "\n"
log_to_output_files(str_log, output)
(ret_code, ret_command) = analysis.change_space(new_space_id)
str_log = "\tRET CODE: " + str(ret_code) + " CMD : " + ret_command + "\n"
log_to_output_files(str_log, output)
project.update_space_id(new_space_id)
str_log = "project.update_space_id DONE\n"
log_to_output_files(str_log, output)
class MoveProject (Component):
......
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