original_docstring: 
          Update/add entry for hostname ip in /etc/hosts
          
docstring: Update/add entry for hostname ip in /etc/hosts
docstring_tokens: Update / add entry for hostname ip in / etc / hosts
code: def update_hosts_file(hostname, ip):
          """
          Update/add entry for hostname ip in /etc/hosts
          """
          import re
  
          with open('/etc/hosts', 'r') as hosts_file:
              contents = hosts_file.read()
  
          if isinstance(hostname, list):
              hostnames = ' '.join(hostname)
          else:
              hostnames = hostname
  
          result = re.search('^{0}\s.*\n'.format(ip), contents, re.MULTILINE)
          if result:
              contents = contents.replace(result.group(0), '{0} {1}\n'.format(ip, hostnames))
          else:
              contents += '{0} {1}\n'.format(ip, hostnames)
  
          with open('/etc/hosts', 'wb') as hosts_file:
              hosts_file.write(contents)
code_tokens: def update_hosts_file ( hostname , ip ) : import re with open ( '/etc/hosts' , 'r' ) as hosts_file : contents = hosts_file . read ( ) if isinstance ( hostname , list ) : hostnames = ' ' . join ( hostname ) else : hostnames = hostname result = re . search ( '^{0}\s.*\n' . format ( ip ) , contents , re . MULTILINE ) if result : contents = contents . replace ( result . group ( 0 ) , '{0} {1}\n' . format ( ip , hostnames ) ) else : contents += '{0} {1}\n' . format ( ip , hostnames ) with open ( '/etc/hosts' , 'wb' ) as hosts_file : hosts_file . write ( contents )
short_docstring: Update/add entry for hostname ip in /etc/hosts
short_docstring_tokens: Update / add entry for hostname ip in / etc / hosts
comment: """
          Update/add entry for hostname ip in /etc/hosts
          """