-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcluster.m
60 lines (58 loc) · 2.09 KB
/
cluster.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
classdef cluster
properties(Constant)
scratch=getenv('SCRATCH');
end
methods(Static)
function out=istextonly
out=usejava('jvm') && ~feature('ShowFigureWindows');
end
function out=stage(filelst,rootdir,sinkdir,more_args)
if ischar(filelst)
filelst={filelst};
end
if ~exist('rootdir','var') || isempty(rootdir)
rootdir=file.fullpath('.');
end
if ~exist('sinkdir','var') || isempty(sinkdir)
sinkdir=cluter.scratch;
end
if ~exist('more_args','var')
more_args='';
end
%assert assumed types
assert(iscellstr(filelst),['input ''filelst'' must be of class ''cellstr'', not of class ''',class(filelst),'''.'])
assert( ischar(rootdir),['input ''rootdir'' must be of class ''char'', not of class ''', class(rootdir),'''.'])
assert( ischar(sinkdir),['input ''sinkdir'' must be of class ''char'', not of class ''', class(sinkdir),'''.'])
%make sure trailing slashes are there
filelst=file.trailing_filesep(file.fullpath(filelst));
rootdir=file.trailing_filesep(file.fullpath(rootdir ));
sinkdir=file.trailing_filesep(file.fullpath(sinkdir ));
%sanity
assert(all(cellfun(@(i) ~strcmp(strrep(i,rootdir,''),i),filelst)),'Some file(s)/dir(s) are not in specified root dir.')
%outputs
out=cell(numel(filelst));
%loop over all specified files
for i=1:numel(filelst)
if exist(filelst{i},'file')
source=filelst{i};
sink=strrep(filelst{i},rootdir,sinkdir);
[out{i},s]=file.rsync(source,sink,more_args);
assert(s==0,['failed to rsync file/dir ',source,' to ',sink])
else
warning(['Could not stage file/dir ',filelst{i},' because it does not exist.'])
end
end
%flatten output
out=cells.flatten(out);
end
function out=unstage(filelist,rootdir,sinkdir,more_args)
error('unfinished')
if ~exist('sinkdir','var') || isempty(sinkdir)
sinkdir=cluter.scratch;
end
if ~exist('more_args','var')
more_args='';
end
end
end
end