コード例 #1
0
ファイル: mm_connection.py プロジェクト: vazexqi/mm
    def new_project(self, params, **kwargs):
        try:
            if 'username' not in params or params['username'] == '':
                return mm_util.generate_error_response('Please specify a username')
            if 'password' not in params or params['password'] == '':
                return mm_util.generate_error_response('Please specify a password')
            if 'project_name' not in params or params['project_name'] == '':
                return mm_util.generate_error_response('Please specify a project name')

            if ('action' in kwargs and kwargs['action'] == 'new') or 'action' not in kwargs:
                if 'package' not in params or params['package'] == []:
                    params['package'] = {
                        'ApexClass'         : '*',
                        'ApexComponent'     : '*',
                        'ApexPage'          : '*',
                        'ApexTrigger'       : '*',
                        'StaticResource'    : '*'
                    }
                self.project = MavensMateProject(params)
                result = self.project.retrieve_and_write_to_disk()
            elif 'action' in kwargs and kwargs['action'] == 'existing':
                self.project = MavensMateProject(params)
                result = self.project.retrieve_and_write_to_disk('existing')

            if json.loads(result)['success'] == True and self.get_plugin_client_setting('mm_open_project_on_create', True):
                #opens project based on the client
                client_location = self.get_plugin_client_setting('mm_plugin_client_location')
                plugin_app_name = self.get_plugin_client_setting('mm_osx_plugin_client_app_name') 
                if client_location == None:
                    client_location = '/Applications'
                if plugin_app_name == None:
                    plugin_app_name = 'Sublime Text 3.app'
                if self.plugin_client == self.PluginClients.SUBLIME_TEXT_2:
                    if self.platform == 'darwin':
                        os.system("'{0}/Sublime Text 2.app/Contents/SharedSupport/bin/subl' --project '{1}'".format(client_location,self.project.location+"/"+self.project.project_name+".sublime-project"))
                elif self.plugin_client == self.PluginClients.SUBLIME_TEXT_3:
                    if self.platform == 'darwin':
                        if os.path.exists(os.path.join('{0}/{1}'.format(client_location, plugin_app_name))):
                            os.system("'{0}/{1}/Contents/SharedSupport/bin/subl' --project '{2}'".format(client_location,plugin_app_name,self.project.location+"/"+self.project.project_name+".sublime-project"))
                        elif os.path.exists(os.path.join('{0}/Sublime Text 3.app'.format(client_location))):
                            os.system("'{0}/Sublime Text 3.app/Contents/SharedSupport/bin/subl' --project '{1}'".format(client_location,self.project.location+"/"+self.project.project_name+".sublime-project"))
                        else:
                            os.system("'{0}/Sublime Text.app/Contents/SharedSupport/bin/subl' --project '{1}'".format(client_location,self.project.location+"/"+self.project.project_name+".sublime-project"))
                    elif 'linux' in self.platform:
                        subl_location = self.get_plugin_client_setting('mm_subl_location', '/usr/local/bin/subl')
                        os.system("'{0}' --project '{1}'".format(subl_location,os.path.join(self.project.location,self.project.project_name+".sublime-project")))
                    else:
                        subl_location = self.get_plugin_client_setting('mm_windows_subl_location')
                        if not os.path.isfile(subl_location) and "x86" not in subl_location:
                            subl_location = subl_location.replace("Program Files", "Program Files (x86)")
                        cmd = '"{0}" --project "{1}"'.format(subl_location,os.path.join(self.project.location,self.project.project_name+".sublime-project"))
                        subprocess.call(cmd)


            return result
        except BaseException, e:
            return mm_util.generate_error_response(e.message)
