Skip to content
Snippets Groups Projects
Commit c4c8b185 authored by Daniel Brown's avatar Daniel Brown
Browse files

Adding parsing exception handling

parent dfb15166
No related branches found
No related tags found
No related merge requests found
......@@ -6,14 +6,30 @@ from __future__ import unicode_literals
import pykat.external.six as six
if six.PY2:
import exceptions
import os
import os, sys
def PrintError(message, exception):
size = 60
print("\033[91m")
try:
from textwrap import wrap, fill
print ("-" * size)
for a in wrap(message, size): print(a)
for a in wrap(str(exception.msg), size): print(a)
print ("-" * size)
finally:
print ("\033[0m")
sys.exit(1)
class BasePyKatException(Exception):
def __init__(self, msg):
self.__msg = msg
self.msg = msg
def __str__(self):
return self.__msg
return self.msg
class FinesseParse(BasePyKatException) :
def __init__(self, msg):
......
......@@ -603,6 +603,7 @@ class kat(object):
return commands_new
def parseCommands(self, commands, blocks=None):
try:
blockComment = False
commands=self.remove_comments(commands)
......@@ -613,7 +614,6 @@ class kat(object):
# objects have been set and created
for line in commands:
try:
if len(line.strip()) >= 2:
line = line.strip()
......@@ -767,11 +767,6 @@ class kat(object):
print ("Removed existing object '{0}' of type {1} to add line '{2}'".format(obj.name, obj.__class__, line))
self.add(obj)
except:
print ("--------------------------------------------------------")
print ("Error parsing line: " + line)
print ("--------------------------------------------------------")
raise
# now process all the varous gauss/attr etc. commands which require
......@@ -884,6 +879,11 @@ class kat(object):
self.__currentTag = NO_BLOCK
except pkex.BasePyKatException as ex:
pkex.PrintError("Error parsing line: '%s':"% line, ex)
sys.exit(1)
def saveScript(self, filename=None):
"""
Saves the current kat object to a Finesse input file
......@@ -1031,23 +1031,17 @@ class kat(object):
if six.PY2:
sys.stdout.write(line)
else:
sys.stdout.write(str(line,'utf-8'))
sys.stdout.write(line) # todo fix this if needed
elif line.rstrip().endswith(b'%'):
vals = line.split("-")
action = vals[0].strip()
prc = vals[1].strip()[:]
if printerr == 1:
if six.PY2:
sys.stdout.write("\r{0} {1}".format(action, prc))
else:
sys.stdout.write("\r{0} {1}".format(str(action, 'utf-8'), str(prc, 'utf-8')))
sys.stdout.write("\r{0} {1}".format(action, str(prc)))
else:
if six.PY2:
err="".join((err,line))
else:
err="".join((err,str(line, 'utf-8')))
err += str(line)
[out,errpipe] = p.communicate()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment