Fix compatibility with Python 3.9

I'm trying to run the nightly script directly from LbEnv, which means using Python 3.9 and I encountered a number of issues I'm listing here

  • cgi.escape has been moved to html.escape (see https://docs.python.org/3/whatsnew/3.8.html#api-and-feature-removals)
  • LbNightlyTools/BuildMethods.py:492 tries to write a str to a file opened in binary mode
  • LbNightlyTools/BuildMethods.py:623 tries to join bytes and str
  • LbNightlyTools/BuildMethods.py:659 tries to join bytes and str
  • LbNightlyTools/Utils.py:733 -> TypeError: a bytes-like object is required, not 'str'
  • LbNightlyTools/Utils.py:823 -> infinite loop trying to compute md5sum because iter is invoked to loop over a binary file expecting and empty str as sentinel
  • LbRPMTools/LHCbRPMSpecBuilder.py:65 uses cmp that has been removed in Python 3, see https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
Edited by Marco Clemencic