X-Git-Url: https://git.tld-linux.org/?p=TLD.git;a=blobdiff_plain;f=pld-builder.new%2FPLD_Builder%2Fpipeutil.py;fp=pld-builder.new%2FPLD_Builder%2Fpipeutil.py;h=4979fea55683bdb0b3f82c59d4d43cad689b92cd;hp=0000000000000000000000000000000000000000;hb=90809c8fec988489786ce00247d9a4150070748b;hpb=ab3934fab858112cd552359b18cb980ea07c310b diff --git a/pld-builder.new/PLD_Builder/pipeutil.py b/pld-builder.new/PLD_Builder/pipeutil.py new file mode 100644 index 0000000..4979fea --- /dev/null +++ b/pld-builder.new/PLD_Builder/pipeutil.py @@ -0,0 +1,41 @@ +# vi: encoding=utf-8 ts=8 sts=4 sw=4 et + +import select +import os +import StringIO + +def rw_pipe(buf_, infd, outfd): + buf = StringIO.StringIO() + buf.write(buf_.read()) + ret = StringIO.StringIO() + pos = 0 + rd_fin = 0 + wr_fin = 0 + buf.seek(pos) + while not (rd_fin and wr_fin): + if wr_fin: + o = [] + else: + o = [infd] + if rd_fin: + i = [] + else: + i = [outfd] + i, o, e = select.select(i, o, []) + if i != []: + s = os.read(outfd.fileno(), 1000) + if s == "": + rd_fin = 1 + ret.write(s) + if o != []: + buf.seek(pos) + s = buf.read(1000) + if s == "": + infd.close() + wr_fin = 1 + else: + cnt = os.write(infd.fileno(), s) + pos += cnt + outfd.close() + ret.seek(0) + return ret