def transform_command_with_value(command, value, notification_timestamp):
python_download_script = 'zk_download_data.py'
if len(value) > _LONG_VALUE_THRESHOLD:
# If the value is too long (serverset is too large), OSError may be thrown.
# Instead of passing it in command line, write to a temp file and
# let zk_download_data read from it.
value = value.replace("\n", "").replace("\r", "")
md5digest = zk_util.get_md5_digest(value)
tmp_filename = 'zk_update_largefile_' + md5digest + '_' + str(notification_timestamp)
tmp_dir = tempfile.gettempprefix()
tmp_filepath = os.path.join('/', tmp_dir, tmp_filename)
log.info("This is a long value, write it to temp file %s", tmp_filepath)
try:
with open(tmp_filepath, 'w') as f:
f.write(value + '\n' + md5digest)
except Exception as e:
log.exception(
"%s: Failed to generate temp file %s for storing large size values"
% (e.message, tmp_filepath))
return (None, None)
finally:
f.close()
transformed_command = command.replace(
python_download_script, "%s -l %s" % (
python_download_script, tmp_filepath))
return transformed_command, tmp_filepath
else:
transformed_command = command.replace(
python_download_script, "%s -v '%s'" % (
python_download_script, value))
return transformed_command, None
评论列表
文章目录