debian/update-helper-*: packaging update helpers
authorChristian Ehrhardt <christian.ehrhardt@canonical.com>
Tue, 16 May 2017 12:59:59 +0000 (14:59 +0200)
committerChristian Ehrhardt <christian.ehrhardt@canonical.com>
Wed, 17 May 2017 13:05:06 +0000 (15:05 +0200)
* Add update-helper-control.py script to easen rename packages for new
  DPDK versions.
  - This script from libboost helps convert all package names
    from the old ABI name to the new one.
  - thanks to Jan Blunck for the conversion from boost!
  - the script was later updated to be python3 ready and fixing the script
    for all warnings/errors (but not all info) thrown by python code checkers.
* Add update-helper-symbols.sh script to easen modifying the package and
  soname references in symbols files for new DPDK versions.
  - We still want to check "real" symbol delta on any update, but to make
    dpkg-gensymbols find the new libs the symbols files need to be updated.

Change-Id: I73a454b8fe628c05569e689f5c14f3b73d2ec4cc
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
debian/update-helper-control.py [new file with mode: 0755]
debian/update-helper-symbols.sh [new file with mode: 0755]

diff --git a/debian/update-helper-control.py b/debian/update-helper-control.py
new file mode 100755 (executable)
index 0000000..fe974ab
--- /dev/null
@@ -0,0 +1,97 @@
+#! /usr/bin/env python3
+#
+# based on https://anonscm.debian.org/viewvc/pkg-boost/boost/
+#    trunk/debian/update-control.py
+#
+
+import re
+import sys
+
+from deb822 import Deb822
+
+gOldVersion = None
+gNewVersion = None
+
+
+class DpdkVersion:
+    def __init__(self, version):
+        (self.Major, self.Minor) = version.split('.')
+        self.PackageVersion = self.Major + '.' + self.Minor
+
+
+def replaceVersion(string, ver1, ver2):
+    '''Search 'string' for a DpdkVersion ver1.  If
+    SharedObjectVersion or PackageVersion of ver1 is found, replace by
+    corresponding ver2 version string.  Return the updated string.'''
+    string = re.sub(ver1.PackageVersion, ver2.PackageVersion, string)
+    return string
+
+
+def updateVersionedValue(paragraph, key):
+    if key not in paragraph:
+        return
+    oldValue = paragraph[key]
+    paragraph[key] = replaceVersion(paragraph[key], gOldVersion, gNewVersion)
+    return (oldValue, paragraph[key])
+
+
+def conflictsWithPrevious(paragraph):
+    if 'Conflicts' not in paragraph:
+        return False
+    nameRe = re.sub('\d', '\\d', paragraph['Package'])
+    return re.search(nameRe, paragraph['Conflicts']) is not None
+
+
+def updateConflicts(paragraph, oldPkgName):
+    newPkgName = paragraph['Package']
+    needsConflict = ((newPkgName.endswith("-dev")
+                      and not newPkgName.endswith("-all-dev"))
+                     or conflictsWithPrevious(paragraph))
+    if not needsConflict:
+        return
+    if 'Conflicts' in paragraph:
+        if paragraph['Conflicts'].find(oldPkgName) == -1:
+            paragraph['Conflicts'] += ', ' + oldPkgName
+    else:
+        paragraph['Conflicts'] = oldPkgName
+
+
+def processSourceParagraph(p):
+    updateVersionedValue(p, 'Source')
+
+
+def processPackageParagraph(p):
+    (oldPkgName, newPkgName) = updateVersionedValue(p, 'Package')
+    updateVersionedValue(p, 'Depends')
+    updateVersionedValue(p, 'Recommends')
+    updateVersionedValue(p, 'Suggests')
+    updateConflicts(p, oldPkgName)
+
+
+def printParagraph(p):
+    for key in p.keys():
+        print("%s: %s" % (key, p[key]))
+
+
+def processControl():
+    firstParagraph = True
+    for paragraph in Deb822.iter_paragraphs(open('control')):
+        if firstParagraph:
+            processSourceParagraph(paragraph)
+            printParagraph(paragraph)
+            firstParagraph = False
+        else:
+            processPackageParagraph(paragraph)
+            print
+            printParagraph(paragraph)
+
+
+if len(sys.argv) < 3:
+    print("Usage: cd debian/; %s <old version> <new version>"
+          " > control_new" % sys.argv[0])
+    exit(1)
+
+gOldVersion = DpdkVersion(sys.argv[1])
+gNewVersion = DpdkVersion(sys.argv[2])
+processControl()
+print
diff --git a/debian/update-helper-symbols.sh b/debian/update-helper-symbols.sh
new file mode 100755 (executable)
index 0000000..c6d0f08
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+if [ "$#" -lt 2 ]; then
+    echo "Need at least two arguments"
+    echo "Usage: $0 <newversion> <symbol-files>..."
+fi
+
+newv=${1}
+
+for symbolf in ${@:2}
+do
+    echo "modifying ${symbolf}"
+    perl -pi -e "s/\.so\.[0-9.]*/.so.${newv}.0/g" "${symbolf}"
+    perl -pi -e "s/[0-9.]* #MINVER#/${newv} #MINVER#/g" "${symbolf}"
+done