initial python import

This commit is contained in:
Jérôme Schneider 2014-01-31 18:16:59 +01:00
parent d79025095a
commit beaf050d91
4 changed files with 152 additions and 301 deletions

2
MANIFEST.in Normal file
View File

@ -0,0 +1,2 @@
include MANIFEST.in
include VERSION

301
eobuilder
View File

@ -1,301 +0,0 @@
#!/bin/bash
set -e
USAGE="Usage: `basename $0` [-h] [-c git|deb|archives|all|old] [-a amd64|i386] -d squeeze|wheezy GIT_REPOSITORY_NAME"
GIT_PATH="/var/lib/eobuilder/git"
ORIGIN_PATH="/var/lib/eobuilder/origin"
PBUILDER_RESULT="/var/lib/eobuilder/results"
EOBUILDER_TMP="/var/tmp/eobuilder"
GIT_REPOSITORY_URL="git+ssh://git@repos.entrouvert.org"
DEBIAN_VERSIONS="wheezy=70 squeeze=60 lenny=50"
DISTS=""
ARCHS="amd64"
BUILD_BRANCH="master"
EOBUILDER_VERSION=6
show_help()
{
echo $USAGE
echo ""
echo "-h: help"
echo "-c: cleaning cache git, deb, archives, old or all"
echo "-b: branch to build (Default: master)"
echo "-a: amd64 and / or i368 (Default: amd64)"
echo "-d: Debian distribution like squeeze or / and wheezy (ex.: squeeze,wheezy)"
echo "GIT_REPOSITORY_NAME: respository name"
echo ""
echo "Examples :"
echo "eobuilder -a amd64 -d squeeze,wheezy wcs"
echo "eobuilder -a amd64 -d wheezy auquotidien"
echo "eobuilder -a i386,amd64 -d squeeze lasso"
echo "eobuilder -c deb"
}
error()
{
echo "$1" >& 2
echo "`basename $0` -h for help" >& 2
exit 1
}
if [ "$(whoami)" != "eobuilder" ]; then
error "You must run be eobuilder to launch this script"
fi
while getopts hc:a:d: OPT; do
case "$OPT" in
h)
show_help
exit 0
;;
c)
if [ "all" = $OPTARG ]; then
rm -rf $ORIGIN_PATH $PBUILDER_RESULT $GIT_PATH
elif [ "git" = $OPTARG ]; then
rm -rf $GIT_PATH
elif [ "deb" = $OPTARG ]; then
rm -rf $PBUILDER_RESULT
elif [ "archives" = $OPTARG ]; then
rm -rf $ORIGIN_PATH
elif [ "old" = $OPTARG ]; then
for file in `find $ORIGIN_PATH -type f -mtime +60 -print`; do
rm $file
done
for file in `find $PBUILDER_RESULT -type f -mtime +60 -print`; do
rm $file
done
else
error "Bad cleaning option : $OPTARG"
fi
echo "Cleaning done."
exit 0
;;
a)
ARCHS=`echo $OPTARG | tr '[A-Z]' '[a-z]' | sed 's/,/ /g'`
;;
d)
DISTS=`echo $OPTARG | tr '[A-Z]' '[a-z]' | sed 's/,/ /g'`
;;
b)
BUILD_BRANCH=$OPTARG
;;
\?)
error "$USAGE"
;;
esac
done
shift `expr $OPTIND - 1`
if [ $# -lt 1 -o ! "$DISTS" ]; then
error "$USAGE"
fi
GIT_NAME=$1
if [ ! -d $GIT_PATH ]; then
mkdir $GIT_PATH
fi
if [ ! -d $ORIGIN_PATH ]; then
mkdir $ORIGIN_PATH
fi
if [ ! $PBUILDER_RESULT ]; then
mkdir $PBUILDER_RESULT
fi
GIT_PROJECT_PATH="$GIT_PATH/$GIT_NAME"
NEW=1
echo "+ Cloning or fetching git repository"
if [ ! -d $GIT_PROJECT_PATH ]; then
cd $GIT_PATH
echo "+ git clone $GIT_REPOSITORY_URL/$GIT_NAME.git"
git clone $GIT_REPOSITORY_URL/$GIT_NAME.git
elif [ ! `cd $GIT_PROJECT_PATH && git fetch` ]; then
NEW=0
fi
is_something_to_build() {
if [ $NEW -eq 1 ]; then
return 0
fi
for DIST in $DISTS; do
for ARCH in $ARCHS; do
if [ ! -f $GIT_PATH/$1_$2_${DIST}_${ARCH}.build ]; then
return 0
fi
done
done
return 1
}
echo "+ Updating git repository and parsing configuration ..."
cd $GIT_PROJECT_PATH
git checkout $BUILD_BRANCH
git pull
if [ -f "setup.py" ]; then
python setup.py --help >/dev/null 2>&1
PROJECT_NAME=`python setup.py --name`
PROJECT_VERSION=`python setup.py --version`
PROJECT_FULL_NAME=`python setup.py --fullname`
elif [ -f "configure.ac" ]; then
./autogen.sh
make all
PROJECT_NAME=`./configure --version | head -n1 | sed 's/ configure.*//'`
PROJECT_AC_VERSION=`./configure --version | head -n1 | sed 's/.* configure //'`
PROJECT_VERSION=`echo $PROJECT_AC_VERSION | sed 's/-/./g'`
PROJECT_FULL_NAME=$PROJECT_NAME
elif [ -f "Makefile" ]; then
PROJECT_NAME=`make name`
PROJECT_VERSION=`make version`
PROJECT_FULL_NAME=`make fullname`
else
echo Unsupported project type
exit 1
fi
BUILD_DIR="$EOBUILDER_TMP/$PROJECT_NAME"
COMMIT_NUMBER=`git log -n1 | grep 'commit' | sed 's/commit\s*//'`
function cleaning() {
echo "+ Cleaning ..."
rm -rf $BUILD_DIR
}
trap cleaning EXIT
DID_BUILD=0
for DIST in $DISTS; do
cleaning
cd $GIT_PROJECT_PATH
DEBIAN_REPOSITORY="$DIST-eobuilder"
echo "+ Updating Debian branch for $DIST ..."
DEBIAN_BRANCH="debian"
if [ "$(git branch -r -l | grep debian-$DIST)" ]; then
DEBIAN_BRANCH="debian-$DIST"
fi
git checkout $DEBIAN_BRANCH
git pull
PACKAGE_NAME=`cat debian/control | sed 's/^Source\s*:\s*//; t; d'`
if [ -f $GIT_PATH/${PROJECT_NAME}_${DIST}.last_version ]; then
LAST_DEBIAN_PACKAGE_VERSION=`cat $GIT_PATH/${PROJECT_NAME}_${DIST}.last_version`
else
LAST_DEBIAN_PACKAGE_VERSION=`dpkg-parsechangelog | sed 's/^Version: //; t; d'`
fi
LAST_VERSION=`echo $LAST_DEBIAN_PACKAGE_VERSION | cut -d '-' -f1`
DEBIAN_FIRST_INC=1
DEBIAN_SECOND_INC=1
if [ $LAST_VERSION = $PROJECT_VERSION ]; then
DEBIAN_FIRST_INC=`echo $LAST_DEBIAN_PACKAGE_VERSION | cut -d "+" -f1 | cut -d '-' -f2`
if [[ "$LAST_DEBIAN_PACKAGE_VERSION" == *~* ]]; then
DEBIAN_SECOND_INC=`echo $LAST_DEBIAN_PACKAGE_VERSION | cut -d '~' -f2 | cut -d '+' -f2`
DEBIAN_SECOND_INC=$(($DEBIAN_SECOND_INC + 1))
else
DEBIAN_FIRST_INC=$(($DEBIAN_FIRST_INC + 1))
DEBIAN_SECOND_INC=1
fi
fi
PACKAGE_VERSION="$PROJECT_VERSION-$DEBIAN_FIRST_INC+eob${EOBUILDER_VERSION}"
for debian_version in $DEBIAN_VERSIONS; do
set -- `echo $debian_version | tr '=' ' '`
if [ $1 = $DIST ]; then
PACKAGE_VERSION+="~eo$2+$DEBIAN_SECOND_INC"
fi
done
if [ -f $GIT_PATH/${PROJECT_NAME}_${PACKAGE_VERSION}_${DIST}.build ]; then
echo "+ Build for $DIST already built !"
continue
fi
if [ ! -f $ORIGIN_PATH/${PACKAGE_NAME}_${PROJECT_VERSION}.orig.tar.bz2 ]; then
echo "+ Generating origin tarball ..."
cd $GIT_PROJECT_PATH
git checkout $BUILD_BRANCH
if [ -f './setup.py' ]; then
python setup.py clean --all
python setup.py sdist --formats=bztar
mv dist/$PROJECT_FULL_NAME.tar.bz2 ${ORIGIN_PATH}/${PACKAGE_NAME}_${PROJECT_VERSION}.orig.tar.bz2
elif [ -f './configure.ac' ]; then
make dist-bzip2
mv $PROJECT_NAME-$PROJECT_AC_VERSION.tar.bz2 ${ORIGIN_PATH}/${PACKAGE_NAME}_${PROJECT_VERSION}.orig.tar.bz2
elif [ -f './Makefile' ]; then
make dist-bzip2
mv sdist/$PROJECT_FULL_NAME.tar.bz2 ${ORIGIN_PATH}/${PACKAGE_NAME}_${PROJECT_VERSION}.orig.tar.bz2
else
echo Unsupported project type
exit 1
fi
fi
echo "+ Prepararing debian build ($PACKAGE_NAME $PACKAGE_VERSION) ..."
git checkout $DEBIAN_BRANCH
mkdir -p $BUILD_DIR
cp ${ORIGIN_PATH}/${PACKAGE_NAME}_${PROJECT_VERSION}.orig.tar.bz2 $BUILD_DIR
cd $BUILD_DIR
tar xfvj ${PACKAGE_NAME}_${PROJECT_VERSION}.orig.tar.bz2
cp -r $GIT_PROJECT_PATH/debian $BUILD_DIR/$PROJECT_NAME-$PROJECT_VERSION
cd $PROJECT_NAME-$PROJECT_VERSION
echo """${PACKAGE_NAME} (${PACKAGE_VERSION}) ${DIST}-eobuilder; urgency=low
* Automatic version : commit ${COMMIT_NUMBER}
-- Jérôme Schneider <info@entrouvert.com> `date -R`
""" > debian/new_changelog
cat debian/changelog >> debian/new_changelog
mv debian/new_changelog debian/changelog
for ARCH in $ARCHS; do
PBUILDER_PROJECT_RESULT="${PBUILDER_RESULT}/${DIST}-${ARCH}/"
if [ ! -d $PBUILDER_PROJECT_RESULT ]; then
mkdir -p $PBUILDER_PROJECT_RESULT
fi
cd $GIT_PATH
# source option
SOURCE_BUILD=$GIT_PATH/${PROJECT_NAME}_${PROJECT_VERSION}_${DIST}_source.build
if [ -f $SOURCE_BUILD ]; then
SOURCE_OPT='-b' # build only binary packages
else
SOURCE_OPT='-sa'
fi
if [ $NEW -eq 0 -a -f $GIT_PATH/${PROJECT_NAME}_${PACKAGE_VERSION}_${DIST}_${ARCH}.build ]; then
echo "Already built."
else
cd $BUILD_DIR/$PROJECT_NAME-$PROJECT_VERSION
echo "+ Building $PROJECT_NAME $PROJECT_VERSION $DIST $ARCH"
DIST=$DIST ARCH=$ARCH pdebuild --use-pdebuild-internal --architecture $ARCH --debbuildopts "$SOURCE_OPT"
echo "+ Add a build file to lock new build for $DIST on $ARCH"
touch $GIT_PATH/${PROJECT_NAME}_${PACKAGE_VERSION}_${DIST}_${ARCH}.build
echo "+ Sending package ..."
cd $PBUILDER_PROJECT_RESULT
dput -u $DEBIAN_REPOSITORY ${PACKAGE_NAME}_${PACKAGE_VERSION}_${ARCH}.changes
echo "+ Updating repository ..."
ssh root@leucas.entrouvert.org "/etc/cron.hourly/process-incoming"
fi
# mark that we did build a source package
if [ ! -f $SOURCE_BUILD ]; then
touch $SOURCE_BUILD
fi
done
echo "+ Add a build file to lock new build for $DIST"
touch $GIT_PATH/${PROJECT_NAME}_${PACKAGE_VERSION}_${DIST}.build
echo -n $PACKAGE_VERSION > $GIT_PATH/${PROJECT_NAME}_${DIST}.last_version
done

70
eobuilder-ctl Executable file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env python
from optparse import OptionParser
from optparse import Option
VERSION = '6'
PROG = 'eobuilder'
class MultipleOption(Option):
ACTIONS = Option.ACTIONS + ("extend",)
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
lvalue = value.split(",")
values.ensure_value(dest, []).extend(lvalue)
else:
Option.take_action(
self, action, dest, opt, value, values, parser)
def parse_cmdline():
parser = OptionParser(option_class=MultipleOption,
usage='usage: %prog [OPTIONS] -d [wheezy,squeeze|wheezy|squeeze] GIT_REPOSITORY_NAME')
parser.add_option("-a", "--architectures",
action="extend", type="string",
dest="architectures", metavar='ARCHITECTURES',
default=[],
help="ARCHITECTURES: amd64 and / or i368 (Default: amd64)")
parser.add_option("-d", "--distribution",
action="extend", type="string",
dest="distrib", metavar='DISTRIBUTIONS',
help="DISTRIBUTIONS: squeeze and / or wheezy")
parser.add_option("-b", "--branch",
action="store", type="string",
dest="branch", metavar='NAME',
default="master",
help="branch to build (Default: master)")
parser.add_option("-c", "--clean",
action="extend", type="string",
dest="cleanning", metavar='CLEANNING_METHODS',
default=[],
help="CLEANNING_METHODS: git, deb, archives, old and / or all")
(options, args) = parser.parse_args()
if len(args) != 1 and not options.cleanning:
parser.error("you should select one GIT_REPOSITORY_NAME")
if len(args) and options.cleanning:
parser.error("you shouldn't use argument when cleanning")
if len(args) and not options.distrib:
parser.error("you should set option --distribution")
if not options.architectures:
options.architectures = ["amd64"]
return options, args
def main():
options, args = parse_cmdline()
if __name__ == "__main__":
main()

80
setup.py Executable file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env python
import glob
import re
import sys
import os
from setuptools import setup, find_packages
from setuptools.command.install_lib import install_lib as _install_lib
from distutils.command.build import build as _build
from distutils.command.sdist import sdist
from distutils.cmd import Command
class eo_sdist(sdist):
def run(self):
print "creating VERSION file"
if os.path.exists('VERSION'):
os.remove('VERSION')
version = get_version()
version_file = open('VERSION', 'w')
version_file.write(version)
version_file.close()
sdist.run(self)
print "removing VERSION file"
if os.path.exists('VERSION'):
os.remove('VERSION')
def get_version():
version = None
if os.path.exists('VERSION'):
version_file = open('VERSION', 'r')
version = version_file.read()
version_file.close()
return version
for d in glob.glob('*'):
if not os.path.isdir(d):
continue
module_file = os.path.join(d, '__init__.py')
if not os.path.exists(module_file):
continue
for v in re.findall("""__version__ *= *['"](.*)['"]""",
open(module_file).read()):
assert version is None
version = v
if version:
break
assert version is not None
if os.path.exists('.git'):
import subprocess
p = subprocess.Popen(['git','describe','--dirty','--match=v*'],
stdout=subprocess.PIPE)
result = p.communicate()[0]
assert p.returncode == 0, 'git returned non-zero'
new_version = result.split()[0][1:]
assert not new_version.endswith('-dirty'), 'git workdir is not clean'
assert new_version.split('-')[0] == version, '__version__ must match the last git annotated tag'
version = new_version.replace('-', '.')
return version
setup(name="eobuilder",
version=get_version(),
license="AGPLv3 or later",
description="Entr'ouvert Package Builder",
author="Entr'ouvert",
author_email="info@entrouvert.org",
maintainer="Jerome Schneider",
maintainer_email="info@entrouvert.com",
include_package_data=True,
url='https://dev.entrouvert.org/projects/eobuilder',
packages=find_packages(),
scripts=('eobuilder-ctl',),
install_requires=[
'GitPython',
],
cmdclass={'sdist': eo_sdist},
)