Commit a9eb8078 authored by Marco Berzborn's avatar Marco Berzborn

Get name and email from git config instead of the svn license file

parent d8272a76
function userInfo = ita_git_read_config
%ITA_GIT_READ_CONFIG - Get name and email from git config
% This function reads the git config and tries to find the username and
% the users email from the local git config. If either one of them are not
% found, the global git config will be used.
%
% Syntax:
% userInfo = ita_git_read_config()
%
% See also:
% ita_preferences
%
% Reference page in Help browser
% <a href="matlab:doc ita_git_read_config">doc ita_git_read_config</a>
% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved.
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder.
% </ITA-Toolbox>
% Author: Marco Berzborn -- Email: marco.berzborn@akustik.rwth-aachen.de
% Created: 24-Nov-2016
workingDir = pwd;
cd(ita_toolbox_path)
% This will only work if git bash bindings are installed.
% TODO: check TortoiseGit command line version
[userName,userMail,statusName,statusMail] = read_config_with_bindings();
if statusName ~= 0 || statusMail ~= 0
% Do not use ita_verbose_info here, as it will result in an infinite
% loop because of an ita_preferences call
disp('Either git was not found on your machine or your username and e-mail are not set in the configuration. You can set them manually using ita_preferences.');
userName = [];
userMail = [];
end
cd(workingDir);
userInfo.AuthorStr = strcat(userName);
userInfo.EmailStr = strcat(userMail);
end
function [userName,userMail,statusName,statusMail] = read_config_with_bindings()
[statusName,userName] = system('git config --local user.name');
[statusMail,userMail] = system('git config --local user.email');
if statusName ~= 0
[statusName,userName] = system('git config --global user.name');
end
if statusMail ~= 0
[statusMail,userMail] = system('git config --global user.email');
disp('I took your E-Mail from the global git configuration');
end
end
function userinfo = ita_licensefile_read(filename)
% Returns info on the user, read from the license file. licensefile can be specified or will be found automatic
% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved.
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder.
% </ITA-Toolbox>
%% Read file
if nargin == 1 % Filename given
elseif nargin == 0 % Find License automatically
filename = rdir([ita_toolbox_path filesep 'Licenses' filesep '**' filesep 'License*.txt'] );
if numel(filename) > 1
ita_verbose_info('!!! More than one license found !!!',0);
ita_verbose_info('!!! Using first one found !!!',0);
filename = filename(1);
end
if numel(filename) == 0
ita_verbose_info(' No license found ',1); % ToDo: Increase verbose level after everything is checked
userinfo = struct();
return;
end
filename = filename.name;
end
fid = fopen(filename);
uinfo = textscan(fid, '%s%[^\n]');
fclose(fid);
%% Add empty passphrase if passphrase is empty
while size(uinfo{2},1) < size(uinfo{1},1)
uinfo{2} = [uinfo{2}; {''}];
end
%% Merge fielnames and values, replacing ':' with '' on occurence
userinfo = cell2struct(uinfo{2}, strrep(uinfo{1},':',''));
%% Add missing fields
if ~isfield(userinfo,'Comment')
userinfo.Comment = '';
end
end
\ No newline at end of file
function ita_licensefile_write(filename,userinfo)
% Write license file
% Usage: ita_licensefile_write(filename,userinfo)
% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved.
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder.
% </ITA-Toolbox>
%% Open file
fid = fopen(filename,'w');
%% Write every field to file
fieldnames = fields(userinfo);
for idx = 1:numel(fieldnames)
fprintf(fid, '%s\n' ,[fieldnames{idx} ': ' userinfo.(fieldnames{idx}) ]);
end
fclose(fid);
end
\ No newline at end of file
......@@ -121,7 +121,7 @@ elseif nargin == 1
elseif iscellstr(varargin{1})
input = varargin{1};
for idx = 1:numel(input)
varargout{idx} = ita_preferences(input{idx});
varargout{idx} = ita_preferences(input{idx}); %#ok<AGROW>
end
return
elseif isstruct(varargin{1}) % All setting as a struct
......@@ -136,32 +136,36 @@ elseif nargin == 1
%get value from global variable
value = eval(global_preference_name);
if isempty(value)
if any(strcmpi(defined_preferences(:,1),preference_name)) && (any(strcmpi(defined_preferences(strcmpi(defined_preferences(:,1),preference_name),3),'LicenseFile')) || strcmpi(defined_preferences(strcmpi(defined_preferences(:,1),preference_name),3),'*LicenseFile')) % Read from license file
if isempty(userInfo) % Check if global is set
userInfo = ita_licensefile_read; %Read from licensefile
end
if isempty(userInfo) || numel(fieldnames(userInfo)) == 0 % Check if read from licensefile was successfull
ita_verbose_info('License file is empty or does not exist',2) % ToDo: Increase verbose level after everything is checked
else
userInfo.AuthorStr = userInfo.Name; %Backward compatibility
userInfo.EmailStr = userInfo.EMail; %Backward compatibility
if any(strcmpi(defined_preferences(:,1),preference_name))
% Read from git configuration, but only if name and email
% haven't been set already or are the same as the default
% values given in ita_defined_preferences
if isempty(userInfo) && (strcmp(preference_name,'AuthorStr') || strcmp(preference_name,'EmailStr'))
if ispref('RWTH_ITA_ToolboxPrefs',preference_name)
if isempty(getpref('RWTH_ITA_ToolboxPrefs',preference_name)) || ...
strcmp(getpref('RWTH_ITA_ToolboxPrefs',preference_name),'@')
userInfo = ita_git_read_config;
else
userInfo.(preference_name) = getpref('RWTH_ITA_ToolboxPrefs',preference_name);
end
else
userInfo = ita_git_read_config;
end
end
if isfield(userInfo,preference_name)
value = userInfo.(preference_name);
eval([global_preference_name ' = value;']); %Set global for faster access the next time
else % ToDo: This can be cleaned up as soon as everyone has a new license
%error('Value not found in license file');
setpref('RWTH_ITA_ToolboxPrefs',preference_name, value);
else
if ispref('RWTH_ITA_ToolboxPrefs',preference_name) % try to read preference
value = getpref('RWTH_ITA_ToolboxPrefs',preference_name);
else %default
any(strcmpi(defined_preferences(:,1),preference_name))
else
% return default values if preferences is not set
is_defined = strcmpi(defined_preferences(:,1),preference_name);
[idx,jdx] = find(is_defined,1);
value = defined_preferences{idx,jdx+1};
end
eval([global_preference_name ' = value;']);
ita_verbose_info('Reading passphrase from preferences. This will be switched off in the future',2) % ToDo: Increase verbose level after everything is checked
ita_verbose_info('!!! Please ask for a new license !!!',2) % ToDo: Increase verbose level after everything is checked
eval([global_preference_name ' = value;']); %Set global for faster access the next time
end
......@@ -306,7 +310,7 @@ if samplingRateChanged
% seems to work this way, tell portaudio the sampling rate ...
playrec('init',sr,playID,recID);
% ... but then kill the playrec part in matlab
clear mex;
clear mex; %#ok<CLMEX>
end
end
......@@ -318,7 +322,7 @@ elseif nargout == 0
if nargin == 0
%show gui
ita_verbose_info('ita_preferences::clearing mex functions first...',2);
clear mex %clear for playrec & pdi
clear mex %#ok<CLMEX> %clear for playrec & pdi
if usejava('jvm') %Only if jvm available (non_cluster)
ita_preferences_gui_tabs(defined_preferences,tab_names);
else
......
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