Created
February 24, 2019 09:23
-
-
Save mhchia/977c8353ff4aea02d295dfa0b8ed7a56 to your computer and use it in GitHub Desktop.
Copy bindings code from py-libp2p-daemon-bindings to trinity, and modify import paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# TODO: currently only support "bindings to trinity", probably need the reverse direction as well. | |
echo "Run this script with a new process spun up because of the usage of \`exit\`" | |
PATH_BINDINGS="$HOME/projects/ethereum/pyeth/py-libp2p-daemon-bindings" | |
PATH_TRINITY="$HOME/projects/ethereum/pyeth/trinity" | |
LIBP2P_BINDINGS_PACKAGE="p2pclient" | |
PATH_RELATIVE_TRINITY_LIBP2P_MODULE="libp2p/p2pclient" | |
# replace '/' with '.' | |
TRINITY_LIBP2P_PACKAGE=${PATH_RELATIVE_TRINITY_LIBP2P_MODULE//\//.} | |
PATH_TRINITY_LIBP2P="$PATH_TRINITY/$PATH_RELATIVE_TRINITY_LIBP2P_MODULE" | |
PATH_TRINITY_LIBP2P_TEST="$PATH_TRINITY/tests/libp2p/p2pclient" | |
# checking paths | |
if [ ! -e $PATH_BINDINGS ]; then | |
echo "bindings' path "$PATH_BINDINGS" is not found" | |
exit 1 | |
fi | |
if [ ! -e $PATH_TRINITY ]; then | |
echo "trinity's path "$PATH_TRINITY" is not found" | |
exit 1 | |
fi | |
# p2pclient code | |
# XXX: if failed here, make sure the paths are correct | |
cp -r $PATH_BINDINGS/p2pclient/pb $PATH_TRINITY_LIBP2P | |
cp $PATH_BINDINGS/p2pclient/*.py $PATH_TRINITY_LIBP2P | |
# p2pclient tests | |
cp $PATH_BINDINGS/tests/*.py $PATH_TRINITY_LIBP2P_TEST | |
FILES_TO_MODIFY=$(find $PATH_TRINITY_LIBP2P_TEST -name 'test_*.py' -type f) | |
FROM_IMPORT_REPLACE_STATEMENT="s/from $LIBP2P_BINDINGS_PACKAGE/from $TRINITY_LIBP2P_PACKAGE/g" | |
IMPORT_REPLACE_STATEMENT="s/import $LIBP2P_BINDINGS_PACKAGE/import $TRINITY_LIBP2P_PACKAGE/g" | |
if [ $(uname) = 'Darwin' ]; then | |
sed -i '' "$FROM_IMPORT_REPLACE_STATEMENT" $FILES_TO_MODIFY | |
sed -i '' "$IMPORT_REPLACE_STATEMENT" $FILES_TO_MODIFY | |
else | |
# other OS or distributions other than macOS | |
sed -i $FROM_IMPORT_REPLACE_STATEMENT $FILES_TO_MODIFY | |
sed -i $IMPORT_REPLACE_STATEMENT $FILES_TO_MODIFY | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment