Example #1
0
 def delete_apex_checkpoint(self, **kwargs):
     if 'overlay_id' in kwargs:
         r = requests.delete(self.get_tooling_url()+"/sobjects/ApexExecutionOverlayAction/{0}".format(kwargs['overlay_id']), headers=self.get_rest_headers(), proxies=self.__get_proxies(), verify=False)
         if self.__is_failed_request(r):
             self.__exception_handler(r)
         return util.generate_success_response('OK')
     else:
         id = kwargs.get('id', None)
         file_path = kwargs.get('file_path', None)
         line_number = kwargs.get('line_number', None)
         if id == None:
             ext = util.get_file_extension_no_period(file_path)
             api_name = util.get_file_name_no_extension(file_path)
             mtype = util.get_meta_type_by_suffix(ext)
             id = self.get_apex_entity_id_by_name(object_type=mtype['xmlName'], name=api_name)
         
         query_string = "Select Id from ApexExecutionOverlayAction Where ExecutableEntityId = '{0}' AND Line = {1}".format(id, line_number)
         r = requests.get(self.get_tooling_url()+"/query/", params={'q':query_string}, headers=self.get_rest_headers(), proxies=self.__get_proxies(), verify=False)
         if self.__is_failed_request(r):
             self.__exception_handler(r)
         query_result = util.parse_rest_response(r.text)
         overlay_id = query_result['records'][0]['Id']
         r = requests.delete(self.get_tooling_url()+"/sobjects/ApexExecutionOverlayAction/{0}".format(overlay_id), headers=self.get_rest_headers(), proxies=self.__get_proxies(), verify=False)
         if self.__is_failed_request(r):
             self.__exception_handler(r)
         return util.generate_success_response('OK')
Example #2
0
    def execute(self):
        """
            Executes requested command
        """
        try:
            self.__setup_connection()

            #if the arg switch argument is included, the request is to launch the out of box
            #MavensMate UI, so we generate the HTML for the UI and launch the process
            #example: mm -o new_project --ui
            if self.args.ui_switch == True:
                config.logger.debug('UI operation requested, attempting to launch MavensMate UI')
                tmp_html_file = util.generate_ui(self.operation,self.payload,self.args)
                if config.connection.plugin_client == 'ATOM': #returning location of html file here so we can open the page inside an atom panel
                    self.__printr(util.generate_success_response(tmp_html_file))
                else:
                    util.launch_ui(tmp_html_file)
                    self.__printr(util.generate_success_response('UI Generated Successfully'))
            
            #non-ui command
            else:        
                commands = get_available_commands()
                #debug(commands)
                try:
                    command_clazz = commands[self.operation](params=self.payload,args=self.args)                
                except KeyError:
                    raise MMUnsupportedOperationException('Could not find the operation you requested. Be sure the command is located in mm.commands, inherits from Command (found in basecommand.py) and includes an execute method.')
                except NotImplementedError:
                    raise MMException("This command is not properly implemented. Be sure it contains an 'execute' method.")
                self.__printr(command_clazz.execute())
        except Exception, e:
            self.__printr(e, is_exception=True)
Example #3
0
 def delete_trace_flags(self, user_id=None):
     if user_id == None:
         query_string = "Select Id From TraceFlag"
     else:
         query_string = "Select Id From TraceFlag WHERE TracedEntityId = '{0}'".format(config.sfdc_client.user_id)
     qr = self.tooling_query(query_string)
     if type(qr['records'] is list and len(qr['records']) > 0):
         for record in qr['records']:
             self.delete_tooling_entity("TraceFlag", record["Id"])
         return util.generate_success_response("Done")
     else:
         return util.generate_success_response("No stack traces to delete")
Example #4
0
    def create_apex_checkpoint(self, payload):        
        if 'ScopeId' not in payload:
            payload['ScopeId'] = self.user_id
        if 'API_Name' in payload:
            payload['ExecutableEntityId'] = self.get_apex_entity_id_by_name(object_type=payload['Object_Type'], name=payload['API_Name'])
            payload.pop('Object_Type', None)
            payload.pop('API_Name', None)
        
        payload.pop('workspace', None)

        payload = json.dumps(payload)
        r = requests.post(self.get_tooling_url()+"/sobjects/ApexExecutionOverlayAction", data=payload, proxies=self.__get_proxies(), headers=self.get_rest_headers('POST'), verify=False)
        if self.__is_failed_request(r):
            self.__exception_handler(r)
        
        ##WE ALSO NEED TO CREATE A TRACE FLAG FOR THIS USER
        expiration = util.get_iso_8601_timestamp(30)

        payload = {
            "ApexCode"          : "FINEST",
            "ApexProfiling"     : "INFO",
            "Callout"           : "INFO",
            "Database"          : "INFO",
            "ExpirationDate"    : expiration,
            "ScopeId"           : self.user_id,
            "System"            : "DEBUG",
            "TracedEntityId"    : self.user_id,
            "Validation"        : "INFO",
            "Visualforce"       : "INFO",
            "Workflow"          : "INFO"
        }
        self.create_trace_flag(payload)

        return util.generate_success_response("Done")
