Skip to content
Snippets Groups Projects
Commit ebab400f authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Python/mex compile: added -h option and colored error reporting


Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@839 4c865b51-4357-4376-afb4-474e03ccb993
parent 4195207c
No related branches found
No related tags found
No related merge requests found
...@@ -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, DCTCheck from xml_dct_io import DCTConf, DCTCheck, DCTOutput
class MexBuilder(object): class MexBuilder(object):
...@@ -15,7 +15,8 @@ class MexBuilder(object): ...@@ -15,7 +15,8 @@ class MexBuilder(object):
def __init__(self, compiler_path, def __init__(self, compiler_path,
indir = os.getcwd(), indir = os.getcwd(),
outdir = os.path.join(os.getcwd(), 'bin', 'mex')): outdir = os.path.join(os.getcwd(), 'bin', 'mex'),
extraArgs = []):
self.indir = indir self.indir = indir
self.outdir = outdir self.outdir = outdir
self.compiler_path = compiler_path self.compiler_path = compiler_path
...@@ -26,6 +27,17 @@ class MexBuilder(object): ...@@ -26,6 +27,17 @@ class MexBuilder(object):
except: except:
print("Error: Couldn't get mex files info. Using plain config.") print("Error: Couldn't get mex files info. Using plain config.")
def printHelp(self):
print("\"%s\" builds your mex files in the DCT dir: \"%s\"" %
(__file__, self.indir) )
print("Usage: call it from within the directory of DCT. Be aware that" +
" the DCT environment variable should be adjusted accordingly")
print(" Options:")
print(" -h | --help : to show this help")
print(" -force-compile : to force the compilation even if not needed")
print(" -v | --verbose : to show more detailed output")
print(" -c <filename> : to compile only a specific file (wildcards also apply)")
def findMexs(self): def findMexs(self):
""" """
def findMexs(): def findMexs():
...@@ -135,27 +147,43 @@ class MexBuilder(object): ...@@ -135,27 +147,43 @@ class MexBuilder(object):
print('- %s' % errorMsg) print('- %s' % errorMsg)
if __name__=="__main__": if __name__=="__main__":
try:
DCTCheck().checkCwdWithDCTDir()
MexPath = DCTConf().getMexPath()
except BaseException as ex:
DCTOutput().printError(ex.args)
exit(1);
skip_next = False skip_next = False
force_compile = False force_compile = False
verbose = False verbose = False
mfiles_to_consider = [ ] mfiles_to_consider = [ ]
for index in range(len(sys.argv)): unclassified_args = [ ]
if skip_next is False: try:
if sys.argv[index] == "-force-compile": for index in range(len(sys.argv)):
force_compile = True if skip_next is False:
if sys.argv[index] == "-verbose" or sys.argv[index] == "-v": if sys.argv[index] == "-force-compile":
verbose = True force_compile = True
if sys.argv[index] == "-c": elif sys.argv[index] == "--verbose" or sys.argv[index] == "-v":
skip_next = True verbose = True
if len(sys.argv) > (index-1): elif sys.argv[index] == "-c":
mfiles_to_consider.append(sys.argv[index+1]) skip_next = True
if len(sys.argv) > (index+1):
mfiles_to_consider.append(sys.argv[index+1])
else:
raise ValueError("Not enough arguments to '-c' option")
elif sys.argv[index] == "--help" or sys.argv[index] == "-h":
raise ValueError("")
else: else:
raise ValueError("Not enough arguments to '-c' option") unclassified_args.append(sys.argv[index])
else: else:
skip_next = False skip_next = False
DCTCheck().checkCwdWithDCTDir() builder = MexBuilder(MexPath, extraArgs = unclassified_args)
MexPath = DCTConf().getMexPath() builder.findMexs()
builder = MexBuilder(MexPath) builder.compileFuncs(mfiles_to_consider, force_compile, verbose)
builder.findMexs() except ValueError as ex:
builder.compileFuncs(mfiles_to_consider, force_compile, verbose) if (len(ex.args) is not 0) and (ex.args[0] is not ""):
DCTOutput().printError(ex.args)
MexBuilder(MexPath).printHelp();
...@@ -16,6 +16,11 @@ except ImportError as ex: ...@@ -16,6 +16,11 @@ except ImportError as ex:
print(ex1) print(ex1)
raise ex1 raise ex1
class DCTOutput(object):
def printError(self, args):
print("\n\033[31;1mError: %s\033[39;0m\n" % "".join(args))
class DCTXMLBase(object): class DCTXMLBase(object):
def __init__(self, xmlFile): def __init__(self, xmlFile):
......
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