Skip to content

Commit

Permalink
Merge pull request #15 from RogueM/commit
Browse files Browse the repository at this point in the history
using sys.exit + __version__ in lib
  • Loading branch information
Gadgetoid authored Nov 9, 2016
2 parents 96a1a63 + c69d57d commit 80cafae
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/wave_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import math
from itertools import tee
from time import sleep
from sys import exit

try:
import numpy
Expand Down
2 changes: 2 additions & 0 deletions library/piglow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import atexit
import time
from sys import exit

try:
import sn3218
except ImportError:
exit("This library requires the sn3218 module\nInstall with: sudo pip install sn3218")

__version__ = '1.2.3'

sn3218.enable()
sn3218.enable_leds(0b111111111111111111)
Expand Down
1 change: 1 addition & 0 deletions library/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Once running you'll need to press ctrl-C to cancel stop the script

import time
from sys import exit, version_info

try:
from smbus import SMBus
Expand Down
2 changes: 1 addition & 1 deletion packaging/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: piglow
Maintainer: Phil Howard <phil@pimoroni.com>
Homepage: https://github.com/pimoroni/piglow
Section: python
Priority: optional
Priority: extra
Build-Depends: debhelper (>= 9.0.0), dh-python, python-all (>= 2.7), python-setuptools, python3-all (>= 3.4), python3-setuptools
Standards-Version: 3.9.6
X-Python-Version: >= 2.7
Expand Down
165 changes: 165 additions & 0 deletions packaging/makeall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/bin/bash

# script control variables

reponame="" # leave this blank for auto-detection
libname="" # leave this blank for auto-detection
packagename="" # leave this blank for auto-selection

debianlog="debian/changelog"
debcontrol="debian/control"
debcopyright="debian/copyright"
debrules="debian/rules"
debreadme="debian/README"

debdir="$(pwd)"
rootdir="$(dirname $debdir)"
libdir="$rootdir/library"

FLAG=false

# function define

success() {
echo "$(tput setaf 2)$1$(tput sgr0)"
}

inform() {
echo "$(tput setaf 6)$1$(tput sgr0)"
}

warning() {
echo "$(tput setaf 1)$1$(tput sgr0)"
}

newline() {
echo ""
}

# assessing repo and library variables

if [ -z "$reponame" ] || [ -z "$libname" ]; then
inform "detecting reponame and libname..."
else
inform "using reponame and libname overrides"
fi

if [ -z "$reponame" ]; then
if [[ $rootdir == *"python"* ]]; then
repodir="$(dirname $rootdir)"
reponame="$(basename $repodir)"
else
repodir="$rootdir"
reponame="$(basename $repodir)"
fi
reponame=$(echo "$reponame" | tr "[A-Z]" "[a-z]")
fi

if [ -z "$libname" ]; then
cd "$libdir"
libname=$(grep "name" setup.py | tr -d "[:space:]" | cut -c 7- | rev | cut -c 3- | rev)
libname=$(echo "$libname" | tr "[A-Z]" "[a-z]") && cd "$debdir"
fi

if [ -z "$packagename" ]; then
packagename="$libname"
fi

echo "reponame is $reponame and libname is $libname"
echo "output packages will be python-$packagename and python3-$packagename"

# checking generating changelog file

./makelog.sh
version=$(head -n 1 "$libdir/CHANGELOG.txt")
echo "building $libname version $version"

# checking debian/changelog file

inform "checking debian/changelog file..."

if ! head -n 1 $debianlog | grep "$libname" &> /dev/null; then
warning "library not mentioned in header!" && FLAG=true
elif head -n 1 $debianlog | grep "UNRELEASED"; then
warning "this changelog is not going to generate a release!"
warning "change distribution to 'stable'" && FLAG=true
fi

# checking debian/copyright file

inform "checking debian/copyright file..."

if ! grep "^Source" $debcopyright | grep "$reponame" &> /dev/null; then
warning "$(grep "^Source" $debcopyright)" && FLAG=true
fi

if ! grep "^Upstream-Name" $debcopyright | grep "$libname" &> /dev/null; then
warning "$(grep "^Upstream-Name" $debcopyright)" && FLAG=true
fi

# checking debian/control file

inform "checking debian/control file..."

if ! grep "^Source" $debcontrol | grep "$libname" &> /dev/null; then
warning "$(grep "^Source" $debcontrol)" && FLAG=true
fi

if ! grep "^Homepage" $debcontrol | grep "$reponame" &> /dev/null; then
warning "$(grep "^Homepage" $debcontrol)" && FLAG=true
fi

if ! grep "^Package: python-$packagename" $debcontrol &> /dev/null; then
warning "$(grep "^Package: python-" $debcontrol)" && FLAG=true
fi