Example #5
0
 def delete_apex_checkpoint_results(self):
     query_string = 'Select Id From ApexExecutionOverlayResult Where UserId = \''+self.user_id+'\' order by CreatedDate'
     r = requests.get(self.get_tooling_url()+"/query/", params={'q':query_string}, headers=self.get_rest_headers(), proxies=self.__get_proxies(), verify=False)
     if self.__is_failed_request(r):
         self.__exception_handler(r)
     qr = util.parse_rest_response(r.text)
     for record in qr['records']:
         self.delete_tooling_entity("ApexExecutionOverlayResult", record["Id"])
     return util.generate_success_response("Done")
Example #6
0
    def execute(self):
        """
            Executes requested command
        """
        try:
            self.__setup_connection()

            #if the arg switch argument is included, the request is to launch the out of box
            #MavensMate UI, so we generate the HTML for the UI and launch the process
            #example: mm -o new_project --ui
            if self.args.ui_switch == True:
                config.logger.debug(
                    'UI operation requested, attempting to launch MavensMate UI'
                )
                tmp_html_file = util.generate_ui(self.operation, self.payload,
                                                 self.args)
                if config.connection.plugin_client == 'ATOM':  #returning location of html file here so we can open the page inside an atom panel
                    self.__printr(
                        util.generate_success_response(tmp_html_file))
                else:
                    util.launch_ui(tmp_html_file)
                    self.__printr(
                        util.generate_success_response(
                            'UI Generated Successfully'))

            #non-ui command
            else:
                commands = get_available_commands()
                #debug(commands)
                try:
                    command_clazz = commands[self.operation](
                        params=self.payload, args=self.args)
                except KeyError:
                    raise MMUnsupportedOperationException(
                        'Could not find the operation you requested. Be sure the command is located in mm.commands, inherits from Command (found in basecommand.py) and includes an execute method.'
                    )
                except NotImplementedError:
                    raise MMException(
                        "This command is not properly implemented. Be sure it contains an 'execute' method."
                    )
                self.__printr(command_clazz.execute())
        except Exception, e:
            self.__printr(e, is_exception=True)
Example #7
0
 def delete_debug_logs(self, scope="user"):
     if scope != "user":
         query_string = "Select Id From ApexLog"
     else:
         query_string = "Select Id From ApexLog WHERE LogUserId = '{0}'".format(self.user_id)
     r = requests.get(self.get_tooling_url()+"/query/", params={'q':query_string}, headers=self.get_rest_headers(), proxies=self.__get_proxies(), verify=False)
     if self.__is_failed_request(r):
         self.__exception_handler(r)
     qr = util.parse_rest_response(r.text)
     for record in qr['records']:
         self.delete_tooling_entity("ApexLog", record["Id"])
     return util.generate_success_response("Done")
Example #8
0
 def sign_in_with_github(self, creds):
     try:
         response = github.sign_in(creds)
         if 'message' in response:
             return util.generate_error_response(response['message'])
         elif 'authentication' in response:
             src = open(os.path.join(self.get_app_settings_directory(),'.github.json'), "wb")
             src.write(json.dumps(response, sort_keys=False, indent=4))
             src.close()
             return util.generate_success_response('Connected to GitHub successfully!')
         else:
             return util.generate_error_response(response)
     except Exception, e:
         return util.generate_error_response("Error connecting to GitHub: "+e.message)
Example #9
0
 def sign_in_with_github(self, creds):
     try:
         response = github.sign_in(creds)
         if 'message' in response:
             return util.generate_error_response(response['message'])
         elif 'authentication' in response:
             src = open(
                 os.path.join(self.get_app_settings_directory(),
                              '.github.json'), "wb")
             src.write(json.dumps(response, sort_keys=False, indent=4))
             src.close()
             return util.generate_success_response(
                 'Connected to GitHub successfully!')
         else:
             return util.generate_error_response(response)
     except Exception, e:
         return util.generate_error_response(
             "Error connecting to GitHub: " + e.message)