"""Create/Update Debian build Jenkins jobs based on Gitlab webhooks
The behavior of the gitlab_jenkins_trigger can be configured by placing a .buildchain
-configuration file into the git repository. See get_config_parser() for the default
-values of the .buildchain configuration.
-
-Example .buildchain file:
-================================================================================
-# This is a sample .buildchain configuration file
-# The section is [debian]
-
-[debian]
-
-# enable or disable Debian package builds (default: auto)
-# In auto mode, the debian build is enabled if debian/changelog exists.
-# Otherwise it will be disabled.
-enabled = True
-
-# distros can be set to a list of space-separated distributions or to 'auto'.
-# In 'auto' mode, debian/changelog will be parsed and the distros
-# from there will be used. Multiple distributions are separated by spaces
-# in debian/changelog. If distributions is set to 'UNRELEASED', the previous
-# changelog entries are parsed recursively.
-# Supported distributions are: squeeze wheezy jessie trusty utopic
-distros = auto
-
-# Email Maintainer (specified in debian/control) when a build fails
-email_maintainer = True
-
-# Email Uploaders (specified in debian/control) when a build fails
-email_uploaders = True
-
-# Additional space separated list of email recipients for build failures
-email_recipients = dcops@profitbricks.com benjamin.drung@profitbricks.com
-================================================================================
-
+configuration file into the git repository.
"""
from __future__ import print_function
import sys
import xml.etree
-try:
- if sys.version_info[:2] >= (3, 2):
- from configparser import ConfigParser
- else:
- from configparser import SafeConfigParser as ConfigParser
-except ImportError:
- from ConfigParser import SafeConfigParser as ConfigParser
-
import debian.changelog
import debian.deb822
import gitlab
import jenkins
+from lib.buildchainconfig import BuildchainConfig
+
_LOG_LEVEL = logging.INFO
_LOG_FORMAT = '%(asctime)s %(name)s [%(process)d] %(levelname)s: %(message)s'
FALLBACK_DISTRO = "squeeze"
-class BuildchainConfig(ConfigParser):
- """Enhanced ConfigParser object
-
- This object is initialised with default values and the configuration is
- read from the optional buildchain_file parameter.
- """
-
- def __init__(self, buildchain_file=None): # pylint: disable=W0231
- ConfigParser.__init__(self)
- self._set_defaults()
- if buildchain_file is not None:
- self.readfp(buildchain_file)
-
- def _set_defaults(self):
- """Create a ConfigParser object and set the default values"""
- self.add_section('debian')
- self.set('debian', 'enabled', 'auto')
- self.set('debian', 'distros', 'auto')
- self.set('debian', 'email_maintainer', 'True')
- self.set('debian', 'email_uploaders', 'True')
- self.set('debian', 'email_recipients', '')
-
-
class JenkinsJob(object):
def __init__(self, jenkins_client, job_name, config_xml, logger):
self.jenkins_client = jenkins_client
--- /dev/null
+# Copyright (C) 2014, ProfitBricks GmbH
+# Authors: Benjamin Drung <benjamin.drung@profitbricks.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+"""
+See BuildchainConfig._set_defaults() for the default values of the .buildchain configuration.
+
+Example .buildchain file:
+================================================================================
+# This is a sample .buildchain configuration file
+# The section is [debian]
+
+[debian]
+
+# enable or disable Debian package builds (default: auto)
+# In auto mode, the debian build is enabled if debian/changelog exists.
+# Otherwise it will be disabled.
+enabled = True
+
+# distros can be set to a list of space-separated distributions or to 'auto'.
+# In 'auto' mode, debian/changelog will be parsed and the distros
+# from there will be used. Multiple distributions are separated by spaces
+# in debian/changelog. If distributions is set to 'UNRELEASED', the previous
+# changelog entries are parsed recursively.
+# Supported distributions are: squeeze wheezy jessie trusty utopic
+distros = auto
+
+# Email Maintainer (specified in debian/control) when a build fails
+email_maintainer = True
+
+# Email Uploaders (specified in debian/control) when a build fails
+email_uploaders = True
+
+# Additional space separated list of email recipients for build failures
+email_recipients = dcops@profitbricks.com benjamin.drung@profitbricks.com
+================================================================================
+"""
+
+import sys
+
+try:
+ if sys.version_info[:2] >= (3, 2):
+ from configparser import ConfigParser
+ else:
+ from configparser import SafeConfigParser as ConfigParser
+except ImportError:
+ from ConfigParser import SafeConfigParser as ConfigParser
+
+
+class BuildchainConfig(ConfigParser):
+ """Enhanced ConfigParser object
+
+ This object is initialised with default values and the configuration is
+ read from the optional buildchain_file parameter.
+ """
+
+ def __init__(self, buildchain_file=None): # pylint: disable=W0231
+ ConfigParser.__init__(self)
+ self._set_defaults()
+ if buildchain_file is not None:
+ self.readfp(buildchain_file)
+
+ def _set_defaults(self):
+ """Create a ConfigParser object and set the default values"""
+ self.add_section('debian')
+ self.set('debian', 'enabled', 'auto')
+ self.set('debian', 'distros', 'auto')
+ self.set('debian', 'email_maintainer', 'True')
+ self.set('debian', 'email_uploaders', 'True')
+ self.set('debian', 'email_recipients', '')