Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
finesse
pykat
Commits
24cf033e
Commit
24cf033e
authored
Jan 05, 2017
by
Daniel Brown
Browse files
addding readBlock method
parent
80a0f7f3
Pipeline
#1756
passed with stage
in 19 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
pykat/finesse.py
View file @
24cf033e
...
...
@@ -195,11 +195,51 @@ def f__lkat_trace_callback(lkat, trace_info, getCavities, getNodes, getSpaces):
trace_info
[
space
.
name
]
=
space_trace
(
gouyx
=
space
.
gouy_x
,
gouyy
=
space
.
gouy_y
)
class
KatBatch
(
object
):
"""
def
readBlocks
(
katfile
):
"""
For a given kat file, the blocks are parsed into dictionary as raw strings.
"""
__blocks
=
{}
__currentBlock
=
NO_BLOCK
__blocks
[
__currentBlock
]
=
""
with
open
(
katfile
)
as
f
:
commands
=
f
.
readlines
()
for
line
in
commands
:
line
=
line
.
strip
()
# Looking for block start or end
values
=
line
.
split
()
if
len
(
values
)
>=
3
and
values
[
0
]
==
"%%%"
:
if
values
[
1
]
==
"FTblock"
:
newTag
=
values
[
2
]
if
__currentBlock
!=
None
and
__currentBlock
!=
NO_BLOCK
:
warnings
.
warn
(
"found block {0} before block {1} ended"
.
format
(
newTag
,
__currentBlock
))
if
newTag
in
__blocks
:
raise
pkex
.
BasePyKatException
(
"Block `{0}` has already been read"
.
format
(
newTag
))
__blocks
[
newTag
]
=
""
__currentBlock
=
newTag
if
(
len
(
line
)
>
0
and
(
__currentBlock
is
NO_BLOCK
)):
continue
__blocks
[
__currentBlock
]
+=
line
+
"
\n
"
if
len
(
values
)
>=
3
and
values
[
0
]
==
"%%%"
:
if
values
[
1
]
==
"FTend"
:
__currentBlock
=
NO_BLOCK
return
__blocks
class
KatBatch
(
object
):
def
__init__
(
self
):
from
IPython.parallel
import
Client
...
...
@@ -1048,7 +1088,7 @@ class kat(object):
for
key
in
self
.
__variables
:
print
(
"$"
+
key
,
"::::"
,
"owner ="
,
self
.
__variables
[
key
].
owner
.
name
,
", use count ="
,
self
.
__variables
[
key
].
putCount
)
def
parseCommands
(
self
,
commands
,
blocks
=
None
,
addToBlock
=
None
):
def
parseCommands
(
self
,
commands
,
blocks
=
None
,
addToBlock
=
None
,
preserve
=
False
):
try
:
if
addToBlock
is
not
None
and
blocks
is
not
None
:
raise
pkex
.
BasePyKatException
(
"When parsing commands you cannot set both blocks and addToBlock arguments"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment