-
Notifications
You must be signed in to change notification settings - Fork 1
/
fileVersion.m
190 lines (172 loc) · 6.27 KB
/
fileVersion.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
function tasks=fileVersion(tasks,varargin)
% fileVersion search for version number and checks that needed functions are available as described in
% 'task=project.pipeline.taskSetup{TaskIndex,MethodIndex}'
%
% fileVersion is checking for:
% function_wrapper
% function_name (if exist in field). Note that a function_wrapper dont have to use a function_name!
% configuratorfile (if exist in field)
% configurator_wrapper(if exist in field)
%
% Input:
% tasks : task=project.pipeline.taskSetup{TaskIndex,MethodIndex}'
% varargin :
% varargin{1}:filename of single file to check for
% varargin{2}:versionlabel to search for
% Output:
% tasks: As input but with an extra filestatus
%
% Uses special functions:
%
%____________________________________________
% T. Dyrby, 190303, NRU
%
%SW version: 250803TD
% -OK 240803TD: Add possibility to check only a single file
% -OK 250803TD: Add check of configurator wrapper and if exist configurator_name
%________ Initialisation
status='';%Reset status cell-array
if(isunix)
os='UNIX';
else
os='WINDOWS';
end
%____ Check a single filename
if(length(varargin))
chkFilename=varargin{1};
versionlabel=varargin{2};
names=which(chkFilename,'-all');
for(i=1:length(names))
if(isempty(names(i)))
status{end+1}.indexname='check of single filename';
status{end}.exist=0;
status{end}.version='';
status{end}.path='';
status{end}.filename='';
status{end}.os=os;
else
[path,name,ext] = fileparts(names{i});
status{end+1}.indexname='check of single filename';
status{end}.exist=1;
status{end}.version=search(names{i},versionlabel);%Get label thats describe the SWversion
status{end}.path=path;
status{end}.filename=[name,ext];
status{end}.os=os;
end
end%for
tasks=status;
return
end
%________ Exist?:Function_wrapper name, Version, path
names=which(tasks.function_wrapper,'-all');
if(isempty(names))
tasks.filesexist=0;%problem finding program
status{end+1}.indexname='function_wrapper';
status{end}.exist=0;
status{end}.version='';
status{end}.path='';
status{end}.filename='';
status{end}.os=os;
else
tasks.filesexist=1;%Programfiles exist
[path,name,ext] = fileparts(names{1});
status{end+1}.indexname='function_wrapper';
status{end}.exist=1;
status{end}.version=search(names{1},tasks.versionlabel);%Get label thats describe the SWversion
status{end}.path=path;
status{end}.filename=[name,ext];
status{end}.os=os;
end
%________(OPTIONAL:NOTE afunction_wrapper could do the same as a function_wrapper) Exist?:Function_name, Version, path
if(~isempty(tasks.function_name))
names=which(tasks.function_name,'-all');
if(isempty(names))
tasks.filesexist=0;%problem finding program
status{end+1}.indexname='function_name';
status{end}.exist=0;
status{end}.version='';
status{end}.path='';
status{end}.filename='';
status{end}.os=os;
else
tasks.filesexist=1;%Programfiles exist
[path,name,ext] = fileparts(names{1});
status{end+1}.indexname='function_name';
status{end}.exist=1;
status{end}.version=search(names{1},tasks.versionlabel);%Get label thats describe the SWversion
status{end}.path=path;
status{end}.filename=[name,ext];
status{end}.os=os;
end
end
% %________ (OPTIONAL) Exist?:Configurator_name, Version, path
%____ Do configurator wrapper exist
if(~isempty(tasks.configurator_wrapper))%Check if function name is given to configurator_name
names=which(tasks.configurator_wrapper,'-all');
if(isempty(names))%Configurator exist
tasks.filesexist=0;%problem finding program
status{end+1}.indexname='';
status{end}.exist=0;
status{end}.version='';
status{end}.path='';
status{end}.filename='';
status{end}.os=os;
else
tasks.filesexist=1;%Programfiles exist
[path,name,ext] = fileparts(names{1});
status{end+1}.indexname='configuratorfile';
status{end}.exist=1;
status{end}.version=search(names{1},tasks.versionlabel);%Get label thats describe the SWversion
status{end}.path=path;
status{end}.filename=[name,ext];
status{end}.os=os;
end
%If given do a function configurator_name exist
if(~isempty(tasks.configurator.configurator_name))%Check if function name is given to configurator_name
names=which(tasks.configurator_wrapper,'-all');
if(isempty(names))%Configurator exist
tasks.filesexist=0;%problem finding program
status{end+1}.indexname='';
status{end}.exist=0;
status{end}.version='';
status{end}.path='';
status{end}.filename='';
status{end}.os=os;
else
tasks.filesexist=1;%Programfiles exist
[path,name,ext] = fileparts(names{1});
status{end+1}.indexname='configuratorfile';
status{end}.exist=1;
status{end}.version=search(names{1},tasks.versionlabel);%Get label thats describe the SWversion
status{end}.path=path;
status{end}.filename=[name,ext];
status{end}.os=os;
end
end
end%end configurator_wrapper
%________ Add status to project
tasks.filestatus=status;
%____________________________________________
% search for version label in given matlabfile (text)
%
%
%____________________________________________
% T. Dyrby, 190303, NRU
function version=search(filename,literal)
% Search for number of string matches per line.
fid = fopen(filename, 'rt');
y = 0;
version='';
while feof(fid) == 0
tline = fgetl(fid);
matches = strfind(lower(tline), lower(literal));
num = length(matches);
if num > 0
version=tline;
break
end
end
if(length(version)==0)
version=sprintf('''%s'' not found in filename',literal);
end
fclose(fid);