diff options
Diffstat (limited to 'pyanaconda/iutil.py')
-rw-r--r-- | pyanaconda/iutil.py | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py index dd691dc4f..abf720fd4 100644 --- a/pyanaconda/iutil.py +++ b/pyanaconda/iutil.py @@ -74,6 +74,13 @@ class tee(threading.Thread): self.running = False return self +def augmentEnv(): + env = os.environ.copy() + env.update({"LC_ALL": "C", + "ANA_INSTALL_PATH": ROOT_PATH + }) + return env + ## Run an external program and redirect the output to a file. # @param command The command to run. # @param argv A list of arguments. @@ -84,6 +91,11 @@ class tee(threading.Thread): # @return The return code of command. def execWithRedirect(command, argv, stdin = None, stdout = None, stderr = None, root = '/', env_prune=[]): + if flags.testing: + log.info("not running command because we're testing: %s %s" + % (command, " ".join(argv))) + return 0 + def chroot (): os.chroot(root) @@ -125,9 +137,6 @@ def execWithRedirect(command, argv, stdin = None, stdout = None, #prepare os pipes for feeding tee proceses pstdout, pstdin = os.pipe() perrout, perrin = os.pipe() - - env = os.environ.copy() - env.update({"LC_ALL": "C"}) for var in env_prune: if env.has_key(var): @@ -146,7 +155,7 @@ def execWithRedirect(command, argv, stdin = None, stdout = None, stdout=pstdin, stderr=perrin, preexec_fn=chroot, cwd=root, - env=env) + env=augmentEnv()) proc.wait() ret = proc.returncode @@ -190,6 +199,11 @@ def execWithRedirect(command, argv, stdin = None, stdout = None, # @param root The directory to chroot to before running command. # @return The output of command from stdout. def execWithCapture(command, argv, stdin = None, stderr = None, root='/'): + if flags.testing: + log.info("not running command because we're testing: %s %s" + % (command, " ".join(argv))) + return "" + def chroot(): os.chroot(root) @@ -222,15 +236,12 @@ def execWithCapture(command, argv, stdin = None, stderr = None, root='/'): program_log.info("Running... %s" % (" ".join([command] + argv),)) - env = os.environ.copy() - env.update({"LC_ALL": "C"}) - try: proc = subprocess.Popen([command] + argv, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=chroot, cwd=root, - env=env) + env=augmentEnv()) while True: (outStr, errStr) = proc.communicate() @@ -254,6 +265,11 @@ def execWithCapture(command, argv, stdin = None, stderr = None, root='/'): def execWithCallback(command, argv, stdin = None, stdout = None, stderr = None, echo = True, callback = None, callback_data = None, root = '/'): + if flags.testing: + log.info("not running command because we're testing: %s %s" + % (command, " ".join(argv))) + return ExecProduct(0, '', '') + def chroot(): os.chroot(root) @@ -1011,6 +1027,34 @@ def lsmod(): lines = f.readlines() return [l.split()[0] for l in lines] +def _run_systemctl(command, service): + """ + Runs 'systemctl command service.service' + + @return: exit status of the systemctl + + """ + + service_name = service + ".service" + ret = execWithRedirect("systemctl", [command, service_name], stdin=None, + stdout="/dev/tty5", stderr="/dev/tty5") + + return ret + +def start_service(service): + return _run_systemctl("start", service) + +def stop_service(service): + return _run_systemctl("stop", service) + +def restart_service(service): + return _run_systemctl("restart", service) + +def service_running(service): + ret = _run_systemctl("status", service) + + return ret == 0 + def dracut_eject(device): """ Use dracut shutdown hook to eject media after the system is shutdown. @@ -1034,3 +1078,4 @@ def dracut_eject(device): log.info("Wrote dracut shutdown eject hook for %s" % (device,)) except Exception, e: log.error("Error writing dracut shutdown eject hook for %s: %s" % (device, e)) + |