Improving error handling if tex2pix cannot be found or the MASS block is missing in the spectrum file, and adding the pyslha.ParseError class. pyslha-1.3.2

Sat, 03 Mar 2012 20:32:13 +0100

author
Andy Buckley <andy@insectnation.org>
date
Sat, 03 Mar 2012 20:32:13 +0100
changeset 166
97ed233d12f8
parent 165
e0e065418fbb
child 167
e9ced0cd7b60

Improving error handling if tex2pix cannot be found or the MASS block is missing in the spectrum file, and adding the pyslha.ParseError class.

ChangeLog file | annotate | diff | comparison | revisions
pyslha.py file | annotate | diff | comparison | revisions
slhaplot file | annotate | diff | comparison | revisions
     1.1 --- a/ChangeLog	Sat Mar 03 01:15:12 2012 +0100
     1.2 +++ b/ChangeLog	Sat Mar 03 20:32:13 2012 +0100
     1.3 @@ -1,5 +1,11 @@
     1.4  2012-03-03  Andy Buckley  <andy.buckley@cern.ch>
     1.5  
     1.6 +	* Version 1.3.2
     1.7 +
     1.8 +	* Improving error handling if tex2pix cannot be found or the MASS
     1.9 +	block is missing in the spectrum file, and adding the
    1.10 +	pyslha.ParseError class.
    1.11 +
    1.12  	* Version 1.3.1
    1.13  
    1.14  	* Fix LaTeX package checks for tikz an mathpazo by adding .sty to
     2.1 --- a/pyslha.py	Sat Mar 03 01:15:12 2012 +0100
     2.2 +++ b/pyslha.py	Sat Mar 03 20:32:13 2012 +0100
     2.3 @@ -24,7 +24,7 @@
     2.4  """
     2.5  
     2.6  __author__ = "Andy Buckley <andy.buckley@cern.ch"
     2.7 -__version__ = "1.3.1"
     2.8 +__version__ = "1.3.2"
     2.9  
    2.10  
    2.11  def _autotype(var):
    2.12 @@ -46,6 +46,14 @@
    2.13      return str(var)
    2.14  
    2.15  
    2.16 +class ParseError(Exception):
    2.17 +    "Exception object to be raised when a spectrum file/string is malformed"
    2.18 +    def __init__(self, errmsg):
    2.19 +        self.msg = errmsg
    2.20 +    def __repr__(self):
    2.21 +        return self.msg
    2.22 +
    2.23 +
    2.24  
    2.25  class Block(object):
    2.26      """
    2.27 @@ -233,7 +241,7 @@
    2.28              if decays.has_key(pid):
    2.29                  decays[pid].mass = blocks["MASS"].entries[pid]
    2.30      except:
    2.31 -        raise Exception("No MASS block found, from which to populate particle masses")
    2.32 +        raise ParseError("No MASS block found: cannot populate particle masses")
    2.33  
    2.34      return blocks, decays
    2.35  
     3.1 --- a/slhaplot	Sat Mar 03 01:15:12 2012 +0100
     3.2 +++ b/slhaplot	Sat Mar 03 20:32:13 2012 +0100
     3.3 @@ -219,11 +219,15 @@
     3.4      sys.exit(1)
     3.5  
     3.6  
     3.7 -## Test for external packages
     3.8 -import tex2pix
     3.9 +## Test for external packages (including tex2pix)
    3.10  if opts.FORMAT.needs_compilation():
    3.11 +    try:
    3.12 +        import tex2pix
    3.13 +    except:
    3.14 +        logging.error("Python package tex2pix could not be found: graphical output cannot work... exiting")
    3.15 +        sys.exit(1)
    3.16      if not tex2pix.check_latex_pkg("tikz.sty"):
    3.17 -        logging.error("LaTeX tikz.sty could not be found: graphical format modes cannot work")
    3.18 +        logging.error("LaTeX tikz.sty could not be found: graphical output cannot work... exiting")
    3.19          sys.exit(1)
    3.20  
    3.21  
    3.22 @@ -251,14 +255,17 @@
    3.23  
    3.24      ## Read spectrum file
    3.25      BLOCKS, DECAYS = None, None
    3.26 -    # print BLOCKS
    3.27 -    if infile == "-":
    3.28 -        intext = sys.stdin.read()
    3.29 -        BLOCKS, DECAYS = pyslha.readSLHA(intext)
    3.30 -    elif infile.endswith(".isa"):
    3.31 -        BLOCKS, DECAYS = pyslha.readISAWIGFile(infile)
    3.32 -    else:
    3.33 -        BLOCKS, DECAYS = pyslha.readSLHAFile(infile)
    3.34 +    try:
    3.35 +        if infile == "-":
    3.36 +            intext = sys.stdin.read()
    3.37 +            BLOCKS, DECAYS = pyslha.readSLHA(intext)
    3.38 +        elif infile.endswith(".isa"):
    3.39 +            BLOCKS, DECAYS = pyslha.readISAWIGFile(infile)
    3.40 +        else:
    3.41 +            BLOCKS, DECAYS = pyslha.readSLHAFile(infile)
    3.42 +    except pyslha.ParseError, pe:
    3.43 +        logging.error(pe)
    3.44 +        sys.exit(1)
    3.45      # print BLOCKS
    3.46  
    3.47  
    3.48 @@ -464,7 +471,7 @@
    3.49                  out += c + "\\input{%s}\n" % opts.PREAMBLE.replace(".tex", "")
    3.50          else:
    3.51              out += c + "%% Default preamble\n"
    3.52 -            if tex2pix.check_latex_pkg("mathpazo.sty"):
    3.53 +            if tex2pix in dir() and tex2pix.check_latex_pkg("mathpazo.sty"):
    3.54                  out += c + "\\usepackage[osf]{mathpazo}\n"
    3.55          #
    3.56          out += c + "\n"

mercurial