metaforce/hecl/blender/hecl_blendershell.py

595 lines
20 KiB
Python
Raw Permalink Normal View History

2016-12-25 07:02:34 +00:00
import bpy, sys, os, re, struct, traceback
2015-07-28 23:54:54 +00:00
ARGS_PATTERN = re.compile(r'''(?:"([^"]+)"|'([^']+)'|(\S+))''')
2019-05-10 04:07:48 +00:00
# Background mode seems to require quit() in some 2.80 builds
def _quitblender():
bpy.ops.wm.quit_blender()
quit()
MIN_BLENDER_MAJOR = 2
MIN_BLENDER_MINOR = 83
# Extract pipe file descriptors from arguments
2015-08-06 19:10:12 +00:00
print('HECL Blender Launch', sys.argv)
2015-05-24 04:51:16 +00:00
if '--' not in sys.argv:
2019-05-10 04:07:48 +00:00
_quitblender()
args = sys.argv[sys.argv.index('--')+1:]
readfd = int(args[0])
writefd = int(args[1])
2015-10-22 02:01:08 +00:00
verbosity_level = int(args[2])
2016-08-02 22:12:49 +00:00
err_path = ""
2015-08-31 03:36:24 +00:00
if sys.platform == "win32":
import msvcrt
readfd = msvcrt.open_osfhandle(readfd, os.O_RDONLY | os.O_BINARY)
writefd = msvcrt.open_osfhandle(writefd, os.O_WRONLY | os.O_BINARY)
2016-08-02 22:12:49 +00:00
err_path = "/Temp"
2016-12-25 07:02:34 +00:00
if 'TEMP' in os.environ:
err_path = os.environ['TEMP']
2016-08-02 22:12:49 +00:00
else:
err_path = "/tmp"
2016-12-25 07:02:34 +00:00
if 'TMPDIR' in os.environ:
err_path = os.environ['TMPDIR']
2016-08-02 22:12:49 +00:00
err_path += "/hecl_%016X.derp" % os.getpid()
def readpipestr():
read_bytes = os.read(readfd, 4)
if len(read_bytes) != 4:
print('HECL connection lost or desynchronized')
2019-05-10 04:07:48 +00:00
_quitblender()
read_len = struct.unpack('I', read_bytes)[0]
return os.read(readfd, read_len)
def writepipestr(linebytes):
2015-10-04 05:08:24 +00:00
#print('LINE', linebytes)
os.write(writefd, struct.pack('I', len(linebytes)))
os.write(writefd, linebytes)
2015-05-24 22:19:28 +00:00
def writepipebuf(linebytes):
2015-10-04 04:35:18 +00:00
#print('BUF', linebytes)
os.write(writefd, linebytes)
def quitblender():
writepipestr(b'QUITTING')
2019-05-10 04:07:48 +00:00
_quitblender()
2017-01-17 07:12:49 +00:00
class PathHasher:
def hashpath32(self, path):
2017-01-21 02:38:03 +00:00
writepipestr(path.encode())
2017-01-17 07:12:49 +00:00
read_str = readpipestr()
2019-10-01 07:23:35 +00:00
return int(read_str[0:8], 16)
2017-01-17 07:12:49 +00:00
# Ensure Blender 2.83+ is being used
if bpy.app.version < (MIN_BLENDER_MAJOR, MIN_BLENDER_MINOR, 0):
writepipestr(b'INVALIDBLENDERVER')
2019-05-10 04:07:48 +00:00
_quitblender()
2015-08-31 03:36:24 +00:00
# If there's a third argument, use it as the .zip path containing the addon
2015-09-17 19:50:01 +00:00
did_install = False
2015-09-22 01:41:38 +00:00
if len(args) >= 4 and args[3] != 'SKIPINSTALL':
2019-05-08 03:47:34 +00:00
bpy.ops.preferences.addon_install(overwrite=True, target='DEFAULT', filepath=args[3])
bpy.ops.preferences.addon_refresh()
2015-09-17 19:50:01 +00:00
did_install = True
2015-05-24 04:51:16 +00:00
2015-05-24 22:19:28 +00:00
# Make addon available to commands
2019-05-08 03:47:34 +00:00
if bpy.context.preferences.addons.find('hecl') == -1:
2015-08-31 03:36:24 +00:00
try:
2019-05-08 03:47:34 +00:00
bpy.ops.preferences.addon_enable(module='hecl')
2015-08-31 03:36:24 +00:00
bpy.ops.wm.save_userpref()
except:
pass
try:
import hecl
except:
writepipestr(b'NOADDON')
2019-05-10 04:07:48 +00:00
_quitblender()
2015-05-24 22:19:28 +00:00
2015-09-17 19:50:01 +00:00
# Quit if just installed
if did_install:
writepipestr(b'ADDONINSTALLED')
2019-05-10 04:07:48 +00:00
_quitblender()
2015-09-17 19:50:01 +00:00
# Intro handshake
writepipestr(b'READY')
ackbytes = readpipestr()
if ackbytes != b'ACK':
quitblender()
2015-08-05 22:59:59 +00:00
# Count brackets
def count_brackets(linestr):
bracket_count = 0
for ch in linestr:
if ch in {'[','{','('}:
bracket_count += 1
elif ch in {']','}',')'}:
bracket_count -= 1
return bracket_count
2015-10-02 04:06:45 +00:00
# Read line of space-separated/quoted arguments
def read_cmdargs():
cmdline = readpipestr()
2015-10-02 04:06:45 +00:00
if cmdline == b'':
print('HECL connection lost')
2019-05-10 04:07:48 +00:00
_quitblender()
2015-10-02 04:06:45 +00:00
cmdargs = []
for match in ARGS_PATTERN.finditer(cmdline.decode()):
cmdargs.append(match.group(match.lastindex))
return cmdargs
2015-08-05 22:59:59 +00:00
# Complete sequences of statements compiled/executed here
def exec_compbuf(compbuf, globals):
2015-10-22 02:01:08 +00:00
if verbosity_level >= 3:
2019-08-31 20:38:06 +00:00
print(compbuf)
2017-01-14 04:15:43 +00:00
try:
co = compile(compbuf, '<HECL>', 'exec')
exec(co, globals)
except Exception as e:
trace_prefix = 'Error processing:\n'
trace_prefix += compbuf
raise RuntimeError(trace_prefix) from e
2015-08-05 22:59:59 +00:00
2015-10-02 04:06:45 +00:00
# Command loop for writing animation key data to blender
def animin_loop(globals):
writepipestr(b'ANIMREADY')
while True:
crv_type = struct.unpack('b', os.read(readfd, 1))
if crv_type[0] < 0:
writepipestr(b'ANIMDONE')
return
elif crv_type[0] == 0:
crvs = globals['rotCurves']
elif crv_type[0] == 1:
crvs = globals['transCurves']
elif crv_type[0] == 2:
crvs = globals['scaleCurves']
key_info = struct.unpack('ii', os.read(readfd, 8))
crv = crvs[key_info[0]]
crv.keyframe_points.add(count=key_info[1])
if crv_type[0] == 1:
for k in range(key_info[1]):
key_data = struct.unpack('if', os.read(readfd, 8))
pt = crv.keyframe_points[k]
pt.interpolation = 'LINEAR'
2016-04-08 23:11:05 +00:00
pt.co = (key_data[0], key_data[1])
else:
for k in range(key_info[1]):
key_data = struct.unpack('if', os.read(readfd, 8))
pt = crv.keyframe_points[k]
pt.interpolation = 'LINEAR'
pt.co = (key_data[0], key_data[1])
2018-04-04 08:28:13 +00:00
def writelight(obj):
wmtx = obj.matrix_world
writepipebuf(struct.pack('ffffffffffffffff',
wmtx[0][0], wmtx[0][1], wmtx[0][2], wmtx[0][3],
wmtx[1][0], wmtx[1][1], wmtx[1][2], wmtx[1][3],
wmtx[2][0], wmtx[2][1], wmtx[2][2], wmtx[2][3],
wmtx[3][0], wmtx[3][1], wmtx[3][2], wmtx[3][3]))
writepipebuf(struct.pack('fff', obj.data.color[0], obj.data.color[1], obj.data.color[2]))
type = 2
spotCutoff = 0.0
hasFalloff = False
castShadow = False
if obj.data.type == 'POINT':
type = 2
hasFalloff = True
2019-05-08 03:47:34 +00:00
castShadow = obj.data.use_shadow
2018-04-04 08:28:13 +00:00
elif obj.data.type == 'SPOT':
type = 3
hasFalloff = True
spotCutoff = obj.data.spot_size
2019-05-08 03:47:34 +00:00
castShadow = obj.data.use_shadow
2018-04-04 08:28:13 +00:00
elif obj.data.type == 'SUN':
type = 1
2019-05-08 03:47:34 +00:00
castShadow = obj.data.use_shadow
2018-04-04 08:28:13 +00:00
constant = 1.0
linear = 0.0
quadratic = 0.0
if hasFalloff:
if obj.data.falloff_type == 'INVERSE_COEFFICIENTS':
constant = obj.data.constant_coefficient
linear = obj.data.linear_coefficient
quadratic = obj.data.quadratic_coefficient
layer = 0
if 'retro_layer' in obj.data.keys():
layer = obj.data['retro_layer']
writepipebuf(struct.pack('IIfffffb', layer, type, obj.data.energy, spotCutoff, constant, linear, quadratic,
castShadow))
writepipestr(obj.name.encode())
2015-10-02 04:06:45 +00:00
# Command loop for reading data from blender
def dataout_loop():
writepipestr(b'READY')
2015-10-02 04:06:45 +00:00
while True:
cmdargs = read_cmdargs()
print(cmdargs)
if cmdargs[0] == 'DATAEND':
writepipestr(b'DONE')
2015-10-04 04:35:18 +00:00
return
2015-10-02 04:06:45 +00:00
elif cmdargs[0] == 'MESHLIST':
2016-08-12 19:41:51 +00:00
meshCount = 0
2015-10-02 04:06:45 +00:00
for meshobj in bpy.data.objects:
2019-10-01 07:23:35 +00:00
if meshobj.type == 'MESH' and not meshobj.data.library:
2016-08-12 19:41:51 +00:00
meshCount += 1
writepipebuf(struct.pack('I', meshCount))
for meshobj in bpy.data.objects:
2019-10-01 07:23:35 +00:00
if meshobj.type == 'MESH' and not meshobj.data.library:
writepipestr(meshobj.name.encode())
2015-10-02 04:06:45 +00:00
2017-02-24 08:27:07 +00:00
elif cmdargs[0] == 'LIGHTLIST':
lightCount = 0
for obj in bpy.context.scene.objects:
2019-10-01 07:23:35 +00:00
if obj.type == 'LIGHT' and not obj.data.library:
2017-02-24 08:27:07 +00:00
lightCount += 1
writepipebuf(struct.pack('I', lightCount))
for obj in bpy.context.scene.objects:
2019-10-01 07:23:35 +00:00
if obj.type == 'LIGHT' and not obj.data.library:
2017-02-24 08:27:07 +00:00
writepipestr(obj.name.encode())
elif cmdargs[0] == 'MESHAABB':
writepipestr(b'OK')
hecl.mesh_aabb(writepipebuf)
2015-10-02 04:06:45 +00:00
elif cmdargs[0] == 'MESHCOMPILE':
2015-10-04 04:35:18 +00:00
meshName = bpy.context.scene.hecl_mesh_obj
if meshName not in bpy.data.objects:
writepipestr(('mesh %s not found' % meshName).encode())
2015-10-04 04:35:18 +00:00
continue
writepipestr(b'OK')
2019-05-08 03:47:34 +00:00
hecl.hmdl.cook(writepipebuf, bpy.data.objects[meshName])
2015-10-04 04:35:18 +00:00
2019-10-01 07:23:35 +00:00
elif cmdargs[0] == 'ARMATURECOMPILE':
armName = bpy.context.scene.hecl_arm_obj
if armName not in bpy.data.objects:
writepipestr(('armature %s not found' % armName).encode())
continue
writepipestr(b'OK')
hecl.armature.cook(writepipebuf, bpy.data.objects[armName].data)
2015-10-04 04:35:18 +00:00
elif cmdargs[0] == 'MESHCOMPILENAME':
2015-10-02 04:06:45 +00:00
meshName = cmdargs[1]
2019-05-08 03:47:34 +00:00
useLuv = int(cmdargs[2])
2015-10-02 04:06:45 +00:00
if meshName not in bpy.data.objects:
writepipestr(('mesh %s not found' % meshName).encode())
2015-10-02 04:06:45 +00:00
continue
writepipestr(b'OK')
2019-05-08 03:47:34 +00:00
hecl.hmdl.cook(writepipebuf, bpy.data.objects[meshName], useLuv)
2015-10-03 01:53:45 +00:00
elif cmdargs[0] == 'MESHCOMPILENAMECOLLISION':
meshName = cmdargs[1]
if meshName not in bpy.data.objects:
writepipestr(('mesh %s not found' % meshName).encode())
continue
writepipestr(b'OK')
hecl.hmdl.cookcol(writepipebuf, bpy.data.objects[meshName])
2017-10-17 05:51:13 +00:00
elif cmdargs[0] == 'MESHCOMPILECOLLISIONALL':
writepipestr(b'OK')
colCount = 0
for obj in bpy.context.scene.objects:
2019-10-01 07:23:35 +00:00
if obj.type == 'MESH' and not obj.data.library:
2017-10-17 05:51:13 +00:00
colCount += 1
writepipebuf(struct.pack('I', colCount))
for obj in bpy.context.scene.objects:
2019-10-01 07:23:35 +00:00
if obj.type == 'MESH' and not obj.data.library:
2017-10-17 05:51:13 +00:00
hecl.hmdl.cookcol(writepipebuf, obj)
2018-02-24 06:15:12 +00:00
elif cmdargs[0] == 'MESHCOMPILEPATH':
meshName = bpy.context.scene.hecl_path_obj
if meshName not in bpy.data.objects:
writepipestr(('mesh %s not found' % meshName).encode())
continue
writepipestr(b'OK')
hecl.path.cook(writepipebuf, bpy.data.objects[meshName])
2016-10-01 23:18:52 +00:00
elif cmdargs[0] == 'WORLDCOMPILE':
writepipestr(b'OK')
2016-10-01 23:18:52 +00:00
hecl.swld.cook(writepipebuf)
elif cmdargs[0] == 'FRAMECOMPILE':
2018-03-28 08:06:34 +00:00
version = int(cmdargs[1])
2017-01-21 02:38:03 +00:00
if version != 0 and version != 1:
writepipestr(b'bad version')
continue
writepipestr(b'OK')
2018-03-28 08:06:34 +00:00
buffer = hecl.frme.cook(writepipebuf, version, PathHasher())
2017-01-17 07:12:49 +00:00
writepipestr(b'FRAMEDONE')
2018-03-28 08:06:34 +00:00
writepipebuf(struct.pack('I', len(buffer)))
writepipebuf(buffer)
2016-08-11 19:51:41 +00:00
elif cmdargs[0] == 'LIGHTCOMPILEALL':
writepipestr(b'OK')
2018-04-04 08:28:13 +00:00
lampCount = 0
firstSpot = None
2016-08-12 19:41:51 +00:00
for obj in bpy.context.scene.objects:
2019-05-08 03:47:34 +00:00
if obj.type == 'LIGHT':
2016-08-11 19:51:41 +00:00
lampCount += 1
2018-04-04 08:28:13 +00:00
if firstSpot is None and obj.data.type == 'SPOT':
firstSpot = obj
2016-08-11 19:51:41 +00:00
2018-04-04 08:28:13 +00:00
# Ambient
2016-08-11 19:51:41 +00:00
world = bpy.context.scene.world
ambient_energy = 0.0
ambient_color = None
if world.use_nodes and 'Background' in world.node_tree.nodes:
bg_node = world.node_tree.nodes['Background']
ambient_energy = bg_node.inputs[1].default_value
ambient_color = bg_node.inputs[0].default_value
if ambient_energy:
lampCount += 1
writepipebuf(struct.pack('I', lampCount))
2018-04-04 08:28:13 +00:00
if firstSpot is not None:
writelight(firstSpot)
2016-08-11 19:51:41 +00:00
if ambient_energy:
writepipebuf(struct.pack('ffffffffffffffff',
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
2016-08-11 20:16:01 +00:00
0.0, 0.0, 0.0, 1.0))
2016-08-11 19:51:41 +00:00
writepipebuf(struct.pack('fff', ambient_color[0], ambient_color[1], ambient_color[2]))
2016-08-11 20:16:01 +00:00
writepipebuf(struct.pack('IIfffffb', 0, 0, ambient_energy, 0.0, 1.0, 0.0, 0.0, False))
2017-02-24 08:27:07 +00:00
writepipestr(b'AMBIENT')
2016-08-11 19:51:41 +00:00
2018-04-04 08:28:13 +00:00
# Lamp objects
2016-08-12 19:41:51 +00:00
for obj in bpy.context.scene.objects:
2019-05-08 03:47:34 +00:00
if obj != firstSpot and obj.type == 'LIGHT':
2018-04-04 08:28:13 +00:00
writelight(obj)
2017-02-24 08:27:07 +00:00
2016-10-02 22:34:10 +00:00
elif cmdargs[0] == 'GETTEXTURES':
writepipestr(b'OK')
2016-10-02 22:34:10 +00:00
img_count = 0
for img in bpy.data.images:
if img.type == 'IMAGE':
img_count += 1
writepipebuf(struct.pack('I', img_count))
for img in bpy.data.images:
if img.type == 'IMAGE':
path = os.path.normpath(bpy.path.abspath(img.filepath))
writepipebuf(struct.pack('I', len(path)))
writepipebuf(path.encode())
2015-10-23 00:44:37 +00:00
elif cmdargs[0] == 'ACTORCOMPILE':
writepipestr(b'OK')
2015-10-23 00:44:37 +00:00
hecl.sact.cook(writepipebuf)
elif cmdargs[0] == 'ACTORCOMPILECHARACTERONLY':
writepipestr(b'OK')
hecl.sact.cook_character_only(writepipebuf)
elif cmdargs[0] == 'ACTIONCOMPILECHANNELSONLY':
actionName = cmdargs[1]
writepipestr(b'OK')
hecl.sact.cook_action_channels_only(writepipebuf, actionName)
elif cmdargs[0] == 'GETSUBTYPENAMES':
writepipestr(b'OK')
hecl.sact.get_subtype_names(writepipebuf)
2017-10-25 07:46:32 +00:00
elif cmdargs[0] == 'GETSUBTYPEOVERLAYNAMES':
subtypeName = cmdargs[1]
writepipestr(b'OK')
hecl.sact.get_subtype_overlay_names(writepipebuf, subtypeName)
elif cmdargs[0] == 'GETATTACHMENTNAMES':
writepipestr(b'OK')
hecl.sact.get_attachment_names(writepipebuf)
2016-04-07 03:38:37 +00:00
elif cmdargs[0] == 'GETACTIONNAMES':
writepipestr(b'OK')
2016-04-07 03:38:37 +00:00
hecl.sact.get_action_names(writepipebuf)
elif cmdargs[0] == 'GETBONEMATRICES':
armName = cmdargs[1]
if armName not in bpy.data.objects:
writepipestr(('armature %s not found' % armName).encode())
continue
armObj = bpy.data.objects[armName]
if armObj.type != 'ARMATURE':
writepipestr(('object %s not an ARMATURE' % armName).encode())
continue
writepipestr(b'OK')
writepipebuf(struct.pack('I', len(armObj.data.bones)))
for bone in armObj.data.bones:
writepipebuf(struct.pack('I', len(bone.name)))
writepipebuf(bone.name.encode())
2016-04-08 23:11:05 +00:00
for r in bone.matrix_local.to_3x3():
for c in r:
writepipebuf(struct.pack('f', c))
2017-02-24 08:27:07 +00:00
elif cmdargs[0] == 'RENDERPVS':
pathOut = cmdargs[1]
locX = float(cmdargs[2])
locY = float(cmdargs[3])
locZ = float(cmdargs[4])
hecl.srea.render_pvs(pathOut, (locX, locY, locZ))
writepipestr(b'OK')
elif cmdargs[0] == 'RENDERPVSLIGHT':
pathOut = cmdargs[1]
lightName = cmdargs[2]
hecl.srea.render_pvs_light(pathOut, lightName)
writepipestr(b'OK')
elif cmdargs[0] == 'MAPAREACOMPILE':
if 'MAP' not in bpy.data.objects:
writepipestr(('"MAP" object not in .blend').encode())
continue
map_obj = bpy.data.objects['MAP']
if map_obj.type != 'MESH':
writepipestr(('object "MAP" not a MESH').encode())
continue
writepipestr(b'OK')
hecl.mapa.cook(writepipebuf, map_obj)
elif cmdargs[0] == 'MAPUNIVERSECOMPILE':
writepipestr(b'OK')
hecl.mapu.cook(writepipebuf)
loaded_blend = None
2016-08-02 22:12:49 +00:00
# Main exception handling
try:
# Command loop
while True:
cmdargs = read_cmdargs()
print(cmdargs)
2015-05-24 04:51:16 +00:00
2016-08-02 22:12:49 +00:00
if cmdargs[0] == 'QUIT':
quitblender()
2015-07-28 02:25:33 +00:00
2016-08-02 22:12:49 +00:00
elif cmdargs[0] == 'OPEN':
if 'FINISHED' in bpy.ops.wm.open_mainfile(filepath=cmdargs[1]):
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode = 'OBJECT')
loaded_blend = cmdargs[1]
writepipestr(b'FINISHED')
2016-08-02 22:12:49 +00:00
else:
writepipestr(b'CANCELLED')
2015-10-01 00:40:06 +00:00
2016-08-02 22:12:49 +00:00
elif cmdargs[0] == 'CREATE':
if len(cmdargs) >= 4:
bpy.ops.wm.open_mainfile(filepath=cmdargs[3])
2016-04-05 01:49:42 +00:00
else:
bpy.ops.wm.read_homefile(use_empty=True)
bpy.context.scene.world = bpy.data.worlds.new('World')
loaded_blend = cmdargs[1]
2019-05-08 03:47:34 +00:00
bpy.context.preferences.filepaths.save_version = 0
2016-08-02 22:12:49 +00:00
if 'FINISHED' in bpy.ops.wm.save_as_mainfile(filepath=cmdargs[1]):
bpy.ops.file.hecl_patching_load()
bpy.context.scene.hecl_type = cmdargs[2]
writepipestr(b'FINISHED')
2016-08-02 22:12:49 +00:00
else:
writepipestr(b'CANCELLED')
2016-04-05 01:49:42 +00:00
2016-08-02 22:12:49 +00:00
elif cmdargs[0] == 'GETTYPE':
writepipestr(bpy.context.scene.hecl_type.encode())
2015-08-05 22:59:59 +00:00
2016-08-02 22:12:49 +00:00
elif cmdargs[0] == 'GETMESHRIGGED':
meshName = bpy.context.scene.hecl_mesh_obj
if meshName not in bpy.data.objects:
writepipestr(b'FALSE')
2016-08-02 22:12:49 +00:00
else:
if len(bpy.data.objects[meshName].vertex_groups):
writepipestr(b'TRUE')
2016-08-02 22:12:49 +00:00
else:
writepipestr(b'FALSE')
2016-08-02 22:12:49 +00:00
elif cmdargs[0] == 'SAVE':
2019-05-08 03:47:34 +00:00
bpy.context.preferences.filepaths.save_version = 0
print('SAVING %s' % loaded_blend)
if loaded_blend:
2022-01-03 03:25:11 +00:00
if bpy.app.version >= (3, 0, 0):
ret = bpy.ops.wm.save_as_mainfile(filepath=loaded_blend, check_existing=False, compress=False)
else:
ret = bpy.ops.wm.save_as_mainfile(filepath=loaded_blend, check_existing=False, compress=True)
if 'FINISHED' in ret:
writepipestr(b'FINISHED')
else:
writepipestr(b'CANCELLED')
2016-08-02 22:12:49 +00:00
elif cmdargs[0] == 'PYBEGIN':
writepipestr(b'READY')
2016-08-02 22:12:49 +00:00
globals = {'hecl':hecl}
compbuf = str()
bracket_count = 0
while True:
try:
line = readpipestr()
2016-08-02 22:12:49 +00:00
# ANIM check
if line == b'PYANIM':
# Ensure remaining block gets executed
if len(compbuf):
exec_compbuf(compbuf, globals)
compbuf = str()
animin_loop(globals)
continue
# End check
elif line == b'PYEND':
# Ensure remaining block gets executed
if len(compbuf):
exec_compbuf(compbuf, globals)
compbuf = str()
writepipestr(b'DONE')
2016-08-02 22:12:49 +00:00
break
# Syntax filter
linestr = line.decode().rstrip()
if not len(linestr) or linestr.lstrip()[0] == '#':
writepipestr(b'OK')
2016-08-02 22:12:49 +00:00
continue
leading_spaces = len(linestr) - len(linestr.lstrip())
# Block lines always get appended right away
if linestr.endswith(':') or leading_spaces or bracket_count:
if len(compbuf):
compbuf += '\n'
compbuf += linestr
bracket_count += count_brackets(linestr)
writepipestr(b'OK')
2016-08-02 22:12:49 +00:00
continue
# Complete non-block statement in compbuf
2015-08-05 22:59:59 +00:00
if len(compbuf):
exec_compbuf(compbuf, globals)
2016-08-02 22:12:49 +00:00
# Establish new compbuf
compbuf = linestr
2015-08-05 22:59:59 +00:00
bracket_count += count_brackets(linestr)
2016-08-02 22:12:49 +00:00
except Exception as e:
writepipestr(b'EXCEPTION')
2016-08-02 22:12:49 +00:00
raise
break
writepipestr(b'OK')
2015-08-05 22:59:59 +00:00
2016-08-02 22:12:49 +00:00
elif cmdargs[0] == 'PYEND':
writepipestr(b'ERROR')
2015-08-05 22:59:59 +00:00
2016-08-02 22:12:49 +00:00
elif cmdargs[0] == 'DATABEGIN':
try:
dataout_loop()
2015-07-28 02:25:33 +00:00
except Exception as e:
writepipestr(b'EXCEPTION')
2015-07-28 23:54:54 +00:00
raise
2015-07-28 02:25:33 +00:00
2016-08-02 22:12:49 +00:00
elif cmdargs[0] == 'DATAEND':
writepipestr(b'ERROR')
2016-08-02 22:12:49 +00:00
else:
hecl.command(cmdargs, writepipestr, writepipebuf)
2016-08-02 22:12:49 +00:00
except Exception:
fout = open(err_path, 'w')
traceback.print_exc(file=fout)
fout.close()
raise