def ref_from_external_file(filename, id): output_ctx = make_local_output(id) with output_ctx: (new_filename, is_fd) = output_ctx.get_filename_or_fd() assert not is_fd shutil.move(filename, new_filename) return output_ctx.get_completed_ref()
def __init__(self, id, block_store): self.id = id self.block_store = block_store self.current_pos = 0 self.output_ctx = make_local_output(self.id) (filename, is_fd) = self.output_ctx.get_filename_or_fd() assert not is_fd self.output_filename = filename
def ref_from_string(string, id): if len(string) < 1024: return SWDataValue(id, value=encode_datavalue(string)) else: output_ctx = make_local_output(id) filename, _ = output_ctx.get_filename_or_fd() with open(filename, "w") as fp: fp.write(string) output_ctx.close() return output_ctx.get_completed_ref()
def write_fixed_ref_string(string, fixed_ref): output_ctx = make_local_output(fixed_ref.id) with open(filename_for_ref(fixed_ref), "w") as fp: fp.write(string) output_ctx.close()