'Checks for new version, prompts to upgrade, then
replaces this script with the latest from the repo'

def upgrade(self):

    try:
        print ((((((GR + '    [!]') + W) + '    upgrading    requires    an    ') + G) + 'internet    connection') + W)
        print (((GR + '    [+]') + W) + '    checking    for    latest    version...')
        revision = get_revision()
        if (revision == (-1)):
            print ((((R + '    [!]') + O) + '    unable    to    access    GitHub') + W)
        elif (revision > self.REVISION):
            print ((((((GR + '    [!]') + W) + '    a    new    version    is    ') + G) + 'available!') + W)
            print ((((((GR + '    [-]') + W) + '            revision:                ') + G) + str(revision)) + W)
            response = raw_input((((GR + '    [+]') + W) + '    do    you    want    to    upgrade    to    the    latest    version?    (y/n):    '))
            if (not response.lower().startswith('y')):
                print ((((((GR + '    [-]') + W) + '    upgrading    ') + O) + 'aborted') + W)
                self.exit_gracefully(0)
                return
            print (((((GR + '    [+]    ') + G) + 'downloading') + W) + '    update...')
            try:
                sock = urllib.urlopen('https://github.com/derv82/wifite/raw/master/wifite.py')
                page = sock.read()
            except IOError:
                page = ''
            if (page == ''):
                print ((((R + '    [+]    ') + O) + 'unable    to    download    latest    version') + W)
                self.exit_gracefully(1)
            f = open('wifite_new.py', 'w')
            f.write(page)
            f.close()
            this_file = __file__
            if this_file.startswith('./'):
                this_file = this_file[2:]
            f = open('update_wifite.sh', 'w')
            f.write((((((('#!/bin/sh\n\n                                                                                                            rm    -rf    ' + this_file) + '\n\n                                                                                                            mv    wifite_new.py    ') + this_file) + '\n\n                                                                                                            rm    -rf    update_wifite.sh\n\n                                                                                                            chmod    +x    ') + this_file) + '\n\n                                                                                                        '))
            f.close()
            returncode = call(['chmod', '+x', 'update_wifite.sh'])
            if (returncode != 0):
                print (((((R + '    [!]') + O) + '    permission    change    returned    unexpected    code:    ') + str(returncode)) + W)
                self.exit_gracefully(1)
            returncode = call(['sh', 'update_wifite.sh'])
            if (returncode != 0):
                print (((((R + '    [!]') + O) + '    upgrade    script    returned    unexpected    code:    ') + str(returncode)) + W)
                self.exit_gracefully(1)
            print (((((((GR + '    [+]    ') + G) + 'updated!') + W) + '    type    "./') + this_file) + '"    to    run    again')
        else:
            print ((((((GR + '    [-]') + W) + '    your    copy    of    wifite    is    ') + G) + 'up    to    date') + W)
    except KeyboardInterrupt:
        print ((((R + '\n    (^C)') + O) + '    wifite    upgrade    interrupted') + W)
    self.exit_gracefully(0)
