comparison m-toolbox/classes/+utils/@helper/installExtensionsForDir.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % INSTALLEXTENSIONSFORDIR installs the toolbox extensions found under the
2 % given directory.
3 %
4 % CALL: utils.helper.installExtensionsForDir(dir)
5 %
6 % M Hewitson 29-10-10
7 %
8 % $Id: installExtensionsForDir.m,v 1.8 2011/03/25 15:14:42 mauro Exp $
9 %
10 function res = installExtensionsForDir(varargin)
11
12 extdir = varargin{1};
13
14 if ~ischar(extdir)
15 error('input a path to a directory of LTPDA extensions');
16 end
17
18 fprintf('* installing extensions under %s ...\n', extdir);
19
20 % toolbox path
21 aopath = fileparts(which('ao'));
22 parts = regexp(aopath, '@', 'split');
23 classpath = parts{1};
24
25 % for each user class, look for a corresponding directory and copy any
26 % extension methods in.
27 % copy <module>/classes/<user_class>/<methods> to the toolbox
28 userclasses = utils.helper.ltpda_userclasses;
29 installedClassMethods = false;
30 for ucl = userclasses
31 extsdir = fullfile(extdir, 'classes', ucl{1});
32 if exist(extsdir, 'dir')==7
33 fprintf(' * installing extensions for class %s ...\n', ucl{1});
34 files = utils.prog.filescan(extsdir, '.m');
35 dstdir = fullfile(classpath, ['@' ucl{1}]);
36 for kk = 1:numel(files)
37 f = files{kk};
38 [path,name,ext] = fileparts(f);
39 fprintf(' installing %s -> %s\n', name, ucl{1});
40 [success, message, messageid] = copyfile(f, dstdir);
41 if ~success
42 fprintf(stderr, 'Failed to copy file %s to %s : %s', f, dstdir, message);
43 else
44 installedClassMethods = true;
45 end
46 end
47 end
48 end
49
50 % Add subdirs to the MATLAB path
51 addpath(extdir);
52 % In order to include user-defined classes, we just need to add the <module>/classes folder
53 addpath(fullfile(extdir, 'classes'));
54 % In order to include user-defined models, we need to add the <module>/models folder and subfolders
55 addpath(genpath(fullfile(extdir, 'models')));
56 % In order to include user-defined functions, we need to add the <module>/functions folder and subfolders
57 addpath(genpath(fullfile(extdir, 'functions')));
58 % In order to include user-defined tests, we need to add the <module>/tests folder and subfolders
59 addpath(genpath(fullfile(extdir, 'tests')));
60
61 % It might be useful to remove the 'CVS' and '.svn' folders, if any
62 utils.helper.remove_cvs_from_matlabpath();
63 utils.helper.remove_svn_from_matlabpath();
64
65 res = installedClassMethods;
66
67 if installedClassMethods
68 fprintf('----------------------------------------------------------------\n');
69 fprintf(' Additional class methods were installed. These will be \n');
70 fprintf(' available next time you run ''clear all'' or ''clear classes''.\n');
71 fprintf('----------------------------------------------------------------\n');
72 end
73
74
75 end
76
77