MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / makepipeline

Function makepipeline

tools/python-3.11.9-amd64/Lib/pipes.py:184–250  ·  view source on GitHub ↗
(infile, steps, outfile)

Source from the content-addressed store, hash-verified

182
183
184def makepipeline(infile, steps, outfile):
185 # Build a list with for each command:
186 # [input filename or '', command string, kind, output filename or '']
187
188 list = []
189 for cmd, kind in steps:
190 list.append(['', cmd, kind, ''])
191 #
192 # Make sure there is at least one step
193 #
194 if not list:
195 list.append(['', 'cat', '--', ''])
196 #
197 # Take care of the input and output ends
198 #
199 [cmd, kind] = list[0][1:3]
200 if kind[0] == 'f' and not infile:
201 list.insert(0, ['', 'cat', '--', ''])
202 list[0][0] = infile
203 #
204 [cmd, kind] = list[-1][1:3]
205 if kind[1] == 'f' and not outfile:
206 list.append(['', 'cat', '--', ''])
207 list[-1][-1] = outfile
208 #
209 # Invent temporary files to connect stages that need files
210 #
211 garbage = []
212 for i in range(1, len(list)):
213 lkind = list[i-1][2]
214 rkind = list[i][2]
215 if lkind[1] == 'f' or rkind[0] == 'f':
216 (fd, temp) = tempfile.mkstemp()
217 os.close(fd)
218 garbage.append(temp)
219 list[i-1][-1] = list[i][0] = temp
220 #
221 for item in list:
222 [inf, cmd, kind, outf] = item
223 if kind[1] == 'f':
224 cmd = 'OUT=' + quote(outf) + '; ' + cmd
225 if kind[0] == 'f':
226 cmd = 'IN=' + quote(inf) + '; ' + cmd
227 if kind[0] == '-' and inf:
228 cmd = cmd + ' <' + quote(inf)
229 if kind[1] == '-' and outf:
230 cmd = cmd + ' >' + quote(outf)
231 item[1] = cmd
232 #
233 cmdlist = list[0][1]
234 for item in list[1:]:
235 [cmd, kind] = item[1:3]
236 if item[0] == '':
237 if 'f' in kind:
238 cmd = '{ ' + cmd + '; }'
239 cmdlist = cmdlist + ' |\n' + cmd
240 else:
241 cmdlist = cmdlist + '\n' + cmd

Callers 1

makepipelineMethod · 0.85

Calls 4

quoteFunction · 0.90
appendMethod · 0.45
insertMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected