MatrixBerryCore
TmpDataManager.m
Go to the documentation of this file.
1 classdef TmpDataManager<mxberry.core.obj.StaticPropStorage
2 
3  methods (Static)
4  function setRootDir(dirName)
5  mxberry.io.TmpDataManager.setPropInternal('rootDir',dirName);
6  end
7  function resDir=getDirByCallerKey(keyName,nStepsUp)
8  import mxberry.core.check.checkgen;
9  if nargin<2
10  nStepsUp=2;
11  if nargin<1
12  keyName='';
13  else
14  checkgen(keyName,'isstring(x)');
15  end
16  else
17  checkgen(nStepsUp,'isnumeric(x)&&isscalar(x)');
18  end
19  callerName=mxberry.core.getcallername(nStepsUp,'full');
20  resDir=mxberry.io.TmpDataManager.getDirByKey(...
21  [callerName,'.',keyName]);
22  end
23  function resDir=getDirByKey(keyName)
24  import mxberry.core.throwerror;
25  mxberry.core.check.checkgen(keyName,'isstring(x)');
26  [rootDir,isThere]=...
27  mxberry.io.TmpDataManager.getPropInternal('rootDir',true);
28  if ~isThere
29  rootDir=mxberry.io.TmpDataManager.setDefaultRootDir();
30  end
31  curTaskName=mxberry.system.getpidhost();
32  keyDirName=mxberry.core.hash({curTaskName,keyName});
33  resDir=[rootDir,filesep,keyDirName];
34  %
35  if mxberry.io.isdir(resDir)
36  try
37  mxberry.io.rmdir(resDir,'s');
38  catch meObj
39  newMeObj=mxberry.core.throwerror('failedToRemoveDir',...
40  'could not remove directory %s',resDir);
41  newMeObj=addCause(newMeObj,meObj);
42  throw(newMeObj);
43  end
44  end
45  try
46  mxberry.io.mkdir(resDir);
47  catch meObj
48  newMeObj=mxberry.core.throwerror('failedToCreatedDir',...
49  'could not create directory %s',resDir);
50  newMeObj=addCause(newMeObj,meObj);
51  throw(newMeObj);
52  end
53  end
54  end
55  %
56  methods (Access=protected,Static)
57  function [propVal,isThere]=getPropInternal(propName,isPresenceChecked)
58  branchName=mfilename('class');
59  [propVal,isThere]=mxberry.core.obj.StaticPropStorage.getPropInternal(...
60  branchName,propName,isPresenceChecked);
61  end
62  %
63  function setPropInternal(propName,propVal)
64  branchName=mfilename('class');
66  branchName,propName,propVal);
67  end
68  function tmpDirName=setDefaultRootDir()
69  tmpDirName=tempdir;
70  if strcmpi(tmpDirName(end),filesep)
71  tmpDirName(end)=[];
72  end
73  mxberry.io.TmpDataManager.setRootDir(tmpDirName);
74  end
75  end
76 end
function filesep()
static function setPropInternal(in branchName, in propName, in propVal)
function getpidhost()
GETPIDHOST returns process id (PID) of current Matlab instance along with a host name it is running o...
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
TMPDATAMANAGER implements a basic functionality for managing temporary data folders.
Definition: TmpDataManager.m:5
function hash(in inpArr, in methodName)
OBJECTHASH counts the hash of input object/array.
function checkgen(in x, in typeSpec, in varargin)
CHECKGEN checks a generic condition provided by typeSpec string in the following format: &#39;isnumeric(x...
function isstring(in inpArray)
static function getPropInternal(in branchName, in propName, in isPresenceChecked)
function getcallername(in nStepsUp, in mode)
GETCALLERNAME returns a name of caller determined by a number of steps up in the call stacks...