From 5a317f7d8ef77900586709ea2001e997ba11f7ec Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Tue, 28 May 2024 19:45:17 +1200 Subject: [PATCH] buildtools: remove Python2 compatibility Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- buildtools/bin/waf | 13 ++------- buildtools/wafsamba/samba_patterns.py | 6 +--- buildtools/wafsamba/samba_utils.py | 42 +++++++-------------------- buildtools/wafsamba/samba_version.py | 2 -- 4 files changed, 13 insertions(+), 50 deletions(-) diff --git a/buildtools/bin/waf b/buildtools/bin/waf index 0f70fa21de2..c103979cc00 100755 --- a/buildtools/bin/waf +++ b/buildtools/bin/waf @@ -45,13 +45,9 @@ join = os.path.join if sys.hexversion<0x206000f: raise ImportError('Python >= 2.6 is required to create the waf file') -WAF='waf' +WAF='waf3' def b(x): - return x -if sys.hexversion>0x300000f: - WAF='waf3' - def b(x): - return x.encode() + return x.encode() def err(m): print(('\033[91mError: %s\033[0m' % m)) @@ -107,11 +103,6 @@ def unpack_wafdir(dir, src): for x in ('Tools', 'extras'): os.chmod(join('waflib',x), 493) - if sys.hexversion<0x300000f: - sys.path = [join(dir, 'waflib')] + sys.path - import fixpy2 - fixpy2.fixdir(dir) - os.remove(tmp) os.chdir(cwd) diff --git a/buildtools/wafsamba/samba_patterns.py b/buildtools/wafsamba/samba_patterns.py index 41296810e13..faaade75ae4 100644 --- a/buildtools/wafsamba/samba_patterns.py +++ b/buildtools/wafsamba/samba_patterns.py @@ -187,11 +187,7 @@ def write_build_options(task): keys_header_sys = [] keys_header_other = [] keys_misc = [] - if sys.hexversion>0x300000f: - trans_table = bytes.maketrans(b'.-()', b'____') - else: - import string - trans_table = string.maketrans('.-()', '____') + trans_table = bytes.maketrans(b'.-()', b'____') for key in tbl: if key.startswith("HAVE_UT_UT_") or key.find("UTMP") >= 0: diff --git a/buildtools/wafsamba/samba_utils.py b/buildtools/wafsamba/samba_utils.py index f287e85d838..e45f0ae1a35 100644 --- a/buildtools/wafsamba/samba_utils.py +++ b/buildtools/wafsamba/samba_utils.py @@ -15,38 +15,16 @@ from waflib.Build import CACHE_SUFFIX # TODO: make this a --option LIB_PATH="shared" - -PY3 = sys.version_info[0] == 3 - -if PY3: - - # helper function to get a string from a variable that maybe 'str' or - # 'bytes' if 'bytes' then it is decoded using 'utf8'. If 'str' is passed - # it is returned unchanged - # Using this function is PY2/PY3 code should ensure in most cases - # the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly - # decodes the variable (see PY2 implementation of this function below) - def get_string(bytesorstring): - tmp = bytesorstring - if isinstance(bytesorstring, bytes): - tmp = bytesorstring.decode('utf8') - elif not isinstance(bytesorstring, str): - raise ValueError('Expected byte of string for %s:%s' % (type(bytesorstring), bytesorstring)) - return tmp - -else: - - # Helper function to return string. - # if 'str' or 'unicode' passed in they are returned unchanged - # otherwise an exception is generated - # Using this function is PY2/PY3 code should ensure in most cases - # the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly - # decodes the variable (see PY3 implementation of this function above) - def get_string(bytesorstring): - tmp = bytesorstring - if not(isinstance(bytesorstring, str) or isinstance(bytesorstring, unicode)): - raise ValueError('Expected str or unicode for %s:%s' % (type(bytesorstring), bytesorstring)) - return tmp +# Py3 transition helper function to get a string from a variable that +# may be 'str' or 'bytes'. If 'bytes' then it is decoded using 'utf8'. +# If 'str' is passed it is returned unchanged. +def get_string(bytesorstring): + tmp = bytesorstring + if isinstance(bytesorstring, bytes): + tmp = bytesorstring.decode('utf8') + elif not isinstance(bytesorstring, str): + raise ValueError('Expected byte of string for %s:%s' % (type(bytesorstring), bytesorstring)) + return tmp # sigh, python octal constants are a mess MODE_644 = int('644', 8) diff --git a/buildtools/wafsamba/samba_version.py b/buildtools/wafsamba/samba_version.py index 31103e0f8c4..3d2998c7441 100644 --- a/buildtools/wafsamba/samba_version.py +++ b/buildtools/wafsamba/samba_version.py @@ -200,8 +200,6 @@ also accepted as dictionary entries here string+="#define SAMBA_VERSION_%s " % name value = self.vcs_fields[name] string_types = str - if sys.version_info[0] < 3: - string_types = basestring if isinstance(value, string_types): string += "\"%s\"" % value elif type(value) is int: -- 2.47.3