コード例 #2
0
    def new_project(self, params, **kwargs):
        try:
            if 'username' not in params or params['username'] == '':
                return mm_util.generate_error_response(
                    'Please specify a username')
            if 'password' not in params or params['password'] == '':
                return mm_util.generate_error_response(
                    'Please specify a password')
            if 'project_name' not in params or params['project_name'] == '':
                return mm_util.generate_error_response(
                    'Please specify a project name')

            if ('action' in kwargs
                    and kwargs['action'] == 'new') or 'action' not in kwargs:
                if 'package' not in params or params['package'] == []:
                    params['package'] = {
                        'ApexClass': '*',
                        'ApexComponent': '*',
                        'ApexPage': '*',
                        'ApexTrigger': '*',
                        'StaticResource': '*'
                    }
                self.project = MavensMateProject(params)
                result = self.project.retrieve_and_write_to_disk()
            elif 'action' in kwargs and kwargs['action'] == 'existing':
                self.project = MavensMateProject(params)
                result = self.project.retrieve_and_write_to_disk('existing')

            if json.loads(result)['success'] == True:
                if self.platform == 'linux2':
                    os.system("'" + self.sublime + "' --project '{0}'".format(
                        self.project.location + "/" +
                        self.project.project_name + ".sublime-project"))
                elif self.platform == 'darwin':
                    if self.plugin_client == self.PluginClients.SUBLIME_TEXT_2:
                        os.system(
                            "'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl' --project '{0}'"
                            .format(self.project.location + "/" +
                                    self.project.project_name +
                                    ".sublime-project"))
                    elif self.plugin_client == self.PluginClients.SUBLIME_TEXT_3:
                        os.system(
                            "'/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl' --project '{0}'"
                            .format(self.project.location + "/" +
                                    self.project.project_name +
                                    ".sublime-project"))

            return result
        except BaseException, e:
            return mm_util.generate_error_response(e.message)
コード例 #3
0
ファイル: mm_connection.py プロジェクト: e-bacho/mm
 def sign_in_with_github(self, creds):
     try:
         response = mm_github.sign_in(creds)
         if 'message' in response:
             return mm_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 mm_util.generate_success_response('Connected to GitHub successfully!')
         else:
             return mm_util.generate_error_response(response)
     except Exception, e:
         return mm_util.generate_error_response("Error connecting to GitHub: "+e.message)
コード例 #4
0
    def new_project(self, params, **kwargs):
        try:
            if 'username' not in params or params['username'] == '':
                return mm_util.generate_error_response('Please specify a username')
            if 'password' not in params or params['password'] == '':
                return mm_util.generate_error_response('Please specify a password')
            if 'project_name' not in params or params['project_name'] == '':
                return mm_util.generate_error_response('Please specify a project name')

            if ('action' in kwargs and kwargs['action'] == 'new') or 'action' not in kwargs:
                if 'package' not in params or params['package'] == []:
                    params['package'] = {
                        'ApexClass'         : '*',
                        'ApexComponent'     : '*',
                        'ApexPage'          : '*',
                        'ApexTrigger'       : '*',
                        'StaticResource'    : '*'
                    }
                self.project = MavensMateProject(params)
                result = self.project.retrieve_and_write_to_disk()
            elif 'action' in kwargs and kwargs['action'] == 'existing':
                self.project = MavensMateProject(params)
                result = self.project.retrieve_and_write_to_disk('existing')

            if json.loads(result)['success'] == True:
                #opens project based on the client
                client_location = self.get_plugin_client_setting('mm_plugin_client_location')
                if client_location == None:
                    client_location = '/Applications'
                if self.plugin_client == self.PluginClients.SUBLIME_TEXT_2:
                    if self.platform == 'darwin':
                        os.system("'{0}/Sublime Text 2.app/Contents/SharedSupport/bin/subl' --project '{1}'".format(client_location,self.project.location+"/"+self.project.project_name+".sublime-project"))
                elif self.plugin_client == self.PluginClients.SUBLIME_TEXT_3:
                    if self.platform == 'darwin':
                        os.system("'{1}/Sublime Text 3.app/Contents/SharedSupport/bin/subl' --project '{1}'".format(client_location,self.project.location+"/"+self.project.project_name+".sublime-project"))

            return result
        except BaseException, e:
            return mm_util.generate_error_response(e.message)
