Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pykat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
finesse
pykat
Commits
c4c8b185
Commit
c4c8b185
authored
10 years ago
by
Daniel Brown
Browse files
Options
Downloads
Patches
Plain Diff
Adding parsing exception handling
parent
dfb15166
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pykat/exceptions.py
+19
-3
19 additions, 3 deletions
pykat/exceptions.py
pykat/finesse.py
+112
-118
112 additions, 118 deletions
pykat/finesse.py
with
131 additions
and
121 deletions
pykat/exceptions.py
+
19
−
3
View file @
c4c8b185
...
@@ -6,14 +6,30 @@ from __future__ import unicode_literals
...
@@ -6,14 +6,30 @@ from __future__ import unicode_literals
import
pykat.external.six
as
six
import
pykat.external.six
as
six
if
six
.
PY2
:
if
six
.
PY2
:
import
exceptions
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
):
class
BasePyKatException
(
Exception
):
def
__init__
(
self
,
msg
):
def
__init__
(
self
,
msg
):
self
.
__
msg
=
msg
self
.
msg
=
msg
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__
msg
return
self
.
msg
class
FinesseParse
(
BasePyKatException
)
:
class
FinesseParse
(
BasePyKatException
)
:
def
__init__
(
self
,
msg
):
def
__init__
(
self
,
msg
):
...
...
This diff is collapsed.
Click to expand it.
pykat/finesse.py
+
112
−
118
View file @
c4c8b185
...
@@ -603,6 +603,7 @@ class kat(object):
...
@@ -603,6 +603,7 @@ class kat(object):
return
commands_new
return
commands_new
def
parseCommands
(
self
,
commands
,
blocks
=
None
):
def
parseCommands
(
self
,
commands
,
blocks
=
None
):
try
:
blockComment
=
False
blockComment
=
False
commands
=
self
.
remove_comments
(
commands
)
commands
=
self
.
remove_comments
(
commands
)
...
@@ -613,7 +614,6 @@ class kat(object):
...
@@ -613,7 +614,6 @@ class kat(object):
# objects have been set and created
# objects have been set and created
for
line
in
commands
:
for
line
in
commands
:
try
:
if
len
(
line
.
strip
())
>=
2
:
if
len
(
line
.
strip
())
>=
2
:
line
=
line
.
strip
()
line
=
line
.
strip
()
...
@@ -767,11 +767,6 @@ class kat(object):
...
@@ -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
))
print
(
"
Removed existing object
'
{0}
'
of type {1} to add line
'
{2}
'"
.
format
(
obj
.
name
,
obj
.
__class__
,
line
))
self
.
add
(
obj
)
self
.
add
(
obj
)
except
:
print
(
"
--------------------------------------------------------
"
)
print
(
"
Error parsing line:
"
+
line
)
print
(
"
--------------------------------------------------------
"
)
raise
# now process all the varous gauss/attr etc. commands which require
# now process all the varous gauss/attr etc. commands which require
...
@@ -884,6 +879,11 @@ class kat(object):
...
@@ -884,6 +879,11 @@ class kat(object):
self
.
__currentTag
=
NO_BLOCK
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
):
def
saveScript
(
self
,
filename
=
None
):
"""
"""
Saves the current kat object to a Finesse input file
Saves the current kat object to a Finesse input file
...
@@ -1031,23 +1031,17 @@ class kat(object):
...
@@ -1031,23 +1031,17 @@ class kat(object):
if
six
.
PY2
:
if
six
.
PY2
:
sys
.
stdout
.
write
(
line
)
sys
.
stdout
.
write
(
line
)
else
:
else
:
sys
.
stdout
.
write
(
str
(
line
,
'
utf-8
'
))
sys
.
stdout
.
write
(
line
)
# todo fix this if needed
elif
line
.
rstrip
().
endswith
(
b
'
%
'
):
elif
line
.
rstrip
().
endswith
(
b
'
%
'
):
vals
=
line
.
split
(
"
-
"
)
vals
=
line
.
split
(
"
-
"
)
action
=
vals
[
0
].
strip
()
action
=
vals
[
0
].
strip
()
prc
=
vals
[
1
].
strip
()[:]
prc
=
vals
[
1
].
strip
()[:]
if
printerr
==
1
:
if
printerr
==
1
:
if
six
.
PY2
:
sys
.
stdout
.
write
(
"
\r
{0} {1}
"
.
format
(
action
,
str
(
prc
)))
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
'
)))
else
:
else
:
if
six
.
PY2
:
err
+=
str
(
line
)
err
=
""
.
join
((
err
,
line
))
else
:
err
=
""
.
join
((
err
,
str
(
line
,
'
utf-8
'
)))
[
out
,
errpipe
]
=
p
.
communicate
()
[
out
,
errpipe
]
=
p
.
communicate
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment