Topic: Python 2.6+ and cmd5.py script
Hi,
while trying to fix another issue that i had i recognized that from at least python version 2.6 and on the module md5 is marked deprecated. So compilation will fail with a DeprecationWarning. Changing the script like this will make it compatible with Python 2.5 and below, and 2.6 and above.
import sys, re
try:
import hashlib
m = hashlib.md5()
hashlib_avail = 1
except ImportError:
# for Python << 2.5
import md5
m = md5.new()
hashlib_avail = 0
alphanum = "0123456789abcdefghijklmnopqrstuvwzyxABCDEFGHIJKLMNOPQRSTUVWXYZ_"
def cstrip(lines):
d = ""
for l in lines:
l = re.sub("#.*", "", l)
l = re.sub("//.*", "", l)
d += l + " "
d = re.sub("\/\*.*?\*/", "", d) # remove /* */ comments
d = d.replace("\t", " ") # tab to space
d = re.sub(" *", " ", d) # remove double spaces
d = re.sub("", "", d) # remove /* */ comments
d = d.strip()
# this eats up cases like 'n {'
i = 1
while i < len(d)-2:
if d[i] == ' ':
if not (d[i-1] in alphanum and d[i+1] in alphanum):
d = d[:i] + d[i+1:]
i += 1
return d
f = ""
for filename in sys.argv[1:]:
f += cstrip([l.strip() for l in file(filename)])
if hashlib_avail == 0:
print '#define GAME_NETVERSION_HASH "%s"' % md5.new(f).hexdigest().lower()[16:]
else:
print '#define GAME_NETVERSION_HASH "%s"' % hashlib.md5(f).hexdigest().lower()[16:]
Maybe this can be improved, im not a python programmer
Questmaster