예제 #1
0
    def main_handler(self, method='GET'):
        # get request url (without url params) and remove trailing /
        config.debug('>>> handling request')
        config.debug(self.path)

        request_url = self.path.split('?')[0]
        if request_url is not '/':
            request_url = request_url.rstrip('/')

        handler = None
        try:
            handler = self.mappings[request_url][method]
            #config.debug(handler)
        except KeyError:
            # no mapping found for the request
            self.send_response(404)
            self.end_headers()
            return

        try:
            handler(self)
        except KeyError:
            # method not found
            self.send_response(501)
            self.end_headers()
            return
예제 #2
0
def run():
    server_config.setup_logging()
    server_config.debug('---> Starting MavensMate UI server')
    sys.path.insert(0, config.base_path)
    handler.Handler.mappings = endpoints.mappings
    HOST, PORT = "localhost", config.connection.get_plugin_client_setting('mm_server_port', 77777)
    server = ThreadedHTTPServer((HOST, PORT), handler.Handler)
    ip, port = server.server_address
    print "Server running on port: "+str(port)
    server_config.debug("MavensMate UI server running on port: "+str(port))
    server.serve_forever()
예제 #3
0
def run():
    server_config.setup_logging()
    server_config.debug('---> Starting MavensMate UI server')
    sys.path.insert(0, config.base_path)
    handler.Handler.mappings = endpoints.mappings
    HOST, PORT = "localhost", config.connection.get_plugin_client_setting(
        'mm_server_port', 77777)
    server = ThreadedHTTPServer((HOST, PORT), handler.Handler)
    ip, port = server.server_address
    print "Server running on port: " + str(port)
    server_config.debug("MavensMate UI server running on port: " + str(port))
    server.serve_forever()
예제 #4
0
def unit_test_request(request_handler):
    '''
        POST /project/unit_test
        {
            "classes" : [
                "UnitTestClass1", "UnitTestClass2"
            ],
            "run_all_tests" : false
        }
    '''
    gc.debug('in unit test method!')
    run_async_operation(request_handler, 'unit_test')
예제 #5
0
파일: endpoints.py 프로젝트: DavidCDean/mm
def unit_test_request(request_handler):
    '''
        POST /project/unit_test
        {
            "classes" : [
                "UnitTestClass1", "UnitTestClass2"
            ],
            "run_all_tests" : false
        }
    '''
    gc.debug('in unit test method!')
    run_async_operation(request_handler, 'unit_test')
예제 #6
0
파일: util.py 프로젝트: DavidCDean/mm
    def run(self):
        mm_response = None
        args = self.get_arguments()
        server_config.debug('>>> running thread arguments on next line!')
        server_config.debug(args)
        if self.debug_mode or 'darwin' not in sys.platform:
            print(self.payload)
            python_path = config.connection.get_plugin_client_setting('mm_python_location')

            if 'darwin' in sys.platform or config.connection.get_plugin_client_setting('mm_debug_location') != None:
                mm_loc = config.connection.get_plugin_client_setting('mm_debug_location')
            else:
                mm_loc = os.path.join(config.mm_dir,"mm","mm.py")
            #p = subprocess.Popen("{0} {1} {2}".format(python_path, pipes.quote(mm_loc), args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
        
            if 'linux' in sys.platform or 'darwin' in sys.platform:
                #osx, linux
                p = subprocess.Popen('\'{0}\' \'{1}\' {2}'.format(python_path, mm_loc, self.get_arguments()), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
            else:
                #windows
                if config.connection.get_plugin_client_setting('mm_debug_mode', False):
                    #user wishes to use system python
                    python_path = config.connection.get_plugin_client_setting('mm_python_location')
                    p = subprocess.Popen('"{0}" "{1}" {2}'.format(python_path, mm_loc, self.get_arguments()), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
                else:
                    python_path = os.path.join(os.environ["ProgramFiles"],"MavensMate","App","python.exe")
                    if not os.path.isfile(python_path):
                        python_path = python_path.replace("Program Files", "Program Files (x86)")
                    p = subprocess.Popen('"{0}" -E "{1}" {2}'.format(python_path, mm_loc, self.get_arguments()), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)

            #process = subprocess.Popen("{0} {1} {2}".format(python_path, pipes.quote(mm_loc), self.get_arguments()), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
        else:
            p = subprocess.Popen("{0} {1}".format(pipes.quote(self.mm_path), args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
        #print("PAYLOAD: ",self.payload)
        #print("PAYLOAD TYPE: ",type(self.payload))
        if self.payload != None and type(self.payload) is str:
            self.payload = self.payload.encode('utf-8')
        p.stdin.write(self.payload)
        p.stdin.close()
        if p.stdout is not None: 
            mm_response = p.stdout.readlines()
        elif p.stderr is not None:
            mm_response = p.stderr.readlines()
        
        #response_body = '\n'.join(mm_response.decode('utf-8'))
        strs = []
        for line in mm_response:
            strs.append(line.decode('utf-8'))   
        response_body = '\n'.join(strs)

        server_config.debug('>>> got a response body')
        server_config.debug(response_body)

        if '--html' not in args:
            try:
                valid_json = json.loads(response_body)
            except:
                response_body = generate_error_response(response_body)

        self.response = response_body
예제 #7
0
def stop():
    server_config.debug('shutting down local MavensMate server')
    server.shutdown()
예제 #8
0
def respond_with_async_request_id(request_handler, request_id):
    response = {'status': 'pending', 'id': request_id}
    json_response_body = json.dumps(response)
    gc.debug(json_response_body)
    respond(request_handler, json_response_body, 'text/json')
예제 #9
0
def status_request(request_handler):
    gc.debug('>>> status request')
    params, json_string, plugin_client = get_request_params(request_handler)
    gc.debug('>>> params: ')
    gc.debug(params)
    try:
        request_id = params['id']
    except:
        request_id = params['id'][0]
    gc.debug('>>> request id: ' + request_id)
    gc.debug('>>> async queue: ')
    gc.debug(async_request_queue)

    if request_id not in async_request_queue:
        response = {
            'status': 'error',
            'id': request_id,
            'body': 'Request ID was not found in async request queue.'
        }
        response_body = json.dumps(response)
        respond(request_handler, response_body, 'text/json')
    else:
        async_thread = async_request_queue[request_id]
        gc.debug('found thread in request queue, checking if alive')
        gc.debug(async_thread.is_alive())
        if async_thread.is_alive():
            gc.debug('>>> request is not ready')
            respond_with_async_request_id(request_handler, request_id)
        elif async_thread.is_alive() == False:
            gc.debug('>>> request is ready, returning response')
            async_request_queue.pop(request_id, None)
            respond(request_handler, async_thread.response, 'text/json')
예제 #10
0
def run_async_operation(request_handler, operation_name):
    gc.debug('>>> running an async operation')
    request_id = util.generate_request_id()
    params, raw_post_body, plugin_client = get_request_params(request_handler)
    if operation_name == None and "command" in params:
        operation_name = params["command"]
    gc.debug(request_id)
    gc.debug(params)
    gc.debug(raw_post_body)

    worker_thread = BackgroundWorker(operation_name, params, True, request_id,
                                     raw_post_body, plugin_client)
    gc.debug('worker created')
    worker_thread.start()
    gc.debug('worker thread started')
    async_request_queue[request_id] = worker_thread
    gc.debug('placed into queue')

    return respond_with_async_request_id(request_handler, request_id)
예제 #11
0
    def run(self):
        mm_response = None
        args = self.get_arguments()
        server_config.debug('>>> running thread arguments on next line!')
        server_config.debug(args)
        if self.debug_mode or 'darwin' not in sys.platform:
            print(self.payload)
            python_path = config.connection.get_plugin_client_setting(
                'mm_python_location')

            if 'darwin' in sys.platform or config.connection.get_plugin_client_setting(
                    'mm_debug_location') != None:
                mm_loc = config.connection.get_plugin_client_setting(
                    'mm_debug_location')
            else:
                mm_loc = os.path.join(config.mm_dir, "mm", "mm.py")
            #p = subprocess.Popen("{0} {1} {2}".format(python_path, pipes.quote(mm_loc), args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)

            if 'linux' in sys.platform or 'darwin' in sys.platform:
                #osx, linux
                p = subprocess.Popen('\'{0}\' \'{1}\' {2}'.format(
                    python_path, mm_loc, self.get_arguments()),
                                     stdin=subprocess.PIPE,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     shell=True)
            else:
                #windows
                if config.connection.get_plugin_client_setting(
                        'mm_debug_mode', False):
                    #user wishes to use system python
                    python_path = config.connection.get_plugin_client_setting(
                        'mm_python_location')
                    p = subprocess.Popen('"{0}" "{1}" {2}'.format(
                        python_path, mm_loc, self.get_arguments()),
                                         stdin=subprocess.PIPE,
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.STDOUT,
                                         shell=True)
                else:
                    python_path = os.path.join(os.environ["ProgramFiles"],
                                               "MavensMate", "App",
                                               "python.exe")
                    if not os.path.isfile(python_path):
                        python_path = python_path.replace(
                            "Program Files", "Program Files (x86)")
                    p = subprocess.Popen('"{0}" -E "{1}" {2}'.format(
                        python_path, mm_loc, self.get_arguments()),
                                         stdin=subprocess.PIPE,
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.STDOUT,
                                         shell=True)

            #process = subprocess.Popen("{0} {1} {2}".format(python_path, pipes.quote(mm_loc), self.get_arguments()), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
        else:
            p = subprocess.Popen("{0} {1}".format(pipes.quote(self.mm_path),
                                                  args),
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT,
                                 shell=True)
        #print("PAYLOAD: ",self.payload)
        #print("PAYLOAD TYPE: ",type(self.payload))
        if self.payload != None and type(self.payload) is str:
            self.payload = self.payload.encode('utf-8')
        p.stdin.write(self.payload)
        p.stdin.close()
        if p.stdout is not None:
            mm_response = p.stdout.readlines()
        elif p.stderr is not None:
            mm_response = p.stderr.readlines()

        #response_body = '\n'.join(mm_response.decode('utf-8'))
        strs = []
        for line in mm_response:
            strs.append(line.decode('utf-8'))
        response_body = '\n'.join(strs)

        server_config.debug('>>> got a response body')
        server_config.debug(response_body)

        if '--html' not in args:
            try:
                valid_json = json.loads(response_body)
            except:
                response_body = generate_error_response(response_body)

        self.response = response_body
예제 #12
0
파일: endpoints.py 프로젝트: DavidCDean/mm
def respond_with_async_request_id(request_handler, request_id):
    response = { 'status' : 'pending', 'id' : request_id }
    json_response_body = json.dumps(response)
    gc.debug(json_response_body)
    respond(request_handler, json_response_body, 'text/json')
예제 #13
0
파일: endpoints.py 프로젝트: DavidCDean/mm
def status_request(request_handler):
    gc.debug('>>> status request')
    params, json_string, plugin_client = get_request_params(request_handler)
    gc.debug('>>> params: ')
    gc.debug(params)
    try:
        request_id = params['id']
    except:
        request_id = params['id'][0]
    gc.debug('>>> request id: ' + request_id)
    gc.debug('>>> async queue: ')
    gc.debug(async_request_queue)

    if request_id not in async_request_queue:
        response = { 'status' : 'error', 'id' : request_id, 'body' : 'Request ID was not found in async request queue.' }
        response_body = json.dumps(response)
        respond(request_handler, response_body, 'text/json')
    else:
        async_thread = async_request_queue[request_id]
        gc.debug('found thread in request queue, checking if alive')
        gc.debug(async_thread.is_alive())
        if async_thread.is_alive():
            gc.debug('>>> request is not ready')
            respond_with_async_request_id(request_handler, request_id)
        elif async_thread.is_alive() == False:
            gc.debug('>>> request is ready, returning response')
            async_request_queue.pop(request_id, None)
            respond(request_handler, async_thread.response, 'text/json')
예제 #14
0
파일: endpoints.py 프로젝트: DavidCDean/mm
def run_async_operation(request_handler, operation_name):
    gc.debug('>>> running an async operation')
    request_id = util.generate_request_id()
    params, raw_post_body, plugin_client = get_request_params(request_handler)
    if operation_name == None and "command" in params:
        operation_name = params["command"]
    gc.debug(request_id)
    gc.debug(params)
    gc.debug(raw_post_body)
    
    worker_thread = BackgroundWorker(operation_name, params, True, request_id, raw_post_body, plugin_client)
    gc.debug('worker created')
    worker_thread.start()
    gc.debug('worker thread started')
    async_request_queue[request_id] = worker_thread
    gc.debug('placed into queue')

    return respond_with_async_request_id(request_handler, request_id)
예제 #15
0
def stop():
    server_config.debug('shutting down local MavensMate server')
    server.shutdown()