Did I find the right examples for you? yes no

All Samples(3)  |  Call(2)  |  Derive(0)  |  Import(1)
Remove the given IP from the /etc/hosts file, then append any given
line.
This requests the sudo password.

        def update_hostfile(ip, append=[]):
    """Remove the given IP from the /etc/hosts file, then append any given
    line.
    This requests the sudo password."""

    call("cp /etc/hosts /tmp/hosts", shell=True)
    hostsf = open('/tmp/hosts', 'r')
    hosts_content = hostsf.readlines()
    hostsf.close()
    remove('/tmp/hosts')

    lines = [line for line in hosts_content if not ip in line]
    for l in append:
        lines.append(str(l) + "\n")

    final_hosts = open('/tmp/hosts_final', 'w')
    final_hosts.writelines(lines)
    final_hosts.close()

    print "Password for sudo?"
    call('sudo cp /tmp/hosts_final /etc/hosts', shell=True)
    call('sudo touch /etc/hosts', shell=True)
    remove('/tmp/hosts_final')
        


src/v/i/virtual-manager-HEAD/vms.py   virtual-manager(Download)
from config import config
from subprocess import call
from os import path, makedirs
from cli import cli
from utils import nostdout, update_hostfile, normalize, render_template
    call("rm -Rf %s" % vagrant_path, shell=True)
    # Remove the entry from the hosts file.
    update_hostfile(ip)
    # Remove the section in the configuration file.
    config.vms.remove_section(name)
    # Update hosts file.
    newline = ["%s\t%s\n" % (ip, name)]
    update_hostfile(ip, newline)
 
    # Starts the virtual machine.