old_contents: #!/usr/bin/python
  #  install_dotfiles
  #  This script will build platform-specific dotfiles and create the appropriate symlinks in ~
  
  import platform
  import os
  import sys
  sysName = ''
  homeDir = ''
  destDir = ''
  bashrc = ''
  def init():
    global sysName
    global bashrc
    global homeDir
    global destDir
    sysName = platform.system()
    if sysName != 'Linux' and sysName != 'Darwin':
      print "System not supported!"
      exit(1)
    else:
      print "System identified as " + sysName
  
    homeDir = os.path.expanduser('~') + '/'
    destDir = os.path.dirname(os.path.abspath(__file__)) + '/'
    os.chdir(destDir)
    cleanUp()
    bashrc = open('bashrc','a')
    bashrc.write("#!/bin/bash\n")
    bashrc.write("# This file was generated by a script. Do not edit manually!\n")
  
  def cleanUp():
    print "Cleaning up files in " + destDir + " ..."
    for file in ['bashrc']:
      if os.path.isfile(file):
        print file
        os.remove(file)
  
  def writeSection(fileName, allowComments):
    f = open(fileName,'r')
    for line in f:
      if line.startswith('#'):
        if allowComments:
          bashrc.write(line)
      else:
        bashrc.write(line)
  
  def createSymlink(targetName, linkName)	:
    target = destDir + targetName
    link = homeDir +  linkName
    print "Creating symlink: " + link + " -> " + target
    if os.path.islink(link):
      print "Link exists. Removing..."
      os.remove(link)
    os.symlink(target, link)
    print "Link created."
  
  init()
  if sysName == 'Linux':
    bashrc.write("# ~/.bashrc: executed by bash(1) for non-login shells.\n")
    if os.path.isfile('bash_private'):
      writeSection('bash_private',False)
    writeSection('bash_common',False)
    writeSection('bash_linux',True)
    createSymlink('bashrc','.bashrc')
  elif sysName == 'Darwin':
    bashrc.write("# ~/.bash_profile: executed by bash(1) for lon-login shells.\n")
    if os.path.isfile('bash_private'):
      writeSection('bash_private',False)
    writeSection('bash_common',False)
    writeSection('bash_mac',True)
    createSymlink('bashrc','.bash_profile')
  
  createSymlink('vimrc','.vimrc')
  bashrc.close()
  
new_contents: #!/usr/bin/python
  #  install_dotfiles
  #  This script will build platform-specific dotfiles and create the appropriate symlinks in ~
  
  import platform
  import os
  import sys
  class DotfilesInstaller:
    sysName = ''
    homeDir = ''
    destDir = ''
    bashrc = ''
    def __init__(self):
      global sysName
      global bashrc
      global homeDir
      global destDir
      sysName = platform.system()
      if sysName != 'Linux' and sysName != 'Darwin':
        print "System not supported!"
        exit(1)
      else:
        print "System identified as " + sysName
  
      homeDir = os.path.expanduser('~') + '/'
      destDir = os.path.dirname(os.path.abspath(__file__)) + '/'
      os.chdir(destDir)
      self.cleanUp()
      bashrc = open('bashrc','a')
      bashrc.write("#!/bin/bash\n")
      bashrc.write("# This file was generated by a script. Do not edit manually!\n")
  
    def cleanUp(self):
      print "Cleaning up files in " + destDir + " ..."
      for file in ['bashrc']:
        if os.path.isfile(file):
  	print file
  	os.remove(file)
  
    def writeSection(self, fileName, allowComments):
      f = open(fileName,'r')
      for line in f:
        if line.startswith('#'):
  	if allowComments:
  	  bashrc.write(line)
        else:
  	bashrc.write(line)
  
    def createSymlink(self, targetName, linkName):
      target = destDir + targetName
      link = homeDir +  linkName
      print "Creating symlink: " + link + " -> " + target
      if os.path.islink(link):
        print "Link exists. Removing..."
        os.remove(link)
      os.symlink(target, link)
      print "Link created."
  
    def install(self):
      if sysName == 'Linux':
        bashrc.write("# ~/.bashrc: executed by bash(1) for non-login shells.\n")
        if os.path.isfile('bash_private'):
  	self.writeSection('bash_private',False)
        self.riteSection('bash_common',False)
        self.writeSection('bash_linux',True)
        self.createSymlink('bashrc','.bashrc')
      elif sysName == 'Darwin':
        bashrc.write("# ~/.bash_profile: executed by bash(1) for lon-login shells.\n")
        if os.path.isfile('bash_private'):
  	self.writeSection('bash_private',False)
        self.writeSection('bash_common',False)
        self.writeSection('bash_mac',True)
        self.createSymlink('bashrc','.bash_profile')
  
        self.createSymlink('vimrc','.vimrc')
        bashrc.close()
  
  installer = DotfilesInstaller()
  installer.install()
  
subject: Convert script to OO style.