summaryrefslogtreecommitdiff
path: root/automation/release
diff options
context:
space:
mode:
authorJ.C. Jones <jjones@mozilla.com>2019-12-04 17:21:26 +0000
committerJ.C. Jones <jjones@mozilla.com>2019-12-04 17:21:26 +0000
commit52870835214aae3b95eab07053ab9ba0df86507e (patch)
tree9d721a522a3f6deb7d4272eedd90c14a3172ebb5 /automation/release
parentb2e068a1bae330f40c33f105156230ba98221602 (diff)
downloadnss-hg-52870835214aae3b95eab07053ab9ba0df86507e.tar.gz
Bug 1535787 - flake8 style updates to nss-release-helper.py r=kjacobs
Depends on D23757 Differential Revision: https://phabricator.services.mozilla.com/D55746
Diffstat (limited to 'automation/release')
-rwxr-xr-xautomation/release/nss-release-helper.py109
1 files changed, 67 insertions, 42 deletions
diff --git a/automation/release/nss-release-helper.py b/automation/release/nss-release-helper.py
index 76f7bae3d..e7d5b0ca0 100755
--- a/automation/release/nss-release-helper.py
+++ b/automation/release/nss-release-helper.py
@@ -5,9 +5,7 @@
import os
import sys
-import datetime
import shutil
-import glob
import re
import tempfile
from optparse import OptionParser
@@ -34,31 +32,26 @@ abi_report_files = ['automation/abi-check/expected-report-libfreebl3.so.txt',
'automation/abi-check/expected-report-libsoftokn3.so.txt',
'automation/abi-check/expected-report-libssl3.so.txt']
+
def check_call_noisy(cmd, *args, **kwargs):
- print "Executing command:", cmd
+ print("Executing command: {}".format(cmd))
check_call(cmd, *args, **kwargs)
-o = OptionParser(usage="client.py [options] remove_beta | set_beta | print_library_versions | print_root_ca_version | set_root_ca_version | set_version_to_minor_release | set_version_to_patch_release | set_release_candidate_number | set_4_digit_release_number | create_nss_release_archive")
-
-try:
- options, args = o.parse_args()
- action = args[0]
-except IndexError:
- o.print_help()
- sys.exit(2)
def exit_with_failure(what):
- print "failure: ", what
+ print("failure: {}".format(what))
sys.exit(2)
+
def check_files_exist():
if (not os.path.exists(nssutil_h) or not os.path.exists(softkver_h)
- or not os.path.exists(nss_h) or not os.path.exists(nssckbi_h)):
+ or not os.path.exists(nss_h) or not os.path.exists(nssckbi_h)):
exit_with_failure("cannot find expected header files, must run from inside NSS hg directory")
+
def inplace_replace(cmds=[], filename=""):
for c in cmds:
- if not "regex" in c or not "repl" in c:
+ if "regex" not in c or "repl" not in c:
raise Exception("Expecting a list of dicts with 'regex' and 'repl' as members")
c["matcher"] = re.compile(c["regex"])
@@ -72,15 +65,16 @@ def inplace_replace(cmds=[], filename=""):
shutil.copystat(filename, tmp_file.name)
shutil.move(tmp_file.name, filename)
+
def toggle_beta_status(is_beta):
check_files_exist()
if (is_beta):
- print "adding Beta status to version numbers"
+ print("adding Beta status to version numbers")
inplace_replace(filename=nssutil_h, cmds=[
{
"regex": r'^(#define *NSSUTIL_VERSION *\"[0-9.]+)\" *$',
"repl": r'\g<1> Beta"'
- },{
+ }, {
"regex": r'^(#define *NSSUTIL_BETA *)PR_FALSE *$',
"repl": r'\g<1>PR_TRUE'
}])
@@ -88,7 +82,7 @@ def toggle_beta_status(is_beta):
{
"regex": r'^(#define *SOFTOKEN_VERSION *\"[0-9.]+\" *SOFTOKEN_ECC_STRING) *$',
"repl": r'\g<1> " Beta"'
- },{
+ }, {
"regex": r'^(#define *SOFTOKEN_BETA *)PR_FALSE *$',
"repl": r'\g<1>PR_TRUE'
}])
@@ -96,17 +90,17 @@ def toggle_beta_status(is_beta):
{
"regex": r'^(#define *NSS_VERSION *\"[0-9.]+\" *_NSS_CUSTOMIZED) *$',
"repl": r'\g<1> " Beta"'
- },{
+ }, {
"regex": r'^(#define *NSS_BETA *)PR_FALSE *$',
"repl": r'\g<1>PR_TRUE'
}])
else:
- print "removing Beta status from version numbers"
+ print("removing Beta status from version numbers")
inplace_replace(filename=nssutil_h, cmds=[
{
"regex": r'^(#define *NSSUTIL_VERSION *\"[0-9.]+) *Beta\" *$',
"repl": r'\g<1>"'
- },{
+ }, {
"regex": r'^(#define *NSSUTIL_BETA *)PR_TRUE *$',
"repl": r'\g<1>PR_FALSE'
}])
@@ -114,7 +108,7 @@ def toggle_beta_status(is_beta):
{
"regex": r'^(#define *SOFTOKEN_VERSION *\"[0-9.]+\" *SOFTOKEN_ECC_STRING) *\" *Beta\" *$',
"repl": r'\g<1>'
- },{
+ }, {
"regex": r'^(#define *SOFTOKEN_BETA *)PR_TRUE *$',
"repl": r'\g<1>PR_FALSE'
}])
@@ -122,47 +116,53 @@ def toggle_beta_status(is_beta):
{
"regex": r'^(#define *NSS_VERSION *\"[0-9.]+\" *_NSS_CUSTOMIZED) *\" *Beta\" *$',
"repl": r'\g<1>'
- },{
+ }, {
"regex": r'^(#define *NSS_BETA *)PR_TRUE *$',
"repl": r'\g<1>PR_FALSE'
}])
- print "please run 'hg stat' and 'hg diff' to verify the files have been verified correctly"
+ print("please run 'hg stat' and 'hg diff' to verify the files have been verified correctly")
+
def print_beta_versions():
check_call_noisy(["egrep", "#define *NSSUTIL_VERSION|#define *NSSUTIL_BETA", nssutil_h])
check_call_noisy(["egrep", "#define *SOFTOKEN_VERSION|#define *SOFTOKEN_BETA", softkver_h])
check_call_noisy(["egrep", "#define *NSS_VERSION|#define *NSS_BETA", nss_h])
+
def remove_beta_status():
- print "--- removing beta flags. Existing versions were:"
+ print("--- removing beta flags. Existing versions were:")
print_beta_versions()
toggle_beta_status(False)
- print "--- finished modifications, new versions are:"
+ print("--- finished modifications, new versions are:")
print_beta_versions()
+
def set_beta_status():
- print "--- adding beta flags. Existing versions were:"
+ print("--- adding beta flags. Existing versions were:")
print_beta_versions()
toggle_beta_status(True)
- print "--- finished modifications, new versions are:"
+ print("--- finished modifications, new versions are:")
print_beta_versions()
+
def print_library_versions():
check_files_exist()
check_call_noisy(["egrep", "#define *NSSUTIL_VERSION|#define NSSUTIL_VMAJOR|#define *NSSUTIL_VMINOR|#define *NSSUTIL_VPATCH|#define *NSSUTIL_VBUILD|#define *NSSUTIL_BETA", nssutil_h])
check_call_noisy(["egrep", "#define *SOFTOKEN_VERSION|#define SOFTOKEN_VMAJOR|#define *SOFTOKEN_VMINOR|#define *SOFTOKEN_VPATCH|#define *SOFTOKEN_VBUILD|#define *SOFTOKEN_BETA", softkver_h])
check_call_noisy(["egrep", "#define *NSS_VERSION|#define NSS_VMAJOR|#define *NSS_VMINOR|#define *NSS_VPATCH|#define *NSS_VBUILD|#define *NSS_BETA", nss_h])
+
def print_root_ca_version():
check_files_exist()
check_call_noisy(["grep", "define *NSS_BUILTINS_LIBRARY_VERSION", nssckbi_h])
def ensure_arguments_after_action(how_many, usage):
- if (len(sys.argv) != (2+how_many)):
+ if (len(sys.argv) != (2 + how_many)):
exit_with_failure("incorrect number of arguments, expected parameters are:\n" + usage)
+
def set_major_versions(major):
for name, file in [["NSSUTIL_VMAJOR", nssutil_h],
["SOFTOKEN_VMAJOR", softkver_h],
@@ -172,6 +172,7 @@ def set_major_versions(major):
"repl": r'\g<1>{}'.format(major),
}])
+
def set_minor_versions(minor):
for name, file in [["NSSUTIL_VMINOR", nssutil_h],
["SOFTOKEN_VMINOR", softkver_h],
@@ -181,6 +182,7 @@ def set_minor_versions(minor):
"repl": r'\g<1>{}'.format(minor),
}])
+
def set_patch_versions(patch):
for name, file in [["NSSUTIL_VPATCH", nssutil_h],
["SOFTOKEN_VPATCH", softkver_h],
@@ -190,6 +192,7 @@ def set_patch_versions(patch):
"repl": r'\g<1>{}'.format(patch),
}])
+
def set_build_versions(build):
for name, file in [["NSSUTIL_VBUILD", nssutil_h],
["SOFTOKEN_VBUILD", softkver_h],
@@ -199,6 +202,7 @@ def set_build_versions(build):
"repl": r'\g<1>{}'.format(build),
}])
+
def set_full_lib_versions(version):
for name, file in [["NSSUTIL_VERSION", nssutil_h],
["SOFTOKEN_VERSION", softkver_h],
@@ -208,6 +212,7 @@ def set_full_lib_versions(version):
"repl": r'\g<1>{}\g<3>'.format(version),
}])
+
def set_root_ca_version():
ensure_arguments_after_action(2, "major_version minor_version")
major = args[1].strip()
@@ -218,29 +223,30 @@ def set_root_ca_version():
{
"regex": r'^(#define *NSS_BUILTINS_LIBRARY_VERSION *\").*$',
"repl": r'\g<1>{}"'.format(version)
- },{
+ }, {
"regex": r'^(#define *NSS_BUILTINS_LIBRARY_VERSION_MAJOR ?).*$',
"repl": r'\g<1>{}'.format(major)
- },{
+ }, {
"regex": r'^(#define *NSS_BUILTINS_LIBRARY_VERSION_MINOR ?).*$',
"repl": r'\g<1>{}'.format(minor)
}])
+
def set_all_lib_versions(version, major, minor, patch, build):
grep_major = check_output(['grep', 'define.*NSS_VMAJOR', nss_h])
grep_minor = check_output(['grep', 'define.*NSS_VMINOR', nss_h])
- old_major = int(grep_major.split()[2]);
- old_minor = int(grep_minor.split()[2]);
+ old_major = int(grep_major.split()[2])
+ old_minor = int(grep_minor.split()[2])
new_major = int(major)
new_minor = int(minor)
if (old_major < new_major or (old_major == new_major and old_minor < new_minor)):
- print "You're increasing the minor (or major) version:"
- print "- erasing ABI comparison expectations"
+ print("You're increasing the minor (or major) version:")
+ print("- erasing ABI comparison expectations")
new_branch = "NSS_" + str(old_major) + "_" + str(old_minor) + "_BRANCH"
- print "- setting reference branch to the branch of the previous version: " + new_branch
+ print("- setting reference branch to the branch of the previous version: " + new_branch)
with open(abi_base_version_file, "w") as abi_base:
abi_base.write("%s\n" % new_branch)
for report_file in abi_report_files:
@@ -253,6 +259,7 @@ def set_all_lib_versions(version, major, minor, patch, build):
set_patch_versions(patch)
set_build_versions(build)
+
def set_version_to_minor_release():
ensure_arguments_after_action(2, "major_version minor_version")
major = args[1].strip()
@@ -262,6 +269,7 @@ def set_version_to_minor_release():
build = "0"
set_all_lib_versions(version, major, minor, patch, build)
+
def set_version_to_patch_release():
ensure_arguments_after_action(3, "major_version minor_version patch_release")
major = args[1].strip()
@@ -271,11 +279,13 @@ def set_version_to_patch_release():
build = "0"
set_all_lib_versions(version, major, minor, patch, build)
+
def set_release_candidate_number():
ensure_arguments_after_action(1, "release_candidate_number")
build = args[1].strip()
set_build_versions(build)
+
def set_4_digit_release_number():
ensure_arguments_after_action(4, "major_version minor_version patch_release 4th_digit_release_number")
major = args[1].strip()
@@ -285,21 +295,22 @@ def set_4_digit_release_number():
version = major + '.' + minor + '.' + patch + '.' + build
set_all_lib_versions(version, major, minor, patch, build)
+
def create_nss_release_archive():
ensure_arguments_after_action(3, "nss_release_version nss_hg_release_tag path_to_stage_directory")
- nssrel = args[1].strip() #e.g. 3.19.3
- nssreltag = args[2].strip() #e.g. NSS_3_19_3_RTM
- stagedir = args[3].strip() #e.g. ../stage
+ nssrel = args[1].strip() # e.g. 3.19.3
+ nssreltag = args[2].strip() # e.g. NSS_3_19_3_RTM
+ stagedir = args[3].strip() # e.g. ../stage
with open('automation/release/nspr-version.txt') as nspr_version_file:
nsprrel = next(nspr_version_file).strip()
nspr_tar = "nspr-" + nsprrel + ".tar.gz"
- nsprtar_with_path= stagedir + "/v" + nsprrel + "/src/" + nspr_tar
+ nsprtar_with_path = stagedir + "/v" + nsprrel + "/src/" + nspr_tar
if (not os.path.exists(nsprtar_with_path)):
exit_with_failure("cannot find nspr archive at expected location " + nsprtar_with_path)
- nss_stagedir= stagedir + "/" + nssreltag + "/src"
+ nss_stagedir = stagedir + "/" + nssreltag + "/src"
if (os.path.exists(nss_stagedir)):
exit_with_failure("nss stage directory already exists: " + nss_stagedir)
@@ -309,7 +320,7 @@ def create_nss_release_archive():
check_call_noisy(["hg", "archive", "-r", nssreltag, "--prefix=nss-" + nssrel + "/nss",
stagedir + "/" + nssreltag + "/src/" + nss_tar, "-X", ".hgtags"])
check_call_noisy(["tar", "-xz", "-C", nss_stagedir, "-f", nsprtar_with_path])
- print "changing to directory " + nss_stagedir
+ print("changing to directory " + nss_stagedir)
os.chdir(nss_stagedir)
check_call_noisy(["tar", "-xz", "-f", nss_tar])
check_call_noisy(["mv", "-i", "nspr-" + nsprrel + "/nspr", "nss-" + nssrel + "/"])
@@ -320,9 +331,23 @@ def create_nss_release_archive():
check_call_noisy(["tar", "-cz", "--remove-files", "-f", nss_nspr_tar, "nss-" + nssrel])
check_call("sha1sum " + nss_tar + " " + nss_nspr_tar + " > SHA1SUMS", shell=True)
check_call("sha256sum " + nss_tar + " " + nss_nspr_tar + " > SHA256SUMS", shell=True)
- print "created directory " + nss_stagedir + " with files:"
+ print("created directory " + nss_stagedir + " with files:")
check_call_noisy(["ls", "-l"])
+
+o = OptionParser(usage="client.py [options] " + " | ".join([
+ "remove_beta", "set_beta", "print_library_versions", "print_root_ca_version",
+ "set_root_ca_version", "set_version_to_minor_release",
+ "set_version_to_patch_release", "set_release_candidate_number",
+ "set_4_digit_release_number", "create_nss_release_archive"]))
+
+try:
+ options, args = o.parse_args()
+ action = args[0]
+except IndexError:
+ o.print_help()
+ sys.exit(2)
+
if action in ('remove_beta'):
remove_beta_status()