if ! grep "^Package: python3-$packagename" $debcontrol &> /dev/null; then
warning "$(grep "^Package: python3-" $debcontrol)" && FLAG=true
fi

if ! grep "^Priority: extra" $debcontrol &> /dev/null; then
warning "$(grep "^Priority" $debcontrol)" && FLAG=true
fi


# checking debian/rules file

inform "checking debian/rules file..."

if ! grep "debian/python-$packagename" $debrules &> /dev/null; then
warning "$(grep "debian/python-" $debrules)" && FLAG=true
fi

if ! grep "debian/python3-$packagename" $debrules &> /dev/null; then
warning "$(grep "debian/python3-" $debrules)" && FLAG=true
fi

# checking debian/README file

inform "checking debian/readme file..."

if ! grep -e "$libname" -e "$reponame" $debreadme &> /dev/null; then
warning "README does not seem to mention product, repo or lib!" && FLAG=true
fi

# summary of checks pre build

if $FLAG; then
warning "Check all of the above and correct!" && exit 1
else
inform "we're good to go... bulding!"
fi

# building deb and final checks

./makedeb.sh

inform "running lintian..."
lintian -v $(find -name "python*$version*.deb")
lintian -v $(find -name "python3*$version*.deb")

inform "checking signatures..."
gpg --verify $(find -name "*$version*changes")
gpg --verify $(find -name "*$version*dsc")

exit 0
4 changes: 2 additions & 2 deletions packaging/makedeb.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

gettools="yes"
gettools="no"
setup="yes"
cleanup="yes"
pkgfiles=( "build" "changes" "deb" "dsc" "tar.xz" )
Expand All @@ -16,7 +16,7 @@ if [ $setup == "yes" ]; then
cp -R ./debian/ ../library/
fi

cd ../library && debuild
cd ../library && debuild -aarmhf

for file in ${pkgfiles[@]}; do
mv ../*.$file ../packaging
Expand Down
68 changes: 66 additions & 2 deletions packaging/makelog.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,82 @@
#!/bin/bash

# script control variables

libname="" # leave this blank for auto-detection
sibname=() # name of sibling in packages list
versionwarn="yes" # set to anything but 'yes' to turn off warning

debdir="$(pwd)"
rootdir="$(dirname $debdir)"
libdir="$rootdir/library"

mainlog="CHANGELOG"
debianlog="debian/changelog"
pypilog="../library/CHANGELOG.txt"
pypilog="$libdir/CHANGELOG.txt"

# function define

success() {
echo "$(tput setaf 2)$1$(tput sgr0)"
}

inform() {
echo "$(tput setaf 6)$1$(tput sgr0)"
}

warning() {
echo "$(tput setaf 1)$1$(tput sgr0)"
}

newline() {
echo ""
}

# generate debian changelog

cat $mainlog > $debianlog
inform "seeded debian changelog"

# generate pypi changelog

sed -e "/--/d" -e "s/ \*/\*/" \
-e "s/.*\([0-9].[0-9].[0-9]\).*/\1/" \
-e '/[0-9].[0-9].[0-9]/ a\
-----' $mainlog | cat -s > $pypilog
-----' $mainlog | cat -s > $pypilog

version=$(head -n 1 $pypilog)
inform "pypi changelog generated"

# touch up version in setup.py file

if [ -n $(grep version "$libdir/setup.py" &> /dev/null) ]; then
inform "touched up version in setup.py"
sed -i "s/'[0-9].[0-9].[0-9]'/'$version'/" "$libdir/setup.py"
else
warning "couldn't touch up version in setup, no match found"
fi

# touch up version in lib or package siblings

if [ -z "$libname" ]; then
cd "$libdir"
libname=$(grep "name" setup.py | tr -d "[:space:]" | cut -c 7- | rev | cut -c 3- | rev)
libname=$(echo "$libname" | tr "[A-Z]" "[a-z]") && cd "$debdir"
sibname+=( "$libname" )
elif [ "$libname" != "package" ]; then
sibname+=( "$libname" )
fi

for sibling in ${sibname[@]}; do
if grep -e "__version__" "$libdir/$sibling.py" &> /dev/null; then
sed -i "s/__version__ = '[0-9].[0-9].[0-9]'/__version__ = '$version'/" "$libdir/$sibling.py"
inform "touched up version in $sibling.py"
elif grep -e "__version__" "$libdir/$sibling/__init__.py" &> /dev/null; then
sed -i "s/__version__ = '[0-9].[0-9].[0-9]'/__version__ = '$version'/" "$libdir/$sibling/__init__.py"
inform "touched up version in $sibling/__init__.py"
elif [ "$versionwarn" == "yes" ]; then
warning "couldn't touch up __version__ in $sibling, no match found"
fi
done

exit 0

0 comments on commit 80cafae

Please sign in to comment.