コード例 #5
0
ファイル: mm_client.py プロジェクト: e-bacho/mm
    def compile_with_tooling_api(self, files, container_id):
        for file_path in files:
            payload = {}
            file_name = file_path.split('.')[0]
            file_name = mm_util.get_file_name_no_extension(file_path)
            metadata_def = mm_util.get_meta_type_by_suffix(file_path.split('.')[-1])
            metadata_type = metadata_def['xmlName']
            if metadata_type == 'ApexPage':
                tooling_type = 'ApexPageMember'
            elif metadata_type == 'ApexComponent':
                tooling_type = 'ApexComponentMember'
            elif metadata_type == 'ApexClass':
                tooling_type = 'ApexClassMember'
            elif metadata_type == 'ApexTrigger':
                tooling_type = 'ApexTriggerMember'

            #create/submit "member"
            payload['MetadataContainerId']  = container_id
            payload['ContentEntityId']      = self.get_apex_entity_id_by_name(object_type=metadata_type, name=file_name)
            payload['Body']                 = open(file_path, 'r').read()
            #payload['LastSyncDate']         = TODO
            payload = json.dumps(payload)
            config.logger.debug(payload)
            r = requests.post(self.get_tooling_url()+"/sobjects/"+tooling_type, data=payload, headers=self.get_rest_headers('POST'), proxies=urllib.getproxies(), verify=False)
            response = mm_util.parse_rest_response(r.text)
            
            #if it's a dup (probably bc we failed to delete before, let's delete and retry)
            if type(response) is list and 'errorCode' in response[0]:
                if response[0]['errorCode'] == 'DUPLICATE_VALUE':
                    dup_id = response[0]['message'].split(':')[-1]
                    dup_id = dup_id.strip()
                    query_string = "Select Id from "+tooling_type+" Where Id = '"+dup_id+"'"
                    r = requests.get(self.get_tooling_url()+"/query/", params={'q':query_string}, headers=self.get_rest_headers(), proxies=urllib.getproxies(), verify=False)
                    r.raise_for_status()
                    query_result = mm_util.parse_rest_response(r.text)
                    
                    r = requests.delete(self.get_tooling_url()+"/sobjects/{0}/{1}".format(tooling_type, query_result['records'][0]['Id']), headers=self.get_rest_headers(), proxies=urllib.getproxies(), verify=False)
                    r.raise_for_status()

                    #retry member request
                    r = requests.post(self.get_tooling_url()+"/sobjects/"+tooling_type, data=payload, headers=self.get_rest_headers('POST'), proxies=urllib.getproxies(), verify=False)
                    response = mm_util.parse_rest_response(r.text)
                    member_id = response['id']
                elif response[0]['errorCode'] == 'INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY' or response[0]['errorCode'] == 'MALFORMED_ID':
                    raise MetadataContainerException('Invalid metadata container')
                else:
                    return mm_util.generate_error_response(response[0]['errorCode'])
            else:
                member_id = response['id']

        #ok, now we're ready to submit an async request
        payload = {}
        payload['MetadataContainerId'] = container_id
        payload['IsCheckOnly'] = False
        payload['IsRunTests'] = False
        payload = json.dumps(payload)
        config.logger.debug(payload)
        r = requests.post(self.get_tooling_url()+"/sobjects/ContainerAsyncRequest", data=payload, headers=self.get_rest_headers('POST'), proxies=urllib.getproxies(), verify=False)
        response = mm_util.parse_rest_response(r.text)

        finished = False
        while finished == False:
            time.sleep(1)
            query_string = "Select Id, MetadataContainerId, MetadataContainerMemberId, State, IsCheckOnly, CompilerErrors, ErrorMsg FROM ContainerAsyncRequest WHERE Id='"+response["id"]+"'"
            r = requests.get(self.get_tooling_url()+"/query/", params={'q':query_string}, headers=self.get_rest_headers(), proxies=urllib.getproxies(), verify=False)
            r.raise_for_status()
            query_result = mm_util.parse_rest_response(r.text)
            if query_result["done"] == True and query_result["size"] == 1 and 'records' in query_result:
                if query_result['records'][0]["State"] != 'Queued':
                    response = query_result['records'][0]
                    finished = True

        #clean up the apex member
        if 'id' in response:
            #delete member
            r = requests.delete(self.get_tooling_url()+"/sobjects/{0}/{1}".format(tooling_type, member_id), headers=self.get_rest_headers(), proxies=urllib.getproxies(), verify=False)
            r.raise_for_status()

        return response