Skip to content
Snippets Groups Projects
Commit a942aefd authored by Yoann Guilhem's avatar Yoann Guilhem Committed by Nicola Vigano
Browse files

Bugfix:

- get rid of hard-coded matlabDCT pathes
- add a check on DCT_DIR and cwd in python scripts

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@784 4c865b51-4357-4376-afb4-474e03ccb993
parent 423858cb
No related branches found
No related tags found
No related merge requests found
...@@ -11,10 +11,15 @@ function [lattice, crystal, table] = gtReadSpaceGroup(sg) ...@@ -11,10 +11,15 @@ function [lattice, crystal, table] = gtReadSpaceGroup(sg)
% crystal = crystal system for this spacegroup % crystal = crystal system for this spacegroup
% table = mhashtable with 'spacegroup' : hermann_mauguin symbol % table = mhashtable with 'spacegroup' : hermann_mauguin symbol
% %
% Version 004 20-09-2012 by YGuilhem
% Now using GT_MATLAB_HOME to determine path to spacegroups.dat
%
% Version 003 14-05-2012 by LNervo % Version 003 14-05-2012 by LNervo
% Add lattice system calculation % Add lattice system calculation
fid=fopen( fullfile( getenv('USER'), 'matlabDCT', 'zUtil_Cryst','spacegroups.dat' ),'r'); global GT_MATLAB_HOME
fid=fopen( fullfile(GT_MATLAB_HOME, 'zUtil_Cryst', 'spacegroups.dat' ),'r');
C=textscan(fid,'%s %d','delimiter','\t','commentstyle','matlab'); C=textscan(fid,'%s %d','delimiter','\t','commentstyle','matlab');
fclose(fid); fclose(fid);
...@@ -78,4 +83,4 @@ end ...@@ -78,4 +83,4 @@ end
end % end of function end % end of function
\ No newline at end of file
...@@ -10,7 +10,9 @@ function gtCopyDataForTest(old_pattern,new_pattern,workdir,newdir) ...@@ -10,7 +10,9 @@ function gtCopyDataForTest(old_pattern,new_pattern,workdir,newdir)
% new_pattern = new dataset name % new_pattern = new dataset name
% newdir = new path % newdir = new path
% workdir = original path to the dataset directory % workdir = original path to the dataset directory
%
% Version 002 20-09-2012 by YGuilhem
% Now using GT_MATLAB_HOME to determine path to tomo_utils.py
if ~exist(fullfile(workdir, old_pattern),'dir') if ~exist(fullfile(workdir, old_pattern),'dir')
disp('Directory doesn''t exist') disp('Directory doesn''t exist')
...@@ -48,24 +50,28 @@ copyfile([ fullfile(workdir, old_pattern, '0_rawdata', 'Orig') '/*'], ... ...@@ -48,24 +50,28 @@ copyfile([ fullfile(workdir, old_pattern, '0_rawdata', 'Orig') '/*'], ...
olddir=pwd; olddir=pwd;
% Set path to tomo_utils.py script
global GT_MATLAB_HOME
tomoUtilsScript = fullfile( GT_MATLAB_HOME, 'zUtil_Python', 'tomo_utils.py');
disp('Renaming the images...') disp('Renaming the images...')
cd(fullfile( newdir, new_pattern, '0_rawdata', 'Orig')); cd(fullfile( newdir, new_pattern, '0_rawdata', 'Orig'));
filenames=[old_pattern '*.edf']; filenames=[old_pattern '*.edf'];
if exist([old_pattern '0_0000.edf'],'file') if exist([old_pattern '0_0000.edf'],'file')
image_old=[old_pattern '0_']; image_old=[old_pattern '0_'];
image_new=[new_pattern '0_']; image_new=[new_pattern '0_'];
cmd=['python26 ' fullfile( getenv('HOME'), 'matlabDCT', 'zUtil_Python', 'tomo_utils.py') ... cmd=['python26 ' tomoUtilsScript ...
' -rename ''' filenames ''' ''' image_old ''' ''' image_new '''']; ' -rename ''' filenames ''' ''' image_old ''' ''' image_new ''''];
[s,msg]=unix(cmd); [s,msg]=unix(cmd);
disp(msg) disp(msg)
image_old=[old_pattern '1_']; image_old=[old_pattern '1_'];
image_new=[new_pattern '1_']; image_new=[new_pattern '1_'];
cmd=['python26 ' fullfile( getenv('HOME'), 'matlabDCT', 'zUtil_Python', 'tomo_utils.py') ... cmd=['python26 ' tomoUtilsScript ...
' -rename ''' filenames ''' ''' image_old ''' ''' image_new '''']; ' -rename ''' filenames ''' ''' image_old ''' ''' image_new ''''];
[s,msg]=unix(cmd); [s,msg]=unix(cmd);
disp(msg) disp(msg)
else else
cmd=['python26 ' fullfile( getenv('HOME'), 'matlabDCT', 'zUtil_Python', 'tomo_utils.py') ... cmd=['python26 ' tomoUtilsScript ...
' -rename ''' filenames ''' ''' old_pattern ''' ''' new_pattern '''']; ' -rename ''' filenames ''' ''' old_pattern ''' ''' new_pattern ''''];
[s,msg]=unix(cmd); [s,msg]=unix(cmd);
disp(msg) disp(msg)
......
...@@ -7,7 +7,7 @@ import sys ...@@ -7,7 +7,7 @@ import sys
import subprocess import subprocess
import string import string
from xml_dct_io import DCTConf from xml_dct_io import DCTConf, DCTCheck
class FunctionsBuilder(object): class FunctionsBuilder(object):
...@@ -79,7 +79,7 @@ class FunctionsBuilder(object): ...@@ -79,7 +79,7 @@ class FunctionsBuilder(object):
print("Generating m-file that will compile those Functions..") print("Generating m-file that will compile those Functions..")
script_content = [ "function compile(varargin)\n", script_content = [ "function compile(varargin)\n",
"current_path = pwd;\n", "current_path = pwd;\n",
"compile_path = [ getenv('HOME') '/matlabDCT/' ];\n", "compile_path = getenv('DCT_DIR');\n",
"cd(compile_path)\n\n", "cd(compile_path)\n\n",
"error_log = java.util.ArrayList();\n\n", "error_log = java.util.ArrayList();\n\n",
"mfiles = java.util.TreeMap();\n" ] "mfiles = java.util.TreeMap();\n" ]
...@@ -184,6 +184,7 @@ if __name__=="__main__": ...@@ -184,6 +184,7 @@ if __name__=="__main__":
will_compile = True will_compile = True
will_generate = True will_generate = True
force_compile = False force_compile = False
DCTCheck().checkCwdWithDCTDir()
matlab_executable = DCTConf().getMatlabCommand() matlab_executable = DCTConf().getMatlabCommand()
mfiles_to_consider = [ ] mfiles_to_consider = [ ]
for index in range(len(sys.argv)): for index in range(len(sys.argv)):
......
...@@ -7,7 +7,7 @@ import subprocess ...@@ -7,7 +7,7 @@ import subprocess
import string import string
import re import re
from xml_dct_io import DCTConf from xml_dct_io import DCTConf, DCTCheck
class MexBuilder(object): class MexBuilder(object):
...@@ -153,7 +153,8 @@ if __name__=="__main__": ...@@ -153,7 +153,8 @@ if __name__=="__main__":
raise ValueError("Not enough arguments to '-c' option") raise ValueError("Not enough arguments to '-c' option")
else: else:
skip_next = False skip_next = False
DCTCheck().checkCwdWithDCTDir()
MexPath = DCTConf().getMexPath() MexPath = DCTConf().getMexPath()
builder = MexBuilder(MexPath) builder = MexBuilder(MexPath)
builder.findMexs() builder.findMexs()
......
...@@ -8,14 +8,16 @@ import os ...@@ -8,14 +8,16 @@ import os
import datetime import datetime
import shutil import shutil
from xml_dct_io import DCTCheck, DCTConf
class ConfUpdater(object): class ConfUpdater(object):
def __init__(self, base_dir = os.getcwd()): def __init__(self, base_dir = os.getcwd()):
self.base_dir = base_dir; self.base_dir = base_dir
def _getNewFilename(self, filepath): def _getNewFilename(self, filepath):
timestamp = datetime.datetime.fromtimestamp(os.path.getmtime(filepath)) timestamp = datetime.datetime.fromtimestamp(os.path.getmtime(filepath))
pieces = os.path.splitext(filepath); pieces = os.path.splitext(filepath)
return (pieces[0] + "-" + timestamp.strftime("%Y-%m-%d-%H-%M") + pieces[1]) return (pieces[0] + "-" + timestamp.strftime("%Y-%m-%d-%H-%M") + pieces[1])
def backup(self, filename): def backup(self, filename):
...@@ -38,9 +40,17 @@ class ConfUpdater(object): ...@@ -38,9 +40,17 @@ class ConfUpdater(object):
print("Creating new file: '%s'" % newfilename) print("Creating new file: '%s'" % newfilename)
self.copy(oldfilename, newfilename) self.copy(oldfilename, newfilename)
def updateXMLConfFile(self):
print "Update conf.xml file with current DCT configuration..."
conf = DCTConf()
conf.setRootDir(os.getenv('DCT_DIR'))
conf.save()
if __name__ == '__main__': if __name__ == '__main__':
upd = ConfUpdater() upd = ConfUpdater()
confexamplefile = os.path.join("zUtil_Conf", "conf.example.xml") DCTCheck().checkCwdWithDCTDir()
upd.safelyInstallNewFile(confexamplefile, "conf.xml") #confexamplefile = os.path.join("zUtil_Conf", "conf.example.xml")
setupexamplefile = os.path.join("zUtil_Conf", "setup_gt_env.example") #upd.safelyInstallNewFile(confexamplefile, "conf.xml")
upd.safelyInstallNewFile(setupexamplefile, "setup_gt_env") upd.updateXMLConfFile()
#setupexamplefile = os.path.join("zUtil_Conf", "setup_gt_env.example")
#upd.safelyInstallNewFile(setupexamplefile, "setup_gt_env")
...@@ -4,6 +4,8 @@ Created on Dec 27, 2011 ...@@ -4,6 +4,8 @@ Created on Dec 27, 2011
@author: vigano @author: vigano
''' '''
import os
try: try:
import lxml.etree as ET import lxml.etree as ET
except ImportError as ex: except ImportError as ex:
...@@ -25,6 +27,21 @@ class DCTXMLBase(object): ...@@ -25,6 +27,21 @@ class DCTXMLBase(object):
self.xmlFile = newName self.xmlFile = newName
self.tree.write(self.xmlFile) self.tree.write(self.xmlFile)
class DCTCheck(object):
def checkCwdWithDCTDir(self, dctdir = os.getenv('DCT_DIR')):
print "Checking if current directory matches with DCT_DIR environment variable...",
indir = os.getcwd()
try:
os.chdir(dctdir)
testdir = os.getcwd()
except:
raise EnvironmentError("DCT_DIR environment variable (%s) points to inexistent directory!" % dctdir)
os.chdir(indir)
if indir == testdir:
print "OK"
else:
raise EnvironmentError("Current working directory does not match with DCT_DIR environment variable!\n%s != %s" % (indir, dctdir))
class DCTConf(DCTXMLBase): class DCTConf(DCTXMLBase):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment