Skip to content

Instantly share code, notes, and snippets.

@bwrsandman
Last active January 2, 2016 02:59
Show Gist options
  • Save bwrsandman/8240998 to your computer and use it in GitHub Desktop.
Save bwrsandman/8240998 to your computer and use it in GitHub Desktop.
Performs bzr branch and checks containing python scripts with fake8
#!/usr/bin/bash
# Check if flake8 and bzr exists
which flake8 > /dev/null || exit 1
which bzr > /dev/null || exit 1
# Check that only one parametter was sent
if [ "$#" -lt "1" ] || [ "$#" -gt "2" ]
then
echo "Usage:"
echo "$0 lp:repository [SUBDIRECTORY]"
echo "$0 https://code.launchpad.net/~group/repository/branch/+merge/0000000 [SUBDIRECTORY]"
exit 1
fi
SUBDIR='.'
# Subdirectory defined
if [ "$#" -eq 2 ]
then
SUBDIR="$2"
fi
# Check that parameters are actually a bazaar branch
bzr info "$1" > /dev/null || exit 1
echo "Making a temp directory"
mkdir -p "/tmp/checkout-flake/" || exit 1
cd "/tmp/checkout-flake/" || exit 1
SRCBRANCH=$(echo "${1}" | sed 's,/+merge/[0-9]*$,,g')
TODIR=$SRCBRANCH
TODIR="${TODIR#lp:}"
TODIR="${TODIR#http://}"
TODIR="${TODIR#https://}"
TODIR="${TODIR////.}"
echo branching to $(pwd)/$TODIR
if [ -d "$TODIR" ]
then
rm -rf "$TODIR"
fi
mkdir "$TODIR" || exit 1
bzr branch "$SRCBRANCH" --use-existing-dir "$TODIR"
cd "$TODIR"
flake8 "$SUBDIR" --filename __init__.py --ignore F401
flake8 "$SUBDIR" --exclude __init__.py
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment