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
|
#!/usr/bin/env python3
import os
import argparse
import re
import shutil
import subprocess
import copy
def versionFromCMakeLists(filePath):
if not os.path.exists(filePath):
raise NameError('File path not found');
textFile = open(filePath, 'rt');
contents = textFile.read(2000);
textFile.close();
versionLines = re.findall('set\s*\(VERSION.*\)', contents, re.MULTILINE);
# print(versionLines);
if not len(versionLines):
raise NameError('Failed to find VERSION statement');
versionLine = versionLines[0];
pattern = re.compile('set\(VERSION\s*([0-9.]+)\).*$');
cmakeVersionNumber = "";
match = pattern.match(versionLine);
if match is not None:
cmakeVersionNumber = match[1];
else:
raise NameError('Failed to extract VERSION number');
# print("Version number from CMakeLists.txt: " + cmakeVersionNumber);
return(cmakeVersionNumber);
def upstreamVersionFromDebianChangelog(projectName, filePath):
if not os.path.exists(filePath):
raise NameError('File path not found');
textFile = open(filePath, 'rt');
contents = textFile.read(100);
textFile.close();
patternString = "^\s*" + projectName + "\s*\(.*$";
# print("patternString: " + patternString);
versionLines = re.findall(patternString, contents, re.MULTILINE);
# print(versionLines);
if not len(versionLines):
raise NameError('Failed to find source package version statement');
# Only the first occurrence is the latest.
versionLine = versionLines[0];
# print("Version line: " + versionLine);
pattern = re.compile("^\s*" + projectName + "\s*\((.+)\).*$");
upstreamDebianVersionNumber = "";
match = pattern.match(versionLine);
if match is not None:
upstreamDebianVersionNumber = match[1];
else:
raise NameError('Failed to extract upstream-debian package version');
# print("Upstream-debian Version number from debian/changelog: " + upstreamDebianVersionNumber);
# The string is like 4.1.0-1, but we want to separate the -1 and thus get
# the upstream version number and the debian package version number an
# return them into a tuple.
pattern = re.compile("(^.*)-([0-9]{1,2})$");
match = pattern.match(upstreamDebianVersionNumber);
if match is not None:
# print(match[0]);
upstreamVersionNumber = match[1];
# print("upstreamVersionNumber: " + upstreamVersionNumber);
debianVersionNumber = match[2];
# print("debianVersionNumber: " + debianVersionNumber);
return (upstreamVersionNumber, debianVersionNumber);
else:
raise NameError('Failed to extract the debian package version number');
|