]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - PLD_Builder/pipeutil.py
a67fb077be7a191e004c03b298a7deb2403cd91d
[projects/pld-builder.new.git] / PLD_Builder / pipeutil.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import select
4 import os
5 if sys.version_info[0] == 2:
6     import StringIO
7 else:
8     from io import StringIO
9
10 def rw_pipe(buf_, infd, outfd):
11     buf = StringIO.StringIO()
12     buf.write(buf_.read())
13     ret = StringIO.StringIO()
14     pos = 0
15     rd_fin = 0
16     wr_fin = 0
17     buf.seek(pos)
18     while not (rd_fin and wr_fin):
19         if wr_fin:
20             o = []
21         else:
22             o = [infd]
23         if rd_fin:
24             i = []
25         else:
26             i = [outfd]
27         i, o, e = select.select(i, o, [])
28         if i != []:
29             s = os.read(outfd.fileno(), 1000)
30             if s == "":
31                 rd_fin = 1
32             ret.write(s)
33         if o != []:
34             buf.seek(pos)
35             s = buf.read(1000)
36             if s == "":
37                 infd.close()
38                 wr_fin = 1
39             else:
40                 cnt = os.write(infd.fileno(), s)
41                 pos += cnt
42     outfd.close()
43     ret.seek(0)
44     return ret
This page took 0.031022 seconds and 2 git commands to generate.