From ff5568d0ecb81a10f5715e81fd13420855693a0b Mon Sep 17 00:00:00 2001 From: Luke Simons <luke.simons@epfl.ch> Date: Fri, 7 Mar 2025 18:08:26 +0100 Subject: [PATCH] Changed tcv_get_deploymentinfo to take function name --- matlab/TCV_IMAS/tcv_get_deploymentinfo.m | 83 ++++++++++++----------- matlab/TCV_IMAS/tcv_get_ids_soft_x_rays.m | 2 +- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/matlab/TCV_IMAS/tcv_get_deploymentinfo.m b/matlab/TCV_IMAS/tcv_get_deploymentinfo.m index 576b97c..f5562e1 100644 --- a/matlab/TCV_IMAS/tcv_get_deploymentinfo.m +++ b/matlab/TCV_IMAS/tcv_get_deploymentinfo.m @@ -1,55 +1,60 @@ -function info = tcv_get_deploymentinfo(filepath) +function info = tcv_get_deploymentinfo(function_name) % Reads a deployment info file and extracts relevant details % Author: L. Simons % Date: 07/03/25 % % Args: - % filepath: Path to the text file + % function_name: String, name of function % % Returns: % info: Struct containing extracted information % Initialize output struct info = struct(); - info.repository=fileparts(filepath); - - % Check if file exists - if exist(filepath, 'file') ~= 2 - error('File does not exist: %s', filepath); - end - - % Open file for reading - fid = fopen(filepath, 'r'); - if fid == -1 - error('Could not open file: %s', filepath); - end - - % Read file line by line - while ~feof(fid) - line = fgetl(fid); - if ischar(line) - tokens = regexp(line, '^(\w+):\s(.+)$', 'tokens'); - if ~isempty(tokens) - key = tokens{1}{1}; - value = strtrim(tokens{1}{2}); - - % Store relevant fields in the struct - switch key - case 'DEPLOYMENT_DATE' - info.deployment_date = value; - case 'GIT_TAG' - info.git_tag = value; - case 'GIT_COMMIT' - info.git_commit = value; - case 'GIT_TAG_DATE' - info.git_tag_date = value; - case 'GITLAB_PROJECT_URL' - info.gitlab_project_url = value; + try + filepath=fullfile(fileparts(which(function_name)),'.this-deployment.info'); + info.repository=fileparts(filepath); + + % Check if file exists + if exist(filepath, 'file') ~= 2 + error('File does not exist: %s', filepath); + end + + % Open file for reading + fid = fopen(filepath, 'r'); + if fid == -1 + error('Could not open file: %s', filepath); + end + + % Read file line by line + while ~feof(fid) + line = fgetl(fid); + if ischar(line) + tokens = regexp(line, '^(\w+):\s(.+)$', 'tokens'); + if ~isempty(tokens) + key = tokens{1}{1}; + value = strtrim(tokens{1}{2}); + + % Store relevant fields in the struct + switch key + case 'DEPLOYMENT_DATE' + info.deployment_date = value; + case 'GIT_TAG' + info.git_tag = value; + case 'GIT_COMMIT' + info.git_commit = value; + case 'GIT_TAG_DATE' + info.git_tag_date = value; + case 'GITLAB_PROJECT_URL' + info.gitlab_project_url = value; + end end end end + + % Close the file + fclose(fid); + catch + warning('Failed to read .deployment at filepath: %s',filepath); end - - % Close the file - fclose(fid); end diff --git a/matlab/TCV_IMAS/tcv_get_ids_soft_x_rays.m b/matlab/TCV_IMAS/tcv_get_ids_soft_x_rays.m index b9fd4b3..5cdf1cf 100644 --- a/matlab/TCV_IMAS/tcv_get_ids_soft_x_rays.m +++ b/matlab/TCV_IMAS/tcv_get_ids_soft_x_rays.m @@ -125,7 +125,7 @@ if status ids_soft_x_rays.code.name = 'rc_load_diodes'; ids_soft_x_rays.code.description = ['rc_load_diodes, RADCAM gitlab repo, loads' ... 'the signal from the SXR diodes in arbitrary units.']; - radcam_gitinfo = tcv_get_deploymentinfo(fullfile(fileparts(which(ids_soft_x_rays.code.name)),'.this-deployment.info')); + radcam_gitinfo = tcv_get_deploymentinfo(ids_soft_x_rays.code.name); ids_soft_x_rays.code.commit=library_gitinfo.git_commit; ids_soft_x_rays.code.version=library_gitinfo.git_tag; ids_soft_x_rays.code.repository=library_gitinfo.git_project_url; -- GitLab