1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-10 12:58:35 +03:00

buildtools: remove Python2 compatibility

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Douglas Bagnall 2024-05-28 19:45:17 +12:00 committed by Douglas Bagnall
parent 564b0a21ce
commit 5a317f7d8e
4 changed files with 13 additions and 50 deletions

13
buildtools/bin/waf vendored
View File

@ -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)

View File

@ -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:

View File

@ -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)

View File

@ -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: