[4e19e8]: PKG_ADD Maximize Restore History

Download this file

PKG_ADD    71 lines (61 with data), 2.3 kB

%1
dirlist = {"molecularDynamics", "ocframe", "core"};
dirname = fileparts (canonicalize_file_name (mfilename ("fullpath")));
pp = strsplit (dirname,filesep (), true);
arch = cstrcat (octave_config_info ("canonical_host_type"),
                              "-", octave_config_info ("api_version"));

%% Get the correct path
% Search installed packages
[local_packages, global_packages] = pkg("list");
installed_pkgs_lst = {local_packages{:}, global_packages{:}};
pkg_data = installed_pkgs_lst (cellfun(@(x) ismember (x.name, {"mechanics"}), ...
                                             installed_pkgs_lst, "unif", true));

if isempty(pkg_data)
  % The package is not installed yet
  [pkg_folder dep_folder] = pkg ("prefix");
  pkg_folder = [pkg_folder strcat(filesep(),{pp{end-1:end}}){:} ];
  if strcmp (arch , pp{end})
  %% If we are in Architecture dependent folder add from outside
    pkg_folder = strsplit (pkg_folder,filesep (), true);
    pkg_folder = [strcat(filesep(),{pkg_folder{1:end-1}}){:}];
  end
else
  pkg_folder = pkg_data{1}.dir;
end

if (! exist (fullfile (dirname, "inst"), "dir"))
%% Installing
  for ii=1:length (dirlist)
    addpath ( [ pkg_folder filesep() dirlist{ii}],"-end")
  endfor

else
%% Testing
  warning("mechanics:Devel","Adding path for testing.");
  for ii=1:length(dirlist)
    addpath ([ dirname "/inst/" dirlist{ii}])
  endfor
endif

warning('off', 'Octave:fopen-file-in-path');
clear dirlist dirname pp arch pkg_folder
clear global_packages ii installed_pkgs_lst local_packages pkg_data

%{
dirname = fileparts (canonicalize_file_name (mfilename ("fullpath")));

%% If we are in Architecture dependent folder add from outside
arch = cstrcat (octave_config_info ("canonical_host_type"),
                              "-", octave_config_info ("api_version"));
pp = strsplit (dirname,filesep (), true);
if strcmp(arch , pp{end})
  dirname = [strcat(filesep(),{pp{1:end-1}}){:}];
end

if (! exist (fullfile (dirname, "inst"), "dir"))
  for ii=1:length (dirlist)
    addpath ( [ dirname filesep dirlist{ii}],"-end")
  endfor
else
  warning("mechanics:Devel","Adding path for testing.");
  for ii=1:length(dirlist)
    addpath ([ dirname "/inst/" dirlist{ii}])
  endfor
endif

warning('off', 'Octave:fopen-file-in-path');
clear dirlist dirname pp
%}