support/package-builder/CommandUtils.py
326d5ca8
 # pylint: disable=invalid-name,missing-docstring
2820c61a
 import subprocess
 import os
 
8f56b626
 class CommandUtils:
2820c61a
 
8f56b626
     @staticmethod
     def findFile(filename, sourcePath):
         process = subprocess.Popen(["find", "-L", sourcePath, "-name", filename,
87815216
                                     "-not", "-type", "d"], stdout=subprocess.PIPE)
         # We don't check the return val here because find could return 1 but still be
         # able to find
b8ab7fb4
         # the result. We shouldn't blindly return None without even checking the result.
         # The reason we want to suppress this is because for built RPMs, we first copy it to
         # the location with a random name and move it to the real name. find will complain our
         # action and return 1.
         # find's flag ignore_readdir_race can suppress this but it isn't working.
         # https://bugs.centos.org/view.php?id=13685
 
         #if returnVal != 0:
         #    return None
87815216
         result = process.communicate()[0]
2820c61a
         if result is None:
             return None
87815216
         return result.decode().split()
2820c61a
 
87815216
     @staticmethod
8f56b626
     def runCommandInShell(cmd, logfile=None, logfn=None):
         retval = 0
         if logfn:
             process = subprocess.Popen("%s" %cmd, shell=True, stdout=subprocess.PIPE)
326d5ca8
             retval = process.wait()
8f56b626
             logfn(process.communicate()[0].decode())
         else:
             if logfile is None:
                 logfile = os.devnull
             with open(logfile, "w") as f:
                 process = subprocess.Popen("%s" %cmd, shell=True, stdout=f, stderr=f)
             retval = process.wait()
         return retval