a method to validate user can access heroku account

def _validate_login(self):
        
        ''' a method to validate user can access heroku account '''
        
        title = '%s.validate_login' % self.__class__.__name__
            
    # verbosity
        windows_insert = ' On windows, run in cmd.exe'
        self.printer('Checking heroku credentials ... ', flush=True)

    # validate netrc exists
        from os import path
        netrc_path = path.join(self.localhost.home, '.netrc')
    # TODO verify path exists on Windows
        if not path.exists(netrc_path):
            error_msg = '.netrc file is missing. Try: heroku login, then heroku auth:token'
            if self.localhost.os.sysname in ('Windows'):
                error_msg += windows_insert
            self.printer('ERROR.')
            raise Exception(error_msg)

    # replace value in netrc
        netrc_text = self._update_netrc(netrc_path, self.token, self.email)

    # verify remote access
        def handle_invalid(stdout, proc):

        # define process closing helper
            def _close_process(_proc):
            # close process
                import psutil
                process = psutil.Process(_proc.pid)
                for proc in process.children(recursive=True):
                    proc.kill()
                process.kill()
            # restore values to netrc
                with open(netrc_path, 'wt') as f:
                    f.write(netrc_text)
                    f.close()

        # invalid credentials
            if stdout.find('Invalid credentials') > -1:
                _close_process(proc)
                self.printer('ERROR.')
                raise Exception('Permission denied. Heroku auth token is not valid.\nTry: "heroku login", then "heroku auth:token"')

        sys_command = 'heroku apps --json'
        response = self._handle_command(sys_command, interactive=handle_invalid, handle_error=True)

        if response.find('Warning: heroku update') > -1:
            self.printer('WARNING: heroku update available.')
            self.printer('Try: npm install -g -U heroku\nor see https://devcenter.heroku.com/articles/heroku-cli#staying-up-to-date')
            self.printer('Checking heroku credentials ... ')
            response_lines = response.splitlines()
            response = '\n'.join(response_lines[1:])

    # add list to object
        import json
        try:
            self.apps = json.loads(response)
        except:
            self.printer('ERROR.')
            raise Exception(response)

        self.printer('done.')

        return self