1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#! /usr/bin/env python3
#
# Script to create debian/control for package boost-defaults
from debian.deb822 import Deb822
import re, sys
gBoostVersion = None
def versionFromSourceName(sourcename):
m = re.match("^boost(\d+)\.(\d+)(\.\d+)?$", sourcename)
if not m: raise RuntimeError("source name does not match expected pattern: " + sourcename)
minor = ".0"
if m.lastindex > 2: minor = m.group(3)
return ".".join(m.group(1,2)) + minor
class BoostVersion:
def __init__(self, version):
(self.Major,self.Minor,self.Revision) = version.split('.')
self.PackageVersion = self.Major + '.' + self.Minor
self.SharedObjectVersion = version
def versionedSubPackage(self, subpkg):
'''Given a subpackage name (subpkg) such as "dev",
returns the versioned package name, libboost@Major.Minor@-@subpkg@.'''
return 'libboost' + self.PackageVersion + '-' + subpkg
def containsPackageVersion(self, string):
'''Return true if 'string' contains the Package version string.'''
return re.search(self.PackageVersion, string) is not None
def containsSharedObjectVersion(self, string):
'''Return true if 'string' contains the Shared Object version string.'''
return re.search(self.SharedObjectVersion, string) is not None
def stripVersion(self, string):
'''Remove PackageVersion or SharedObjectVersion if contained in 'string'.'''
return self.replaceVersion(string,'')
def replaceVersion(self, string, replacement):
'''Replace either PackageVersion or SharedObjectVersion if contained in 'string',
with 'replacement'.'''
string = re.sub(self.SharedObjectVersion, replacement, string)
string = re.sub(self.PackageVersion, replacement, string)
return string
def appendFirstLine(string, suffix):
'''Given a multiline string, return a new string
with suffix appended to the first line.'''
lines = string.split('\n')
lines[0] += suffix
return '\n'.join(lines)
def deleteKey(paragraph, key):
if key in paragraph:
del paragraph[key]
def processSourceParagraph(p):
p['Source'] = 'boost-defaults'
p['Vcs-Browser'] = 'https://salsa.debian.org/debian/boost-defaults'
p['Vcs-Git'] = 'https://salsa.debian.org/debian/boost-defaults.git'
p['Build-Depends'] = 'debhelper (>= 9), ' + \
gBoostVersion.versionedSubPackage('dev') + ' (>= ' + gBoostVersion.SharedObjectVersion + ')'
deleteKey(p, 'Build-Conflicts')
deleteKey(p, 'Build-Depends-Indep')
def genericPackageName(pkgName):
'''Given an input package name of the form x1-x2-...-yVERSION-z,
return an unversioned variant of form x1-x2-...-y-z.'''
nameComponents = pkgName.split('-')
lastComp = nameComponents[-1]
if not lastComp in ['dbg','dev','doc']:
return None
return '-'.join(map(gBoostVersion.stripVersion, nameComponents))
def dependsLibDev(p, versionedName):
'''Set package Depends for a library -dev package.'''
return '${misc:Depends}, ' + versionedName
def dependsDbg(p, versionedName):
'''Set package Depends for libboost-dbg.'''
return 'libboost-dev (= ${binary:Version}), ' + dependsLibDev(p, versionedName)
def dependsAllDev(p, versionedName):
'''Set package Depends for libboost-all-dev.'''
return gBoostVersion.stripVersion(p['Depends'])
def processPackageParagraph(p):
versionedName = p['Package']
genericName = genericPackageName(versionedName)
if genericName is None:
return False
p['Package'] = genericName
if genericName == 'libboost-dbg':
depends = dependsDbg(p, versionedName)
elif genericName == 'libboost-all-dev':
depends = dependsAllDev(p, versionedName)
else:
depends = dependsLibDev(p, versionedName)
p['Depends'] = depends
if genericName == 'libboost-dev':
p['Suggests'] = 'libboost-doc'
else:
deleteKey(p, 'Suggests')
deleteKey(p, 'Recommends')
deleteKey(p, 'Conflicts')
deleteKey(p, 'Replaces')
p['Description'] = appendFirstLine(p['Description'], ' (default version)') \
+ '''
.
This package is a dependency package, which depends on Debian\'s default
Boost version (currently ''' + gBoostVersion.PackageVersion + ').'
return True
def printParagraph(p):
for key in p.keys():
print("%s: %s" % (key, p[key]))
def processControl(controlfile):
firstParagraph = True
for paragraph in Deb822.iter_paragraphs(open(controlfile)):
if firstParagraph:
global gBoostVersion
gBoostVersion = BoostVersion(versionFromSourceName(paragraph['Source']))
processSourceParagraph(paragraph)
printParagraph(paragraph)
firstParagraph = False
else:
if processPackageParagraph(paragraph):
print()
printParagraph(paragraph)
controlfile = 'control'
if len(sys.argv) > 1:
controlfile = sys.argv[1]
processControl(controlfile)
|