Skip to content

Instantly share code, notes, and snippets.

@ethankhall
Created August 16, 2016 21:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethankhall/8b885e1a46adf6bb3464ec526ac8f28d to your computer and use it in GitHub Desktop.
Save ethankhall/8b885e1a46adf6bb3464ec526ac8f28d to your computer and use it in GitHub Desktop.
Upload pypi to bintray
NAME=$1
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO=""
USERNAME=""
KEY=""
echo "Uploading $1 to bintray"
if jfrog bt package-show $USERNAME/$USERNAME/$NAME > /dev/null; then
echo "Package already exists, not creating"
else
echo "Creating new package $NAME"
license=`curl -Ss https://pypi.python.org/pypi/$NAME/json | jq -r .info.license | sed 's/BSD License/BSD/;s/MIT License/MIT/'`
licenseBeta=`curl -Ss https://pypi.python.org/pypi/$NAME/json | jq .info.classifiers | grep "License :: OSI Approved"`
if echo $licenseBeta | grep 'BSD License'; then
license="BSD"
elif echo $licenseBeta | grep 'Apache Software License'; then
license="Apache-2.0"
elif echo $licenseBeta | grep 'MIT License'; then
license="MIT"
elif echo $licenseBeta | grep 'Python Software Foundation License'; then
license="PythonSoftFoundation"
elif echo $licenseBeta | grep 'Mozilla Public License 2.0 (MPL 2.0)'; then
license="MPL-2.0"
fi
url=`curl -Ss https://pypi.python.org/pypi/$NAME/json | jq -r .info.package_url`
if jfrog bt package-create --licenses "$license" --vcs-url "$url" "$USERNAME/$REPO/$NAME"; then
echo "Successfully created $NAME"
else
echo "===============>> Unable to create repo $NAME, bailing out"
exit 1
fi
fi
for file in `find $DIR -type f -name "*$NAME*"`; do
upload_path=`echo $file | sed -e "s;$DIR;;"`
version=`echo $upload_path | cut -d'/' -f 4`
#echo "Uploading $file to $upload_path with version $version"
if [ "`basename $file`" != ".DS_Store" ]; then
status=`curl -s --head -w %{http_code} -u$USERNAME:$KEY "https://$USERNAME.bintray.com/$REPO/$upload_path" -o /dev/null`
if [ 404 -eq $status ]; then
if curl -Ss -T $file -u$USERNAME:$KEY "https://api.bintray.com/content/$USERNAME/$REPO/$NAME/$version$upload_path?publish=1" > /dev/null; then
echo "$file was uploaded successfully!"
else
echo "===========> $file failed to upload!!"
fi
else
echo "$file already exists, skipping"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment