def run(self):
        if self.use_mm_panel:
            if sys.version_info >= (3, 0):
                self.calculate_process_region()
            PanelThreadProgress(self)

        #last_thread = ThreadTracker.get_last_added(self.window)
        ThreadTracker.add(self)

        port_number = self.settings.get('mm_app_server_port', '56248')
        ####### ---> new
        if util.is_mm_project():
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1&pid='+util.get_project_settings()['id']
        else:
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1'
        debug(url)

        try:
            if self.body != None:
                body = json.dumps(self.body).encode('utf8')
                debug('posting to MavensMate:')
                debug(body)
                req = urllib.request.Request(url, data=body, headers={'Content-Type': 'application/json', 'MavensMate-Editor-Agent': 'sublime'})
                response = urllib.request.urlopen(req)
            else:
                response = urllib.request.urlopen(url)

            debug('response from MavensMate')
            debug(response)

            mm_response = json.loads(response.read().decode('utf-8'))

            request_id = mm_response['id']
            status = mm_response['status']
            result = None
            while status == 'pending':
                url = 'http://localhost:'+str(port_number)+'/status?id='+request_id
                req = urllib.request.Request(url, headers={'MavensMate-Editor-Agent': 'sublime'})

                response = urllib.request.urlopen(url)
                response_body = response.read().decode('utf-8')
                status_response = json.loads(response_body)
                if 'status' in status_response and status_response['status'] == 'pending':
                    time.sleep(0.5)
                else:
                    result = status_response
                    status = 'done'

        except urllib.error.HTTPError as e:
            debug('urllib.error.HTTPError')
            result = e.read().decode('utf-8')
            debug(result)
            result = str(result)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(result) }
            status = 'done'
        except urllib.error.URLError as e:
            debug('urllib.error.URLError')
            result = 'Error contacting MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed. please ensure the MavensMate app is running.' }
            status = 'done'
        except Exception as e:
            debug('Exception')
            result = 'Error contacting MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(e) }
            status = 'done'


        debug(result)
        self.result = response_body

        self.calculate_process_region()

        ThreadTracker.remove(self)
Esempio n. 2
0
    def run(self):
        if self.use_mm_panel:
            if sys.version_info >= (3, 0):
                self.calculate_process_region()
            PanelThreadProgress(self)

        #last_thread = ThreadTracker.get_last_added(self.window)
        ThreadTracker.add(self)

        port_number = self.settings.get('mm_app_server_port', '56248')
        ####### ---> new
        if util.is_mm_project() and self.operation != 'new-project' and self.operation != 'open-settings':
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1&pid='+util.get_project_settings()['id']
        else:
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1'
        debug(url)

        try:
            if self.body != None:
                body = json.dumps(self.body).encode('utf8')
                debug('posting to MavensMate:')
                debug(body)
                req = urllib.request.Request(url, data=body, headers={'Content-Type': 'application/json', 'MavensMate-Editor-Agent': 'sublime'})
                response = urllib.request.urlopen(req)
            else:
                response = urllib.request.urlopen(url)

            debug('response from MavensMate')
            debug(response)

            mm_response = json.loads(response.read().decode('utf-8'))

            request_id = mm_response['id']
            status = mm_response['status']
            result = None
            while status == 'pending':
                url = 'http://localhost:'+str(port_number)+'/status?id='+request_id
                # url = 'http://localhost:'+str(port_number)+'/execute/'+request_id # this is the new call, but we don't need to use it for a while (until users are fully migrated to 0.0.11+)
                req = urllib.request.Request(url, headers={'MavensMate-Editor-Agent': 'sublime'})

                response = urllib.request.urlopen(url)
                response_body = response.read().decode('utf-8')
                status_response = json.loads(response_body)
                if 'status' in status_response and status_response['status'] == 'pending':
                    time.sleep(0.5)
                else:
                    result = status_response
                    status = 'done'

        except urllib.error.HTTPError as e:
            debug('urllib.error.HTTPError')
            result = e.read().decode('utf-8')
            debug(result)
            result = str(result)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(result) }
            status = 'done'
        except urllib.error.URLError as e:
            debug('urllib.error.URLError')
            result = 'Error contacting local MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed, please ensure MavensMate Desktop is installed and running. For more information, please visit https://github.com/joeferraro/MavensMate/tree/master/docs' }
            status = 'done'
        except Exception as e:
            debug('Exception')
            result = 'Error contacting local MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(e) }
            status = 'done'


        debug(result)
        self.result = response_body

        self.calculate_process_region()

        ThreadTracker.remove(self)
    def run(self):
        if self.use_mm_panel:
            if sys.version_info >= (3, 0):
                self.calculate_process_region()
            PanelThreadProgress(self)

        #last_thread = ThreadTracker.get_last_added(self.window)
        ThreadTracker.add(self)

        port_number = self.settings.get('mm_app_server_port', '56248')
        ####### ---> new
        if util.is_mm_project():
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1&pid='+util.get_project_settings()['id']
        else:
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1'
        debug(url)

        try:
            if self.body != None:
                body = json.dumps(self.body).encode('utf8')
                debug('posting to MavensMate:')
                debug(body)
                req = urllib.request.Request(url, data=body, headers={'Content-Type': 'application/json', 'MavensMate-Editor-Agent': 'sublime'})
                response = urllib.request.urlopen(req)
            else:
                response = urllib.request.urlopen(url)

            debug('response from MavensMate')
            debug(response)

            mm_response = json.loads(response.read().decode('utf-8'))

            request_id = mm_response['id']
            status = mm_response['status']
            result = None
            while status == 'pending':
                url = 'http://localhost:'+str(port_number)+'/status?id='+request_id
                req = urllib.request.Request(url, headers={'MavensMate-Editor-Agent': 'sublime'})

                response = urllib.request.urlopen(url)
                response_body = response.read().decode('utf-8')
                status_response = json.loads(response_body)
                if 'status' in status_response and status_response['status'] == 'pending':
                    time.sleep(0.5)
                else:
                    result = status_response
                    status = 'done'

        except urllib.error.HTTPError as e:
            debug('urllib.error.HTTPError')
            result = e.read().decode('utf-8')
            debug(result)
            result = str(result)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(result) }
            status = 'done'
        except urllib.error.URLError as e:
            debug('urllib.error.URLError')
            result = 'Error contacting MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed. please ensure the MavensMate app is running.' }
            status = 'done'
        except Exception as e:
            debug('Exception')
            result = 'Error contacting MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(e) }
            status = 'done'


        debug(result)
        self.result = response_body

        self.calculate_process_region()

        ThreadTracker.remove(self)