Permalink
Browse files

set the configuration of the pybit-client to use external configurati…

…on and enable this as debconf for Debian packaging.
  • Loading branch information...
codehelp committed Nov 19, 2012
1 parent 75c1f67 commit 640ecaffe563143d822fc514a75c17ca2b9ff351
View
@@ -1,16 +1,15 @@
{
- "clientid": "1",
- "host_arch": "i386",
+ "clientid": "",
+ "host_arch": "",
"use_lvm": true,
- "suite": "development",
- "distribution": "Debian",
- "pkg_format": "deb",
+ "distribution": "",
+ "pkg_format": "",
"buildroot": "/home/buildd/pybit",
- "host": "cayenne.tcl.office",
+ "host": "localhost",
"port": "5672",
"userid": "guest",
"password": "guest",
"vhost": "/",
"dput": "-U",
- "dput_dest": "tcl"
+ "dput_dest": ""
}
View
@@ -7,7 +7,7 @@ Uploaders: Nick Davidson <nickd@toby-churchill.com>,
Neil Williams <neilw@toby-churchill.com>,
Nick Bane <nick@cecomputing.co.uk>,
James Bennet <James.Bennet@toby-churchill.com>
-Build-Depends: debhelper (>= 7.0.50~), docbook-xsl, xsltproc,
+Build-Depends: debhelper (>= 7.0.50~), docbook-xsl, xsltproc, po-debconf,
python (>= 2.6.6-3~), python2.6, python-setuptools,
python-jsonpickle,
python-requests (>=0.10.1-1~),
View
@@ -0,0 +1,2 @@
+[type: gettext/rfc822deb] pybit-client.templates
+
View
@@ -0,0 +1,150 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: pybit@packages.debian.org\n"
+"POT-Creation-Date: 2012-11-19 14:13+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:1001
+msgid "Specify pybit client id string:"
+msgstr ""
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:1001
+msgid ""
+"Each client needs to have a unique string to identify itself within the job "
+"list and queues."
+msgstr ""
+
+#. Type: boolean
+#. Description
+#: ../pybit-client.templates:2001
+msgid "Use lvm snapshots on this client?"
+msgstr ""
+
+#. Type: boolean
+#. Description
+#: ../pybit-client.templates:2001
+msgid ""
+"If your sbuild configuration uses lvm-snapshots, pybit-client can ensure "
+"that your snapshot apt cache data remains updated whilst keeping the "
+"snapshot clean."
+msgstr ""
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:3001
+msgid "Specify the buildd location:"
+msgstr ""
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:3001
+msgid ""
+"Please enter a writeable directory where the version control handler and the "
+"upload task can write files."
+msgstr ""
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:3001
+msgid "If this is empty, the default /home/buildd/pybit will be used."
+msgstr ""
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:4001
+msgid "Specify the host machine running RabbitMQ:"
+msgstr ""
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:4001
+msgid ""
+"Each buildd client needs to communicate with a single server running "
+"rabbitMQ from which it receives the details of the jobs which the client "
+"needs to attempt to build."
+msgstr ""
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:5001
+msgid "Specify the dput destination for packages to be uploaded:"
+msgstr ""
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:5001
+msgid ""
+"Each client has a dput config for a specific upload machine, specify that "
+"config name here."
+msgstr ""
+
+#. Type: string
+#. Description
+#: ../pybit-client.templates:5001
+msgid "This entry must not be empty."
+msgstr ""
+
+#. Type: note
+#. Description
+#: ../pybit-client.templates:6001
+msgid "Client id string cannot be empty!"
+msgstr ""
+
+#. Type: note
+#. Description
+#: ../pybit-client.templates:6001
+msgid ""
+"Any client with an empty clientid (or a clientid which matches an existing "
+"clientid) will fail to start."
+msgstr ""
+
+#. Type: note
+#. Description
+#: ../pybit-client.templates:7001
+msgid "RabbitMQ host is empty!"
+msgstr ""
+
+#. Type: note
+#. Description
+#: ../pybit-client.templates:7001
+msgid ""
+"Any client with a missing rabbitmq host will not receive any messages from "
+"the queue and will not build any packages."
+msgstr ""
+
+#. Type: note
+#. Description
+#: ../pybit-client.templates:7001
+msgid "Please edit /etc/pybit/client/client.conf after configuration."
+msgstr ""
+
+#. Type: note
+#. Description
+#: ../pybit-client.templates:8001
+msgid "dput destination cannot be empty!"
+msgstr ""
+
+#. Type: note
+#. Description
+#: ../pybit-client.templates:8001
+msgid ""
+"pybit-client is not intended to upload to unspecified dput destinations like "
+"ftp-master.debian.org and does not currently support GnuPG signed uploads."
+msgstr ""
View
@@ -0,0 +1,203 @@
+#!/usr/bin/perl -w
+
+use Debconf::Client::ConfModule qw(:all);
+
+version("2.0");
+capb("backup");
+
+# basic structure borrowed from /var/lib/dpkg/info/dwww.config
+
+my $cfgfile = '/etc/pybit/client/client.conf';
+my %cfg=();
+
+if ( -r "$cfgfile" ) {
+ # read any existing config file to avoid changing it
+ &ScanClientConfFile ( "$cfgfile" );
+ # set relevant values in debconf from any existing file
+ foreach my $cfgvar ('clientid', 'lvmsnapshot', 'rabbitmqhost', 'buildroot', 'dputdest', 'distribution') {
+ if (defined $cfg{$cfgvar}) {
+ set("pybit-client/$cfgvar", $cfg{$cfgvar});
+ fset("pybit-client/$cfgvar", 'seen', 'true');
+ }
+ }
+}
+
+my $state = 1;
+while ($state > 0 && $state < 3) {
+ if ($state == 1) {
+ beginblock();
+ input('high', 'pybit-client/clientid');
+ input('high', 'pybit-client/rabbitmqhost');
+ input('high', 'pybit-client/dputdest');
+ endblock();
+ @ret = go();
+
+ # error handling
+ my $id = scalar get('pybit-client/clientid');
+ chomp ($id) if defined ($id);
+ while (($ret[0] == 0) and (not defined $id or $id =~ m/^\s*$/)) {
+ fset('pybit-client/clientid', 'seen', 'false');
+ fset('pybit-client/missingid', 'seen', 'false');
+ beginblock();
+ input('high', 'pybit-client/missingid');
+ input('high', 'pybit-client/clientid');
+ endblock();
+ @ret = go();
+ $id = scalar get('pybit-client/clientid');
+ chomp ($id) if defined ($id);
+ }
+ set('pybit-client/clientid', $id);
+
+ my $host = scalar get('pybit-client/rabbitmqhost');
+ if (($ret[0] == 0) and (not defined $host or $host =~ m/^\s*$/)) {
+ fset('pybit-client/rabbitmqhost', 'seen', 'false');
+ fset('pybit-client/missinghost', 'seen', 'false');
+ beginblock();
+ input('high', 'pybit-client/missinghost');
+ endblock();
+ @ret = go();
+ chomp ($host) if (defined $host);
+ $host = scalar get('pybit-client/rabbitmqhost');
+ $host = "" if not defined ($host);
+ }
+ set('pybit-client/rabbitmqhost', $host);
+
+ my $dput = scalar get('pybit-client/dputdest');
+ while (($ret[0] == 0) and (not defined $dput or $dput =~ m/^\s*$/)) {
+ fset('pybit-client/dputdest', 'seen', 'false');
+ fset('pybit-client/defaultdput', 'seen', 'false');
+ beginblock();
+ input('high', 'pybit-client/defaultdput');
+ input('high', 'pybit-client/dputdest');
+ endblock();
+ @ret = go();
+ chomp ($dput) if (defined $dput);
+ $dput = scalar get('pybit-client/dputdest');
+ }
+ set('pybit-client/dputdest', $dput);
+ }
+ elsif ($state == 2) {
+ beginblock();
+ input('medium', 'pybit-client/lvmsnapshot');
+ input('medium', 'pybit-client/buildroot');
+ endblock();
+ @ret = go();
+
+ my $dir = scalar get('pybit-client/buildroot');
+ chomp ($dir) if (defined $dir);
+ if ($ret[0] == 0) {
+ if ($dir =~ m|^/$| or not defined $dir or $dir eq '') {
+ $dir = "/home/buildd/pybit";
+ }
+ mkdir_p ($dir);
+ }
+ set('pybit-client/buildroot', canondir($dir));
+ }
+ if ( ($ret[0] == 30) ) {
+ $state--; # go back
+ }
+ else {
+ $state++; # go forward
+ }
+}
+
+# SUBROUTINES
+
+# Subroutine to scan client configuration file
+# Configfile to parse is the argument to the subroutine
+sub ScanClientConfFile {
+ if ( ! -r "$_[0]" ) { return; };
+ open(CONFFILE,"<$_[0]") || die "Could not open $_[0]";
+ # set defaults
+ my $host = `dpkg-architecture -qDEB_HOST_ARCH 2>/dev/null`;
+ chomp ($host);
+ $cfg{'hostarch'} = $host;
+ $cfg{'rabbitport'} = 5672;
+ $cfg{'rabbituser'} = "guest";
+ $cfg{'rabbitpword'} = "guest";
+ $cfg{'rabbitvhost'} = "/";
+ $cfg{'dputopt'} = "-U";
+ my $distro = `dpkg-vendor --query vendor`;
+ chomp ($distro);
+ $cfg{'distribution'} = $distro;
+ $cfg{'pkgformat'} = "deb";
+
+ while (<CONFFILE>) {
+ # debconf values - keep the tag names the same as the debconf names
+ # Check for clientid
+ if( s/^\s*"clientid": (.*),?/$1/) {
+ chomp($cfg{'clientid'}=$_) if /\w/;
+ }
+ # Check for use_lvm
+ elsif( s/^\s*"use_lvm": (.*),?/$1/) {
+ chomp($cfg{'lvmsnapshot'}=$_) if /\w/;
+ }
+ # Check for buildroot
+ elsif( s/^\s*"buildroot": (.*),?/$1/) {
+ chomp($cfg{'buildroot'}=$_) if /\w/;
+ }
+ # Check for host
+ elsif( s/^\s*"host": (.*),?/$1/) {
+ chomp($cfg{'rabbitmqhost'}=$_) if /\w/;
+ }
+ # Check for dput_dest
+ elsif( s/^\s*"dput_dest": (.*),?/$1/) {
+ chomp($cfg{'dputdest'}=$_) if /\w/;
+ }
+ # defaults and manual values
+ # Check for host_arch
+ elsif( s/^\s*"host_arch": (.*),?/$1/) {
+ chomp($cfg{'hostarch'}=$_) if /\w/;
+ }
+ # Check for distribution
+ elsif( s/^\s*"distribution": (.*),?/$1/) {
+ chomp($cfg{'distribution'}=$_) if /\w/;
+ }
+ # Check for pkg_format
+ elsif( s/^\s*"pkg_format": (.*),?/$1/) {
+ chomp($cfg{'pkgformat'}=$_) if /\w/;
+ }
+ # Check for port
+ elsif( s/^\s*"port": (.*),?/$1/) {
+ chomp($cfg{'rabbitport'}=$_) if /\w/;
+ }
+ # Check for userid
+ elsif( s/^\s*"userid": (.*),?/$1/) {
+ chomp($cfg{'rabbituser'}=$_) if /\w/;
+ }
+ # Check for rabbitvhost
+ elsif( s/^\s*"vhost": (.*),?/$1/) {
+ chomp($cfg{'rabbitvhost'}=$_) if /\w/;
+ }
+ # Check for dput
+ elsif( s/^\s*"dput": (.*),?/$1/) {
+ chomp($cfg{'dputopt'}=$_) if /\w/;
+ }
+ }
+ foreach my $key (keys %cfg) {
+ my $val = $cfg{$key};
+ $val =~ s/"//g;
+ $val =~ s/'//g;
+ $val =~ s/,//g;
+ $cfg{$key} = $val;
+ }
+ close CONFFILE;
+}
+
+sub canondir {
+ my $dir = $_[0];
+ $dir =~ s|/+|/|g;
+ $dir =~ s|/$||;
+ return $dir;
+}
+
+# Same as `mkdir -p'
+sub mkdir_p {
+ my $dir = shift;
+ return if (-d $dir);
+ my $p = "";
+ foreach $f (split "/", $dir) {
+ $p .= $f . "/";
+ (-d $p) or (mkdir $p, 0755) or die "Can't create directory $p: $!\n";
+ }
+}
@@ -1,4 +1,4 @@
-configs/client/client.conf ./etc/pybit/client/
+configs/client/client.conf ./usr/share/pybitclient/
configs/client/dput.cf ./etc/pybit/client/
pybitclient/sbuild-cross.sh ./usr/share/pybitclient/
pybitclient/sbuild-orig.sh ./usr/share/pybitclient/
Oops, something went wrong.

0 comments on commit 640ecaf

Please sign in to comment.