Commit de2a3cec authored by Jerome Mariette's avatar Jerome Mariette
Browse files

fix bug in _get_file_description

parent 5fcfd559
......@@ -391,54 +391,48 @@ class Analyse (object):
@param file : the file
@return : the file description
"""
try :
if self.__run :
mids_desc = self.__run.get_mids_description()
else :
run_id = self.__get_run_id()
my_run = Run.get_from_id(run_id)
mids_desc = my_run.get_mids_description()
# Look at all description available
best_description = {}
for mid_desc in mids_desc.keys():
mid_desc_regex = re.compile(".*" + mid_desc + ".*")
#try :
if self.__run :
mids_desc = self.__run.get_mids_description()
else :
run_id = self.__get_run_id()
my_run = Run.get_from_id(run_id)
mids_desc = my_run.get_mids_description()
# Look at all description available
best_description = {}
for mid_desc in mids_desc.keys():
mid_desc_regex = re.compile(".*" + mid_desc + ".*")
mdr = mid_desc_regex.match(file)
if mdr != None:
best_description[mid_desc] = mids_desc[mid_desc]
# If we have more than 1 description available, use the one in between .[desc].
final_descriptions = {}
if len(best_description) > 1:
for bdescription in best_description.keys():
mid_desc_regex = re.compile(".*\." + bdescription + "\..*")
mdr = mid_desc_regex.match(file)
if mdr != None:
best_description[mid_desc] = mids_desc[mid_desc]
# If more than a description match, take the longuest
max_len = 0
final_descriptions = {}
final_description = os.path.splitext(file)[0]
if len(best_description) > 0:
for bdescription in best_description.keys():
# If this is the longuest seen so far
if len(bdescription) > max_len:
max_len = len(bdescription)
final_descriptions = {}
final_descriptions[bdescription] = best_description[bdescription]
final_description = best_description[bdescription]
# If an other one is as long
elif len(bdescription) == max_len:
final_descriptions[bdescription] = best_description[bdescription]
# If we have more than 1 description available, use the one in between .[desc].
if len(final_descriptions) > 1:
for final_desc in final_descriptions.keys():
mid_desc_regex = re.compile(".*\." + final_desc + "\..*")
mdr = mid_desc_regex.match(file)
if mdr != None:
final_description = final_descriptions[final_desc]
# Return the description
return final_description
final_descriptions[bdescription] = best_description[bdescription]
except :
# If more than a description match, take the longuest
max_len = 0
final_description = os.path.splitext(file)[0]
if len(final_descriptions) != 1:
for bdescription in best_description.keys():
# If this is the longuest seen so far
if len(bdescription) > max_len:
max_len = len(bdescription)
final_description = best_description[bdescription]
# Return the description
return final_description
#except :
# Return the file name
return os.path.splitext(file)[0]
# # Return the file name
# return os.path.splitext(file)[0]
def _create_and_archive(self, files, archive_name=None, prefix="dir"):
......
Supports Markdown
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