Add support for providing alternatives
[auto-debuild.git] / auto_debuild.py
index c7a762854abff687b89a5a24a8b1a28ed45411df..8441f079aeae1fe7c083ad2ea0935f2e75631e32 100755 (executable)
@@ -109,7 +109,7 @@ def createDebianFiles(config):
        if os.path.exists('debian'): raise Exception('debian folder already exists?')
        os.mkdir('debian')
        os.mkdir('debian/source')
-       if not os.path.exists(debDir): os.mkdir(debDir)
+       if not os.path.exists(debDir): os.makedirs(debDir)
        # source format file
        with open('debian/source/format', 'w') as f:
                print >>f, "3.0 (native)"
@@ -159,6 +159,31 @@ def createDebianFiles(config):
                        if line.startswith('/'): # a file from within the package, not from the source tree
                                line = 'debian/'+binaryName+line
                        print >>f, line
+       # maintainer scripts for alternatives
+       if 'alternatives' in config:
+               with open('debian/'+binaryName+'.postinst', 'w') as f:
+                       print >>f, "#!/bin/sh"
+                       print >>f, "set -e"
+                       print >>f, 'if [ "$1" = "configure" ]; then'
+                       for alternative in config['alternatives']:
+                               print >>f, safeCall('update-alternatives', '--install', alternative['link'], alternative['name'], alternative['target'],
+                                       str(alternative['priority']))
+                       print >>f, 'fi'
+                       print >>f, ''
+                       print >>f, '#DEBHELPER#'
+                       print >>f, ''
+                       print >>f, 'exit 0'
+               with open('debian/'+binaryName+'.prerm', 'w') as f:
+                       print >>f, "#!/bin/sh"
+                       print >>f, "set -e"
+                       print >>f, 'if [ "$1" = "remove" ]; then'
+                       for alternative in config['alternatives']:
+                               print >>f, safeCall('update-alternatives', '--remove', alternative['name'], alternative['target'])
+                       print >>f, 'fi'
+                       print >>f, ''
+                       print >>f, '#DEBHELPER#'
+                       print >>f, ''
+                       print >>f, 'exit 0'
        # rules file: build system specific
        with open('debian/rules', 'w') as f:
                # get rule file for build system: may only touch auto_config and auto_clean rules and the dh options