From b183ae486980197f388468f52ffed6af6ed69472 Mon Sep 17 00:00:00 2001 From: Nicola Vigano <nicola.vigano@esrf.fr> Date: Tue, 23 Apr 2013 15:55:08 +0200 Subject: [PATCH] Python: added verbosity levels, added fresh mexopts option and fixed some bugs Signed-off-by: Nicola Vigano <nicola.vigano@esrf.fr> --- dct_launch.py | 12 +- zUtil_Python/dct_compile_matlab_functions.py | 59 +++--- zUtil_Python/dct_compile_mex_functions.py | 194 +++++++++++-------- zUtil_Python/dct_io_xml.py | 36 ++-- zUtil_Python/dct_setup.py | 71 ++++--- zUtil_Python/dct_utils_platform.py | 24 +-- 6 files changed, 219 insertions(+), 177 deletions(-) diff --git a/dct_launch.py b/dct_launch.py index d169b560..72d56ac4 100755 --- a/dct_launch.py +++ b/dct_launch.py @@ -71,7 +71,9 @@ class DCTLauncher(object): invoker = dct.dct_matlab_invocation.DCTMatlabInvocation(dct_dir = self.dct_dir, \ extra_args = self.args) - func_builder = FunctionsBuilder.getInstanceFromArgs([], dct_dir = self.dct_dir) + func_builder = FunctionsBuilder(matlab_path = "", \ + dct_dir = self.dct_dir, \ + verboseLevel = 0) func_builder.generateMfile() invoker.invoke() @@ -84,9 +86,7 @@ class DCTLauncher(object): from zUtil_Python.dct_compile_mex_functions import MexBuilder try: - args_compile = [""] - for arg in self.args: - args_compile.append(arg) + args_compile = [""] + self.args mex_builder = MexBuilder.getInstanceFromArgs(args_compile, dct_dir = self.dct_dir) mex_builder.findMexs() mex_builder.compileFuncs() @@ -101,9 +101,7 @@ class DCTLauncher(object): from zUtil_Python.dct_compile_matlab_functions import FunctionsBuilder try: - args_compile = [""] - for arg in self.args: - args_compile.append(arg) + args_compile = [""] + self.args func_builder = FunctionsBuilder.getInstanceFromArgs(args_compile, dct_dir = self.dct_dir) if func_builder.do_generate is True: diff --git a/zUtil_Python/dct_compile_matlab_functions.py b/zUtil_Python/dct_compile_matlab_functions.py index b3262659..d7a0b241 100755 --- a/zUtil_Python/dct_compile_matlab_functions.py +++ b/zUtil_Python/dct_compile_matlab_functions.py @@ -24,6 +24,8 @@ class FunctionsBuilder(object): confPath = os.path.join(dct_dir, "conf.xml") confPath = os.path.abspath(confPath) + args = args[1:] + conf = DCTConf(confPath) matlab_path = conf.getMatlabPath() @@ -31,33 +33,38 @@ class FunctionsBuilder(object): will_compile = True will_generate = True force_compile = False + verbose = 1 mfiles_to_consider = [ ] - for index in range(len(sys.argv)): + for index in range(len(args)): if skip_next is False: - if sys.argv[index] == "-just-generate": + if args[index] == "-just-generate": will_compile = False will_generate = True - if sys.argv[index] == "-just-compile": + elif args[index] == "-just-compile": will_compile = True will_generate = False - if sys.argv[index] == "-force-compile": + elif args[index] == "-force-compile": will_compile = True force_compile = True - if sys.argv[index] == "-c": + elif args[index] == "-c": skip_next = True - if len(sys.argv) > (index-1): - mfiles_to_consider.append(sys.argv[index+1]) + if len(args) > (index-1): + mfiles_to_consider.append(args[index+1]) else: raise ValueError("Not enough arguments for '-c' option") - elif sys.argv[index] in ("--help", "-h"): + elif args[index] in ("--help", "-h"): raise ValueError("") - if sys.argv[index] == "-mp": + elif args[index] in ("--verbose", "-v"): + verbose = 2 + elif args[index] == "-mp": skip_next = True - if len(sys.argv) > (index-1): - matlab_path = sys.argv[index+1] + if len(args) > (index-1): + matlab_path = args[index+1] else: raise ValueError("Not enough arguments for '-mp' option") + else: + DCTOutput.printWarning('Unknown argument (at position %d): %s' % (index, args[index])) else: skip_next = False @@ -66,12 +73,13 @@ class FunctionsBuilder(object): force_compile = force_compile, \ mfiles_to_consider = mfiles_to_consider, \ do_compile = will_compile, \ - do_generate = will_generate) + do_generate = will_generate, \ + verboseLevel = verbose) def __init__(self, matlab_path, dct_dir = os.getcwd(), \ script_dir = None, bin_dir = None, force_compile = False, \ mfiles_to_consider = [], do_compile = True, \ - do_generate = True): + do_generate = True, verboseLevel = 1): self.dct_dir = dct_dir if script_dir is None: script_dir = os.path.join(self.dct_dir, 'bin', 'scripts') @@ -92,6 +100,8 @@ class FunctionsBuilder(object): self.m_files = { } self.compile_records = { } + self.out = DCTOutput(verboseLevel = verboseLevel); + def printHelp(self): launchname = os.path.basename(__file__) print("\"%s\" builds your mex files in the DCT dir: \"%s\"" % @@ -113,7 +123,7 @@ class FunctionsBuilder(object): regexp = re.compile(regexpString) searchPatterns.append(regexp) - DCTOutput.printSubJob("Finding functions that may be compiled, from: '%s'" % self.dct_dir) + self.out.printSubJob("Finding functions that may be compiled, from: '%s'" % self.dct_dir) filesList = [] for root, dir_name, file_names in os.walk(self.dct_dir): for file_name in file_names: @@ -148,15 +158,15 @@ class FunctionsBuilder(object): else: self.call_funcs[filepath] = [function_name] - DCTOutput.printSubJob("These functions were found:") + self.out.printSubJob("These functions were found:") for file_name in self.call_funcs: - DCTOutput.printSubSubJob('In file', file_name) + self.out.printSubSubJob('In file', file_name) for func in self.call_funcs[file_name]: - print(' + Function: ' + func) + self.out.printSubSubSubJob("Function", func) print('') def _prepareFuncsList(self): - DCTOutput.printSubJob("Adding information about functions that may not need to be compiled..") + self.out.printSubJob("Adding information about functions that may not need to be compiled..") for caller in self.call_funcs: callerFuncName = os.path.basename(caller)[:-2] for function in self.call_funcs[caller]: @@ -165,16 +175,15 @@ class FunctionsBuilder(object): try: self.compile_records[function] = (outpath, self.m_files[function]) except KeyError: - print(' -> WARNING!! function: "' + function \ - + '" is NOT a local function (may be from ID19) <-') + DCTOutput.printWarning("-> function: '%' is NOT a local function (may be from ID19) <-" % function) self.compile_records[callerFuncName][function] = (' ',' ') def _generateMCompileFile(self): if not os.path.exists(self.script_dir): - DCTOutput.printSubJob("Creating script directory: '%s'" % self.script_dir) + self.out.printSubJob("Creating script directory: '%s'" % self.script_dir) os.makedirs(self.script_dir) - DCTOutput.printSubJob("Generating m-file that will compile those Functions..") + self.out.printSubJob("Generating m-file that will compile those Functions..") script_content = [ "function varargout = compile(force, doCompile, varargin)\n\n", "mfiles = [];\n" ] for func in self.compile_records: @@ -187,16 +196,16 @@ class FunctionsBuilder(object): script_content.append("\nif (doCompile)\n gtCompileFunctions(force, mfiles, varargin)\nend\n\nend % end of function\n") script_loc = os.path.join(self.script_dir, 'compile.m') - DCTOutput.printSubJob("Writing '%s' script to disk.." % script_loc) + self.out.printSubJob("Writing '%s' script to disk.." % script_loc) fid = open(script_loc, "w") fid.writelines(script_content) fid.close() def compileFuncs(self): if not os.path.exists(self.bin_dir): - DCTOutput.printSubJob('Creating binaries directory') + self.out.printSubJob('Creating binaries directory') os.makedirs(self.bin_dir) - DCTOutput.printSubJob("Calling matlab..") + self.out.printSubJob("Calling matlab..") extra_args = ['-nodesktop', '-nosplash'] diff --git a/zUtil_Python/dct_compile_mex_functions.py b/zUtil_Python/dct_compile_mex_functions.py index b097dcbe..bae5d789 100755 --- a/zUtil_Python/dct_compile_mex_functions.py +++ b/zUtil_Python/dct_compile_mex_functions.py @@ -9,6 +9,8 @@ import re from dct_io_xml import DCTConf, DCTOutput +import dct_utils_platform + class MexBuilder(object): file_extensions = [ '*.c', '*.cxx', '*.cpp' ] @@ -22,55 +24,54 @@ class MexBuilder(object): confPath = os.path.join(dct_dir, "conf.xml") confPath = os.path.abspath(confPath) - conf = DCTConf(confPath) - matlab_path = conf.getMatlabPath() + args = args[1:] + matlab_path = "" skip_next = False force_compile = False - verbose = False + fresh_mexopts = False + verbose = 1 mfiles_to_consider = [ ] unclassified_args = [ ] - for index in range(len(sys.argv)): + for index in range(len(args)): if skip_next is False: - if sys.argv[index] == "-force-compile": + if args[index] == "-force-compile": force_compile = True - elif sys.argv[index] in ("--verbose", "-v"): - verbose = True - elif sys.argv[index] == "-c": + elif args[index] == "-fresh-mexopts": + fresh_mexopts = True + elif args[index] in ("--verbose", "-v"): + verbose = 2 + elif args[index] == "-c": skip_next = True if len(sys.argv) > (index+1): - mfiles_to_consider.append(sys.argv[index+1]) + mfiles_to_consider.append(args[index+1]) else: raise ValueError("Not enough arguments to '-c' option") - elif sys.argv[index] == "-mp": + elif args[index] == "-mp": skip_next = True - if len(sys.argv) > (index-1): - matlab_path = sys.argv[index+1] + if len(args) > (index-1): + matlab_path = args[index+1] else: raise ValueError("Not enough arguments for '-mp' option") - elif sys.argv[index] in ("--help", "-h"): + elif args[index] in ("--help", "-h"): raise ValueError("") else: - unclassified_args.append(sys.argv[index]) + unclassified_args.append(args[index]) + print(args[index]) else: skip_next = False - try: - mex_info = conf.getMexFiles() - except: - DCTOutput.printWarning("Couldn't get mex files info. Using plain config.") - mex_info = None - - return MexBuilder(matlab_path, dct_dir = dct_dir, \ - extraArgs = unclassified_args, mex_info = mex_info, \ + return MexBuilder(matlab_path = matlab_path, dct_dir = dct_dir, \ + extraArgs = unclassified_args, \ force_compile = force_compile, verbose = verbose, \ - mfiles_to_consider = mfiles_to_consider) + mfiles_to_consider = mfiles_to_consider, \ + fresh_mexopts = fresh_mexopts) - def __init__(self, matlab_path, dct_dir = None, outdir = None, \ - extraArgs = [], mex_info = None, force_compile = False, \ - verbose = False, mfiles_to_consider = []): + def __init__(self, matlab_path = "", dct_dir = None, outdir = None, \ + extraArgs = [], force_compile = False, verbose = 1, \ + mfiles_to_consider = [], fresh_mexopts = False): """ - force_compile: if true, compiles even if the file is recent - verbose: generates a lot of output @@ -83,14 +84,27 @@ class MexBuilder(object): self.dct_dir = dct_dir self.outdir = outdir - self.matlab_dir = matlab_path - self.c_files = { } - self.mex_info = mex_info self.mfiles_to_consider = mfiles_to_consider self.force_compile = force_compile - self.verbose = verbose + self.fresh_mexopts = fresh_mexopts + + self.out = DCTOutput(verboseLevel = verbose) + + confPath = os.path.join(dct_dir, "conf.xml") + confPath = os.path.abspath(confPath) + self.conf = DCTConf(confPath) + + if matlab_path == "": + matlab_path = self.conf.getMatlabPath() + self.matlab_dir = matlab_path + + try: + self.mex_info = self.conf.getMexFiles() + except: + DCTOutput.printWarning("Couldn't get mex files info. Using plain config.") + self.mex_info = None def printHelp(self): launchname = os.path.basename(__file__) @@ -104,6 +118,7 @@ class MexBuilder(object): print(" -c <filename> : to compile only a specific file (wildcards also apply)") print(" -mp <matlab_dir> : to specify matlab's directory") print(" -force-compile : to force the compilation even if not needed") + print(" -fresh-mexopts : to force the resetting of mexopts file") def findMexs(self): """ @@ -111,20 +126,20 @@ class MexBuilder(object): Finds the mex files (well, the C sources) and saves the files into the object """ - DCTOutput.printSubJob("Finding mex files, from: '%s'" % self.dct_dir) + self.out.printSubJob("Finding mex files, from: '%s'" % self.dct_dir) for root, dir_name, file_names in os.walk(self.dct_dir): for file_extension in self.file_extensions: for file_name in file_names: if fnmatch.fnmatch(file_name, file_extension): filepath = os.path.join(root, file_name) self.c_files[file_name] = filepath - DCTOutput.printSubJob("These files were found:") + self.out.printSubJob("These files were found:") for file_name in self.c_files: - DCTOutput.printSubSubJob('File', file_name + ' ( ' + self.c_files[file_name] + ' )') + self.out.printSubSubJob('File', file_name + ' ( ' + self.c_files[file_name] + ' )') print('') def _buildMakeCmd(self, cmd, includes, lib_paths, libs, defines): - if self.verbose is True: + if self.out.verboseLevel > 1: cmd.append('-v') for include in includes: cmd.append("-I" + include) @@ -134,38 +149,35 @@ class MexBuilder(object): cmd.append("-l" + lib) for define in defines: cmd.append("-D" + define) - DCTOutput.printSubSubJob('File', cmd[1] + ' (cmd: ' + string.join(cmd, ' ') + ' )') - subprocess.call(cmd) + self.out.printSubSubJob('File', cmd[1] + ' (cmd: ' + string.join(cmd, ' ') + ' )') + return subprocess.call(cmd) - def _compileFile(self, file_name): + def _compileFile(self, file_path): """ - [Internal] def _compileFile(file_name): + [Internal] def _compileFile(file_path): - Tries to compile the given file_name. + Tries to compile the given file_path. """ - file_path = self.c_files[file_name] compiler_path = os.path.join(self.matlab_dir, "bin", "mex") cmd = [ compiler_path, file_path, '-outdir', self.outdir ] - std_include = [ os.path.join(self.dct_dir, 'zUtil_Cxx', 'include') ] + includes = [ os.path.join(self.dct_dir, 'zUtil_Cxx', 'include') ] + lib_paths = [] + libs = [] + defines = [] - if self.mex_info is None: - # No info at all into the xml file -# DCTOutput.printWarning("Mex info not loaded.") - self._buildMakeCmd(cmd, std_include, [], [], []) - else: - if self.mex_info.isExcluded(file_path) is False: - props = self.mex_info.getFileProperties(file_path) - if props is not None: - includes = std_include + props.get("includes") - self._buildMakeCmd(cmd, includes, - props.get("lib_paths"), - props.get("libs"), - props.get("defines")) - else: - # info found, but not about this file, so let's use standard params -# DCTOutput.printWarning("No Mex info on file: '%s'" % file_name) - self._buildMakeCmd(cmd, std_include, [], [], []) + if (self.mex_info is not None) \ + and (self.mex_info.isExcluded(file_path) is False): + + props = self.mex_info.getFileProperties(file_path) + if props is not None: + # No info at all into the xml file + includes = includes + props.get("includes") + lib_paths = lib_paths + props.get("lib_paths") + libs = libs + props.get("libs") + defines = defines + props.get("defines") + + return self._buildMakeCmd(cmd, includes, lib_paths, libs, defines) def compileFuncs(self): """ @@ -173,38 +185,54 @@ class MexBuilder(object): Compiles the mex files into the list. """ + + if self.fresh_mexopts is True: + self.out.printSubJob("Resetting mexopts file") + dct_utils = dct_utils_platform.UtilsFactory.getMachineDep() + dct_utils.resetMatlabMexopts(self.conf.getMatlabVersion(), \ + self.conf.getMatlabPath() ) + listOfErrors = []; if not os.path.exists(self.outdir): - DCTOutput.printSubJob("Creating mex directory") + self.out.printSubJob("Creating mex directory") os.makedirs(self.outdir) - DCTOutput.printSubJob("Compiling mex files:") - if ( len(self.mfiles_to_consider) is 0 - or ( len(self.mfiles_to_consider) is 1 and self.mfiles_to_consider[0] == 'all' ) ): + self.out.printSubJob("Compiling mex files:") + + if (len(self.mfiles_to_consider) is 0) \ + or ( (len(self.mfiles_to_consider) is 1) \ + and (self.mfiles_to_consider[0] == 'all') ): # No preferences, so let's compile everything - for file_name in self.c_files: - self._compileFile(file_name) + files_to_compile = self.c_files else: # Specific files - for file_name in self.mfiles_to_consider: - try: - self._compileFile(file_name) - except KeyError as exc: - # Not found in the list, se let's check if it is a regular expression - try: - found = False - for cfile in self.c_files: - if re.search(file_name, cfile): - self._compileFile(cfile) - found = True - if found is not True: - DCTOutput.printError("Nothing found!") - raise exc - except: - errorMsg = 'ERROR. File not found: ' + file_name - DCTOutput.printError(errorMsg) - print(exc) - listOfErrors.append(errorMsg); + files_to_compile = self.mfiles_to_consider + + # Now let's compile + for file_name in files_to_compile: + + # Check if it is an actual file or a regular expression + if file_name in self.c_files: + match_list = [ file_name ] + else: + match_list = [] + for cfile in self.c_files: + if re.search(file_name, cfile): + match_list.append(cfile) + if len(match_list) is 0: + errorMsg = "No file corresponds to: %s" % file_name + DCTOutput.printError(errorMsg) + listOfErrors.append(errorMsg); + + # Let's compile each match + for cfile in match_list: + file_path = self.c_files[file_name] + if (self.mex_info is None) \ + or ( (self.mex_info is not None) \ + and (self.mex_info.isExcluded(file_path) is False) ): + ret_val = self._compileFile(file_path) + if ret_val is not 0: + listOfErrors.append("Error compiling MEX: %s (Return Value: %d)" % (file_name, ret_val)) print('') if len(listOfErrors) is not 0: print("Errors happened during compilation:") diff --git a/zUtil_Python/dct_io_xml.py b/zUtil_Python/dct_io_xml.py index b8552ade..6dd12395 100755 --- a/zUtil_Python/dct_io_xml.py +++ b/zUtil_Python/dct_io_xml.py @@ -5,6 +5,7 @@ Created on Dec 27, 2011 ''' import os +import re import datetime import shutil @@ -22,6 +23,11 @@ except ImportError as ex: class DCTOutput(object): + def __init__(self, verboseLevel = 1): + if verboseLevel is True: + verboseLevel = 1; + self.verboseLevel = verboseLevel; + @staticmethod def printError(args): print("\n\033[31;1mError: %s\033[39;0m\n" % "".join(args)) @@ -30,21 +36,25 @@ class DCTOutput(object): def printWarning(args): print("\n\033[33;1mWarning: %s\033[39;0m\n" % "".join(args)) - @staticmethod - def printInfoRecord(title, args): - print(" %s: \033[36;1m%s\033[39;0m" % (title, "".join(args))) + def printInfoRecord(self, title, args): + if self.verboseLevel >= 1: + print(" %s: \033[36;1m%s\033[39;0m" % (title, "".join(args))) - @staticmethod - def printJob(args): - print("\033[39;1m%s\033[39;0m" % "".join(args)) + def printJob(self, args): + if self.verboseLevel >= 1: + print("\033[39;1m%s\033[39;0m" % "".join(args)) - @staticmethod - def printSubJob(args): - print(" * \033[32;1m%s\033[39;0m" % "".join(args)) + def printSubJob(self, args): + if self.verboseLevel >= 1: + print(" * \033[32;1m%s\033[39;0m" % "".join(args)) - @staticmethod - def printSubSubJob(title, args): - print(" - \033[32m%s\033[39;0m: %s" % (title, "".join(args))) + def printSubSubJob(self, title, args): + if self.verboseLevel >= 1: + print(" - \033[32m%s\033[39;0m: %s" % (title, "".join(args))) + + def printSubSubSubJob(self, title, args): + if self.verboseLevel >= 1: + print(" + %s: %s" % (title, "".join(args))) class DCTXMLBase(object): @@ -146,7 +156,7 @@ class MexConf(object): def isExcluded(self, testFile): for exclude in self.tree.findall("exclude_list/path"): - if exclude.text in testFile: + if re.search(exclude.text, testFile): return True else: return False diff --git a/zUtil_Python/dct_setup.py b/zUtil_Python/dct_setup.py index 8ccc72bc..e38a23d4 100755 --- a/zUtil_Python/dct_setup.py +++ b/zUtil_Python/dct_setup.py @@ -16,7 +16,7 @@ from dct_compile_matlab_functions import FunctionsBuilder class DCTSetup(object): def __init__(self, args): - self.verbose = False + self.verbose = 1 self.initialized = False self.branch = "" self.repo_dir = "" @@ -35,7 +35,7 @@ class DCTSetup(object): for index in range(len(args)): if skip_next is False: if args[index] == "--verbose" or args[index] == "-v": - self.verbose = True + self.verbose = 2 elif args[index] == "-b": skip_next = True if len(args) > (index+1): @@ -85,6 +85,7 @@ class DCTSetup(object): self.repo_dir = "_".join(["dct", stable_ver]) self.initialized = True + self.out = DCTOutput(self.verbose) for arg in unclassified_args: DCTOutput.printWarning("Unused argument: %s" % arg) @@ -97,7 +98,7 @@ class DCTSetup(object): try: branches = dct_utils_git.DCTGit.getAvailableRemoteBranches() except ValueError as ex: - DCTOutput.printWarning(ex.args) + self.out.printWarning(ex.args) branches = [] print("Installs DCT for both users and developers" ) print(" Options:") @@ -115,22 +116,22 @@ class DCTSetup(object): print("\nGit repository information:") if self.sf_username is not "": - DCTOutput.printInfoRecord("Mode", "Developer") - DCTOutput.printInfoRecord("Sourceforge Username", self.sf_username) - DCTOutput.printInfoRecord("User Real Name", self.user_real_name) - DCTOutput.printInfoRecord("User e-mail", self.user_email) + self.out.printInfoRecord("Mode", "Developer") + self.out.printInfoRecord("Sourceforge Username", self.sf_username) + self.out.printInfoRecord("User Real Name", self.user_real_name) + self.out.printInfoRecord("User e-mail", self.user_email) else: - DCTOutput.printInfoRecord("Mode", "User") + self.out.printInfoRecord("Mode", "User") - DCTOutput.printInfoRecord("Branch", self.branch) - DCTOutput.printInfoRecord("DCT Dir", self.repo_dir) + self.out.printInfoRecord("Branch", self.branch) + self.out.printInfoRecord("DCT Dir", self.repo_dir) def printSystemSummary(self): print("\nSystem information:") - DCTOutput.printInfoRecord("System Description", self.system_type) - DCTOutput.printInfoRecord("Matlab Version", self.matlab_ver) - DCTOutput.printInfoRecord("Gcc Version", self.gcc_version) - DCTOutput.printInfoRecord("Git Version", self.git_version) + self.out.printInfoRecord("System Description", self.system_type) + self.out.printInfoRecord("Matlab Version", self.matlab_ver) + self.out.printInfoRecord("Gcc Version", self.gcc_version) + self.out.printInfoRecord("Git Version", self.git_version) def checkSystem(self, platform_utils): self.git_version = platform_utils.checkGitVersion() @@ -146,14 +147,14 @@ class DCTSetup(object): self.user_real_name = dct_utils_git.DCTGit.getGlobalConfig("user.name") except ValueError as ex: DCTOutput.printWarning(ex.args) - DCTOutput.printSubJob("Trying to guess the Real Name of the user") + self.out.printSubJob("Trying to guess the Real Name of the user") self.user_real_name = utils.guessUserRealName() dct_utils_git.DCTGit.setGlobalConfig("user.name", self.user_real_name) try: self.user_email = dct_utils_git.DCTGit.getGlobalConfig("user.email") except ValueError as ex: DCTOutput.printWarning(ex.args) - DCTOutput.printSubJob("Trying to guess the e-mail of the user") + self.out.printSubJob("Trying to guess the e-mail of the user") self.user_email = utils.guessUserEmail() dct_utils_git.DCTGit.setGlobalConfig("user.email", self.user_email) @@ -165,7 +166,7 @@ if __name__ == '__main__': utils = dct_utils_platform.UtilsFactory.getMachineDep() dct_sup.system_type = utils.getSystemDescription() - DCTOutput.printJob("Checking system...") + dct_sup.out.printJob("Checking system...") try: dct_sup.checkSystem(utils) dct_sup.prepareUserEnvironment("proxy.esrf.fr:3128") # assuming ESRF @@ -174,16 +175,16 @@ if __name__ == '__main__': except ValueError as ex: DCTOutput.printError(ex.args) sys.exit(1) - DCTOutput.printJob("Done.") + dct_sup.out.printJob("Done.") dct_sup.printSystemSummary() dct_sup.printRepoSummary() print("") - DCTOutput.printJob("Installing...") + dct_sup.out.printJob("Installing...") utils_git = dct_utils_git.DCTGit() - DCTOutput.printSubJob("Cloning repository...") + dct_sup.out.printSubJob("Cloning repository...") if dct_sup.sf_username is not "": retcode = utils_git.createDeveloperRepo(username = dct_sup.sf_username, \ dest_dir = dct_sup.repo_dir, \ @@ -193,12 +194,12 @@ if __name__ == '__main__': retcode = utils_git.createUserRepo(dest_dir = dct_sup.repo_dir, \ branch = dct_sup.branch) if retcode is not 0: - DCTOutput.printSubJob("Directory exists. Checking it is a git repository, and updating...") + dct_sup.out.printSubJob("Directory exists. Checking it is a git repository, and updating...") utils_git.updateRepo() - DCTOutput.printJob("Done.") + dct_sup.out.printJob("Done.") print("") - DCTOutput.printJob("Initializing configuration files..") + dct_sup.out.printJob("Initializing configuration files..") upd = DCTConfUpdater(utils_git.repo_dir) confexamplefile = utils_git.getFilePathInRepo("zUtil_Conf", "conf.example.xml") @@ -215,36 +216,30 @@ if __name__ == '__main__': if dct_sup.matlab_dir is "": dct_sup.matlab_dir = dct_conf.getMatlabPath() - utils.checkMatlabGccVersion(matlabVersion = dct_sup.matlab_ver, \ - matlabPath = dct_sup.matlab_dir) - DCTOutput.printJob("Done.") + utils.resetMatlabMexopts(matlabVersion = dct_sup.matlab_ver, \ + matlabPath = dct_sup.matlab_dir) + dct_sup.out.printJob("Done.") print("") - DCTOutput.printJob("Compiling MEX files..") - try: - mex_info = dct_conf.getMexFiles() - except: - DCTOutput.printWarning("Couldn't get mex files info. Using plain config.") - mex_info = None - + dct_sup.out.printJob("Compiling MEX files..") mex_builder = MexBuilder(matlab_path = dct_sup.matlab_dir, \ - dct_dir = utils_git.repo_dir, mex_info = mex_info, \ + dct_dir = utils_git.repo_dir, \ mfiles_to_consider = [], force_compile = True, \ verbose = dct_sup.verbose) mex_builder.findMexs() mex_builder.compileFuncs() - DCTOutput.printJob("Done.") + dct_sup.out.printJob("Done.") print("") - DCTOutput.printJob("Compiling batch functions... (may take several minutes)") + dct_sup.out.printJob("Compiling batch functions... (may take several minutes)") func_builder = FunctionsBuilder(dct_dir = utils_git.repo_dir, \ matlab_path = dct_sup.matlab_dir, \ mfiles_to_consider = [], \ force_compile = True) func_builder.generateMfile() func_builder.compileFuncs() - DCTOutput.printJob("Done.") + dct_sup.out.printJob("Done.") print("") - DCTOutput.printJob("DCT is now Installed in: '%s'" % utils_git.repo_dir) + dct_sup.out.printJob("DCT is now Installed in: '%s'" % utils_git.repo_dir) diff --git a/zUtil_Python/dct_utils_platform.py b/zUtil_Python/dct_utils_platform.py index f1732123..97eff341 100755 --- a/zUtil_Python/dct_utils_platform.py +++ b/zUtil_Python/dct_utils_platform.py @@ -114,17 +114,19 @@ class UtilsInterface(object): return version_txt - def checkMatlabGccVersion(self, searchPatterns, matlabVersion, \ + def resetMatlabMexopts(self, searchPatterns, matlabVersion, \ matlabPath = ""): import stat mexoptsfile = self._getMatlabMexoptsPath(matlabVersion) - if os.path.exists(mexoptsfile) is not True: - if matlabPath is "": - # Try ESRF Paths - matlabPath = self._getMatlabPath(matlabVersion) - self._createMatlabMexopts(matlabPath) + if os.path.exists(mexoptsfile) is True: + os.remove(mexoptsfile) + + if matlabPath is "": + # Try ESRF Paths + matlabPath = self._getMatlabPath(matlabVersion) + self._createMatlabMexopts(matlabPath) stats = os.stat(mexoptsfile) os.chmod(mexoptsfile, stats.st_mode | stat.S_IWRITE) @@ -194,7 +196,7 @@ class UtilsLinux(UtilsInterface): def _getMatlabPath(self, matlabVersion): return os.path.join("/sware", "com", "matlab_%s" % matlabVersion) - def checkMatlabGccVersion(self, matlabVersion, matlabPath = ""): + def resetMatlabMexopts(self, matlabVersion, matlabPath = ""): searchPatterns = [("COPTIMFLAGS='-O -DNDEBUG'", "COPTIMFLAGS='-O -DNDEBUG -fopenmp'"), \ ("CXXOPTIMFLAGS='-O -DNDEBUG'", "CXXOPTIMFLAGS='-O -DNDEBUG -fopenmp'"), \ ('(CLIBS="\$RPATH \$MLIBS -lm)"', '\g<1> -fopenmp"'), \ @@ -204,10 +206,10 @@ class UtilsLinux(UtilsInterface): searchPatterns.append(("CC='gcc'", "CC='gcc44'")) searchPatterns.append(("CXX='g\+\+'", "CXX='g++44'")) - UtilsInterface.checkMatlabGccVersion(self, \ - searchPatterns = searchPatterns, \ - matlabVersion = matlabVersion, \ - matlabPath = matlabPath) + UtilsInterface.resetMatlabMexopts(self, \ + searchPatterns = searchPatterns, \ + matlabVersion = matlabVersion, \ + matlabPath = matlabPath) def guessUserRealName(self): username = os.getenv("USER") -- GitLab