837ac2e
diff --git a/bin/bdii-update b/bin/bdii-update
8617727
index 337e8e4..bce8f19 100755
837ac2e
--- a/bin/bdii-update
837ac2e
+++ b/bin/bdii-update
837ac2e
@@ -1,4 +1,4 @@
837ac2e
-#!/usr/bin/python
837ac2e
+#!/usr/bin/env python3
837ac2e
 ##############################################################################
837ac2e
 # Copyright (c) Members of the EGEE Collaboration. 2004.
837ac2e
 # See http://www.eu-egee.org/partners/ for details on the copyright
8617727
@@ -153,7 +153,7 @@ def get_config(config):
8617727
                         pf = os.open(config['BDII_PASSWD_FILE'][rootdn],
8617727
                                      os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
8617727
                                      0o600)
8617727
-                        os.write(pf, rootpw)
8617727
+                        os.write(pf, rootpw.encode())
8617727
                         os.close(pf)
8617727
                         rootdn = False
837ac2e
                         rootpw = False
8617727
@@ -209,7 +209,7 @@ def create_daemon(log_file):
837ac2e
     e = os.open(log_file, os.O_WRONLY | os.O_APPEND | os.O_CREAT, 0o644)
837ac2e
     os.dup2(e, 2)
837ac2e
     os.close(e)
837ac2e
-    sys.stderr = os.fdopen(2, 'a', 0)
837ac2e
+    sys.stderr = os.fdopen(2, 'a')
837ac2e
 
837ac2e
     # Write PID
837ac2e
     pid_file = open(config['BDII_PID_FILE'], 'w')
8617727
@@ -355,7 +355,7 @@ def convert_entry(entry_string):
8617727
             attribute = line[:index].lower()
8617727
             value = line[index + 1:].strip()
8617727
             if value and line[index + 1] == ":":
8617727
-                value = base64.b64decode(line[index + 2:].strip())
8617727
+                value = base64.b64decode(line[index + 2:].strip()).decode()
8617727
             if attribute in entry:
8617727
                 if value not in entry[attribute]:
8617727
                     entry[attribute].append(value)
8617727
@@ -392,7 +392,7 @@ def convert_back(entry):
8617727
         for value in entry[attribute]:
8617727
             if needs_encoding(value):
8617727
                 entry_string += "%s:: %s\n" % (attribute,
8617727
-                                               base64.b64encode(value))
8617727
+                                               base64.b64encode(value.encode()).decode())
8617727
             else:
8617727
                 entry_string += "%s: %s\n" % (attribute, value)
8617727
 
8617727
@@ -517,9 +517,8 @@ def fix(dns, ldif):
837ac2e
         entry = convert_entry(ldif[dns[dn][0]:dns[dn][1]])
837ac2e
         if dn[:11].lower() == "mds-vo-name":
837ac2e
             if 'objectclass' in entry:
837ac2e
-                if 'mds' in map(lambda x: x.lower(), entry['objectclass']):
837ac2e
-                    if 'gluetop' in map(lambda x: x.lower(),
837ac2e
-                                        entry['objectclass']):
837ac2e
+                if 'mds' in [x.lower() for x in entry['objectclass']]:
837ac2e
+                    if 'gluetop' in [x.lower() for x in entry['objectclass']]:
837ac2e
                         value = dn[12:dn.index(",")]
837ac2e
                         entry = {'dn': [dn],
837ac2e
                                  'objectclass': ['MDS'],
8617727
@@ -669,7 +668,7 @@ def main(config, log):
837ac2e
         log.debug("Finished Diff")
837ac2e
 
837ac2e
         log.debug("Sorting Add Keys")
837ac2e
-        ldif_add.sort(lambda x, y: cmp(len(x), len(y)))
837ac2e
+        ldif_add.sort(key=lambda x: len(x))
837ac2e
 
837ac2e
         log.debug("Writing ldif_add to disk")
837ac2e
         if config['BDII_LOG_LEVEL'] == 'DEBUG':
8617727
@@ -688,7 +687,7 @@ def main(config, log):
837ac2e
             error_file = tempfile.mktemp()
837ac2e
 
837ac2e
         roots = group_dns(ldif_add)
837ac2e
-        suffixes = roots.keys()
837ac2e
+        suffixes = list(roots.keys())
837ac2e
         if "o=shadow" in suffixes:
837ac2e
             index = suffixes.index("o=shadow")
837ac2e
             if index > 0:
8617727
@@ -759,13 +758,13 @@ def main(config, log):
837ac2e
                 log.error("Could not modify entries in the database.")
837ac2e
 
837ac2e
             modify_error_counter += log_errors(error_file,
837ac2e
-                                               ldif_modify_dns.keys())
837ac2e
+                                               list(ldif_modify_dns.keys()))
837ac2e
 
837ac2e
             if config['BDII_LOG_LEVEL'] != 'DEBUG':
837ac2e
                 os.remove(error_file)
837ac2e
 
837ac2e
         log.debug("Sorting Delete Keys")
837ac2e
-        ldif_delete.sort(lambda x, y: cmp(len(y), len(x)))
837ac2e
+        ldif_delete.sort(key=lambda x: len(x))
837ac2e
 
837ac2e
         log.debug("Writing ldif_delete to disk")
837ac2e
         if config['BDII_LOG_LEVEL'] == 'DEBUG':
8617727
@@ -1026,7 +1025,7 @@ if __name__ == '__main__':
837ac2e
                     os.O_WRONLY | os.O_APPEND | os.O_CREAT, 0o644)
837ac2e
         os.dup2(e, 2)
837ac2e
         os.close(e)
837ac2e
-        sys.stderr = os.fdopen(2, 'a', 0)
837ac2e
+        sys.stderr = os.fdopen(2, 'a')
837ac2e
 
837ac2e
     log = get_logger(config['BDII_LOG_FILE'], config['BDII_LOG_LEVEL'])
837ac2e
     main(config, log)