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

Utils.py update

The get_directories_structure_and_content() function has been reworked
to make the projects, runs and analyzes names normalization way more
consistent. This will solve the differences between sources and
destinations in this function.

issue #153
parent 96df9089
......@@ -361,6 +361,17 @@ class Utils(object):
return "".join(dec)
"""
@staticmethod
def get_project_dirname(project_id, project_name):
return "Project_%s.%s" % ( re.sub( r"[\s\/]", "_", project_name), project_id )
@staticmethod
def get_run_dirname(run_id, run_name):
return "Run_%s.%s" % ( re.sub( r"[^A-Za-z0-9]", "_", run_name), run_id)
@staticmethod
def get_analyse_dirname(analyse_id, analyse_name):
return "Analyse_%s.%s"%( re.sub( r"[\s\/]", "_", analyse_name), analyse_id )
@staticmethod
def get_directories_structure_and_content(ng6_username, data_folder, output_folder, prefixed_ids):
from ng6.t3MySQLdb import t3MySQLdb
......@@ -372,6 +383,7 @@ class Utils(object):
try : user_id = t3mysql.get_user_id(ng6_username)
except : pass
for prefixed_id in prefixed_ids.split(';') :
vals = prefixed_id.split('_')
prefix = vals[0]
......@@ -380,10 +392,10 @@ class Utils(object):
if prefix == "data" or prefix == "run" :
run = t3mysql.select_run_informations(id)
source_dir = data_folder +'/'+ run['directory']
project_name = "Project_%s.%s" % ( re.sub( r"[\s\/]", "_", run['project_name']), run['project_id'] )
project_name = Utils.get_project_dirname(run['project_id'],run['project_name'])
#run_name = "Run_%s.%s" %( run['name'].replace(' ', '_').replace('/', '_'), id )
run_name = "Run_%s.%s" % ( re.sub( r"[^A-Za-z0-9]", "_", run['name']), id)
run_name = Utils.get_run_dirname(id,run['name'])
raw_data_dir = os.path.join( output_folder, project_name, run_name, "RawData" )
if source_dir not in src_directories :
......@@ -394,7 +406,7 @@ class Utils(object):
if prefix == "run" :
for analyse_id, analyse_values in t3mysql.get_user_run_analysis(user_id, id, 'tx_nG6_analyze.name').items() :
analysis_dir = data_folder + '/' + analyse_values["directory"]
analysis_name = "Analyse_%s.%s"%( re.sub( r"[\s\/]", "_", analyse_values['name']), analyse_id )
analysis_name = Utils.get_analyse_dirname(analyse_id, analyse_values['name'] )
dest_analysis_dir = os.path.join( output_folder, project_name, run_name, analysis_name )
if analysis_dir not in src_directories :
......@@ -409,19 +421,19 @@ class Utils(object):
if source_dir not in src_directories :
src_directories.append(source_dir)
project_name = "Project_%s.%s" % ( re.sub( r"[\s\/]", "_", analyse["project_name"]), analyse["project_id"])
project_name = Utils.get_project_dirname(analyse['project_id'],analyse['project_name'])
# it's a run analysis
if analyse["run_id"]:
run_name = "Run_%s.%s" % ( re.sub( r"[\s\/]", "_", analyse["run_name"]), analyse["run_id"])
analysis_name = "Analyse_%s.%s" % ( re.sub( r"[\s\/]", "_", analyse["name"]), id)
if analyse["run_id"]:
run_name = Utils.get_run_dirname(analyse["run_id"], analyse["run_name"])
analysis_name = Utils.get_analyse_dirname(id, analyse['name'] )
dest_analysis_dir = os.path.join( output_folder, project_name, run_name, analysis_name )
if dest_analysis_dir not in dest_directories :
dest_directories.append(dest_analysis_dir)
# it's a project analysis
else :
analysis_name = "Project_analyses/%s.%s" % ( re.sub( r"[\s\/]", "_", analyse["name"]), id)
analysis_name = "Project_"+ Utils.get_analyse_dirname(id, analyse['name'] )
dest_analysis_dir = os.path.join( output_folder, project_name, analysis_name )
if dest_analysis_dir not in dest_directories :
dest_directories.append(dest_analysis_dir)
......
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