Question

I need to implement an SVN pre-commit hook which executes a script that itself is stored in SVN.

I can use the svn cat command to pipe that script to the Python interpreter, as follows:

svn cat file://$REPO/trunk/my_script.py | python - --argument1 --argument2

However, my_script.py itself requires data to be piped on STDIN.

That data is not stored in a file; it is stored on the network. I would prefer not to have to download the data to a temporary file, as normally I could pipe it to a Python program:

curl http://example.com/huge_file.txt | python my_script.py

I'm not sure how to combine both of these pipes.

Was it helpful?

Solution

I figured out how to do this without creating any temporary files, but not strictly with "pipes".

curl http://example.com/huge_file.txt | python <(svn cat file://$REPO/trunk/my_script.py) --argument1 --argument2

I used the "anonymous file descriptor" construct in Bash, which can be used in place of any file path.

E.g. python my_script.py would be equivalent to python <(cat my_script.py)

OTHER TIPS

I don't think this is possible. You feed the script as standard input to the python interpreter. This means that the python interpreter is already attached to an input stream. I don't think the script contents can create a second standard input to read from.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top