Skip to content

Instantly share code, notes, and snippets.

@superdaigo
Created August 15, 2013 10:21
Show Gist options
  • Save superdaigo/6239827 to your computer and use it in GitHub Desktop.
Save superdaigo/6239827 to your computer and use it in GitHub Desktop.
Check pip download time (sec) for each pypi mirror servers.
#!/bin/bash
# System Requirements
# pip ... python package install command
# requirements.txt ... package list to install via pip
TMP_DIR="${HOME}/tmp"
REQUIREMENTS_TXT="requirements.txt"
if [ -f $1 ] ; then
REQUIREMENTS_TXT=$1
fi
PYPI_SERVERS=('pypi.python.org' 'b.pypi.python.org' 'c.pypi.python.org'
'd.pypi.python.org' 'e.pypi.python.org' 'f.pypi.python.org' 'a.pypi.python.org'
'g.pypi.python.org' 'pypi.crate.io' 'pypi.douban.com' 'pypi.hustunique.com' )
DL_DIR=$TMP_DIR/dl
OUT_TXT=$TMP_DIR/out.txt
OUT_LOG=$TMP_DIR/out.log
function download_test() {
# prepare
mkdir -p $DL_DIR
# download
START_TIME=$SECONDS
pip install -d $DL_DIR -i $PYPI_URL -r $REQUIREMENTS_TXT >> $OUT_LOG
ELAPSED_TIME=$(($SECONDS - $START_TIME))
# cleanup
rm -rf $DL_DIR
echo "Server: $s Elapsed: $ELAPSED_TIME" >> $OUT_TXT
}
echo "Start downlaading (Logfile: ${OUT_LOG})"
rm -rf $DL_DIR
touch $OUT_TXT
touch $OUT_LOG
for s in ${PYPI_SERVERS[@]}
do
printf " ${s} ..."
PYPI_URL="http://${s}/simple"
download_test
printf " $ELAPSED_TIME sec.\n"
done
echo "Finish (Outfile: ${OUT_TXT})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment