def copy(src, dest): console.message("Copying file/directory '%s' to '%s'" % (src, dest)) if os.path.isfile(src): shutil.copy(src, dest) else: shutil.copytree(src, dest)
def run(args, timeout=None, stdout=None, exit_on_error=True): console.message("Running task: %s" % " ".join(args)) p = subprocess.Popen(args, stdout=stdout, stderr=subprocess.PIPE, bufsize=1) thread = _attach_stderr_listener(p) if timeout is not None: thread.join(timeout) p.poll() if p.returncode == None: p.kill() if exit_on_error: raise error.ProletarianBuildException("Process '%s' timed out after %s seconds" % (args[0], timeout)) else: console.error("Process '%s' failed to finish in the specified time (%s seconds)" % (args[0], timeout)) else: thread.join() # Uses a busy waiting loop instead of communicate() or wait() because # this should not happen frequently (i.e. the thread should join when # the process terminates) and it has less risk of starvation. while p.returncode != 0: time.sleep(0.1) p.poll() if exit_on_error and p.returncode != 0: raise error.ProletarianBuildException("Process '%s' had a non-zero return code (%s)" % (args[0], p.returncode))
def run_async(args): console.message("Running async task: %s" % " ".join(args)) p = subprocess.Popen(args, stderr=subprocess.PIPE, bufsize=1) _attach_stderr_listener(p) return p
def remove_dir(dir, ignore_errors=False): console.message("Removing directory '%s'" % dir) shutil.rmtree(dir, ignore_errors)
def make_dir(dir): console.message("Making directory '%s'" % dir) os.mkdir(dir)
def move(src, dest): console.message("Moving file/directory '%s' to '%s'" % (src, dest)) shutil.move(src, dest)
def set_cwd(dir): console.message("Setting working directory to %s" % dir) os.chdir(dir)