#2949 Minor Python 3 fixes for kojikamid.py
Closed 3 years ago by mikeb. Opened 3 years ago by mikeb.
mikeb/koji kojikamid-py3  into  master

file modified
+3 -9
@@ -540,23 +540,17 @@ 

  def run(cmd, chdir=None, fatal=False, log=True):

      global logfd

      output = ''

-     olddir = None

-     if chdir:

-         olddir = os.getcwd()

-         os.chdir(chdir)

      if log:

          logger = logging.getLogger('koji.vm')

          logger.info('$ %s', ' '.join(cmd))

          proc = subprocess.Popen(cmd, stdout=logfd, stderr=subprocess.STDOUT,

-                                 close_fds=True)

+                                 close_fds=True, text=True, cwd=chdir)

          ret = proc.wait()

      else:

          proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,

-                                 close_fds=True)

+                                 close_fds=True, text=True, cwd=chdir)

          output, dummy = proc.communicate()

          ret = proc.returncode

-     if olddir:

-         os.chdir(olddir)

      if ret and fatal:

          msg = 'error running: %s, return code was %s' % (' '.join(cmd), ret)

          if log:
@@ -700,7 +694,7 @@ 

              contents = fd.read(65536)

              if contents:

                  size = len(contents)

-                 data = base64.b64encode(contents)

+                 data = base64.b64encode(contents).decode()

                  digest = hashlib.sha256(contents).hexdigest()

                  del contents

                  try:

Fix some bytes/str conversions, and simplify directory handling in run().

Pull-Request has been closed by mikeb

3 years ago
Metadata