diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py index 681c3e2543e0b3b22bb5cd0fbf6f815f2afb4f9a..dd37dad935980f8ae0649c90749b081b4d45e0c9 100644 --- a/cal_tools/cal_tools/tools.py +++ b/cal_tools/cal_tools/tools.py @@ -15,10 +15,29 @@ import time from uuid import uuid4 +def atoi(text): + ''' + Convert string to integer is possible + + :param text: string to be converted + :return: integer value or input string + ''' + + return int(text) if text.isdigit() else text + + +def natural_keys(text): + ''' + Decompose string to list of integers and sub-strings + ''' + return [ atoi(c) for c in re.split(r'(\d+)', text) ] + + def combine_report(run_path, calibration): sphinx_path = "{}/sphinx_rep".format(os.path.abspath(run_path)) os.makedirs(sphinx_path) direntries = os.listdir(run_path) + direntries.sort(key=natural_keys) for entry in direntries: