buildpackage: implement --[no-]hooks option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 22 Apr 2013 07:38:54 +0000 (10:38 +0300)
committerGuido Günther <agx@sigxcpu.org>
Fri, 26 Apr 2013 20:08:14 +0000 (22:08 +0200)
For enabling/disabling all hooks. This option does not affect the
builder command, though.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
docs/manpages/git-buildpackage.sgml
gbp/config.py
gbp/scripts/buildpackage.py

index d528f3d..be3676f 100644 (file)
@@ -41,6 +41,7 @@
       <arg><option>--git-postbuild=</option><replaceable>command</replaceable></arg>
       <arg><option>--git-postexport=</option><replaceable>command</replaceable></arg>
       <arg><option>--git-prebuild=</option><replaceable>command</replaceable></arg>
+      <arg><option>--git-[no-]hooks=</option></arg>
       <arg><option>--git-debian-tag=</option><replaceable>tag-format</replaceable></arg>
       <arg><option>--git-upstream-tag=</option><replaceable>tag-format</replaceable></arg>
       <arg><option>--git-force-create</option></arg>
         </listitem>
       </varlistentry>
       <varlistentry>
+        <term><option>--git-[no-]hooks</option></term>
+        <listitem>
+      <para>Enable running all (cleaner, postexport, prebuild, postbuild,
+      and posttag) hooks. Note: the <option>--git-builder</option> command is
+      not affected by this option.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
         <term><option>--git-debian-tag=</option><replaceable>tag-format</replaceable>
         </term>
         <listitem>
index ec75765..c27cf5a 100644 (file)
@@ -83,6 +83,7 @@ class GbpOptionParser(OptionParser):
                  'prebuild'        : '',
                  'postexport'      : '',
                  'postimport'      : '',
+                 'hooks'           : 'True',
                  'debian-tag'      : 'debian/%(version)s',
                  'upstream-tag'    : 'upstream/%(version)s',
                  'import-msg'      : 'Imported Upstream version %(version)s',
@@ -241,6 +242,8 @@ class GbpOptionParser(OptionParser):
              'postimport':
                   ("hook run after a successful import, "
                    "default is '%(postimport)s'"),
+             'hooks':
+                  ("Enable running all hooks, default is %(hooks)s"),
              'time-machine':
                   ("don't try head commit only to apply the patch queue "
                    "but look TIME_MACHINE commits back, "
index 9c02e3e..989801f 100755 (executable)
@@ -342,6 +342,14 @@ def setup_pbuilder(options):
             os.environ['GIT_PBUILDER_OPTIONS'] = options.pbuilder_options
 
 
+def disable_hooks(options):
+    """Disable all hooks (except for builder)"""
+    for hook in ['cleaner', 'postexport', 'prebuild', 'postbuild', 'posttag']:
+        if getattr(options, hook):
+            gbp.log.info("Disabling '%s' hook" % hook)
+            setattr(options, hook, '')
+
+
 def parse_args(argv, prefix):
     args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == 0 ]
     dpkg_args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == -1 ]
@@ -421,6 +429,7 @@ def parse_args(argv, prefix):
     cmd_group.add_config_file_option(option_name="arch", dest="pbuilder_arch")
     cmd_group.add_boolean_config_file_option(option_name = "pbuilder-autoconf", dest="pbuilder_autoconf")
     cmd_group.add_config_file_option(option_name="pbuilder-options", dest="pbuilder_options")
+    cmd_group.add_boolean_config_file_option(option_name="hooks", dest="hooks")
     export_group.add_config_file_option(option_name="export-dir", dest="export_dir", type="path",
                       help="before building the package export the source into EXPORT_DIR, default is '%(export-dir)s'")
     export_group.add_config_file_option("export", dest="export",
@@ -432,6 +441,8 @@ def parse_args(argv, prefix):
     options, args = parser.parse_args(args)
 
     gbp.log.setup(options.color, options.verbose, options.color_scheme)
+    if not options.hooks:
+        disable_hooks(options)
     if options.retag:
         if not options.tag and not options.tag_only:
             gbp.log.err("'--%sretag' needs either '--%stag' or '--%stag-only'" % (prefix, prefix, prefix))