Ejemplo n.º 1
0
    def run_subl_command(self, command, params):
        if self.plugin_client != self.PluginClients.SUBLIME_TEXT_3:
            raise MMException('unsupported operation')

        if sys.platform == 'darwin':
            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 os.path.exists(os.path.join('{0}/{1}'.format(client_location, plugin_app_name))):
                os.system("'{0}/{1}/Contents/SharedSupport/bin/subl' --command '{2} {3}'".format(client_location, plugin_app_name, command, params))
            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' --command '{1} {2}'".format(client_location, command, params))
            else:
                os.system("'{0}/Sublime Text.app/Contents/SharedSupport/bin/subl' --command '{1} {2}'".format(client_location, command, params))
        elif 'linux' in sys.platform:
            subl_location = self.get_plugin_client_setting('mm_subl_location', '/usr/local/bin/subl')
            os.system("'{0}' --command '{1} {2}'".format(subl_location,os.path.join(self.project.location, command, params)))
        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)")
            params = params.replace('"','\"')
            cmd = '"{0}" --command "{1} {2}"'.format(subl_location,os.path.join(self.project.location, command, params))
            subprocess.call(cmd)
Ejemplo n.º 2
0
    def get_plugin_client_settings(self):
        settings = {}
        user_path = self.get_plugin_settings_path("User")
        def_path = self.get_plugin_settings_path("MavensMate")
        '''
            if the default path for settings is none, we're either dealing with a bad client setup or
            a new client like Atom.io. Let's load the settings from the default cache and optionally allow 
            them to pipe settings in via STDIN
        '''
        if def_path == None:
            if 'ATOM' in self.plugin_client:
                file_name = 'atom'
            elif 'SUBLIME_TEXT' in self.plugin_client:
                file_name = 'st3'
            elif 'BRACKETS' in self.plugin_client:
                file_name = 'brackets'
            settings['default'] = util.parse_json_from_file(
                config.base_path + "/" + config.support_dir + "/config/" +
                file_name + ".json")

            if config.plugin_client_settings != None:
                settings['user'] = config.plugin_client_settings
        else:
            workspace = self.params.get('workspace', None)
            if self.project_name != None and workspace != None:
                try:
                    settings['project'] = util.parse_json_from_file(
                        os.path.join(workspace, self.project_name,
                                     self.project_name + '.sublime-settings'))
                except:
                    debug('Project settings could not be loaded')
            if not user_path == None:
                try:
                    settings['user'] = util.parse_json_from_file(user_path)
                except:
                    debug('User settings could not be loaded')
            if not def_path == None:
                try:
                    settings['default'] = util.parse_json_from_file(def_path)
                except:
                    raise MMException(
                        'Could not load default MavensMate settings.')
        if settings == {}:
            raise MMException(
                'Could not load MavensMate settings. Please ensure they contain valid JSON'
            )
        return settings
Ejemplo n.º 3
0
    def get_workspace(self):
        mm_workspace_path = None
        mm_workspace_setting = self.get_plugin_client_setting('mm_workspace')
        if type(mm_workspace_setting) is list and len(mm_workspace_setting) > 0:
            mm_workspace_path = mm_workspace_setting[0] #grab the first path
        else:
            mm_workspace_path = mm_workspace_setting #otherwise, it's a string, set it
        if mm_workspace_path == None or mm_workspace_path == '':

            raise MMException("Please set mm_workspace to the location where you'd like your mavensmate projects to reside")
        elif not os.path.exists(mm_workspace_path):
            try:
                if mm_workspace_path.startswith('~'):
                    os.makedirs(os.path.expanduser(mm_workspace_path))
                else:
                    os.makedirs(mm_workspace_path)
            except:
                raise MMException("Unable to create mm_workspace location")
        return mm_workspace_path
Ejemplo n.º 4
0
    def get_workspaces(self):
        workspaces = []
        mm_workspace_setting = self.get_plugin_client_setting('mm_workspace')
        if type(mm_workspace_setting) is list and len(mm_workspace_setting) == 0:
            raise MMException("mm_workspace not properly set")

        if type(mm_workspace_setting) is list and len(mm_workspace_setting) > 0:
            workspaces = mm_workspace_setting
        else:
            workspaces = [mm_workspace_setting]
        return workspaces
Ejemplo n.º 5
0
    def __init__(self, params={}, **kwargs):
        params = dict(params.items() + kwargs.items())  #join params and kwargs
        self.params = params

        self.operation = params.get('operation', None)
        if self.operation == None:
            raise MMException('Please specify an operation')

        self.args = params.get('args', None)

        self.plugin_client = params.get(
            'client', None)  #=> "Sublime Text", "Notepad++", "TextMate"
        if self.plugin_client not in self.currently_supported_clients:
            raise MMException('Unsupported plugin client')

        self.project_name = params.get('project_name', None)
        self.project_location = params.get('project_location', None)
        self.plugin_client_settings = self.get_plugin_client_settings()
        '''
            if project location is not specified, set workspace based on workspace param or the first specified in their settings
            if project location is specified, set it based on the directory of the project
        '''
        if self.project_location == None:
            self.workspace = params.get('workspace', self.get_workspace())
        else:
            self.workspace = os.path.dirname(self.project_location)
        '''
            if project name is specified but location isn't, set it
        '''
        if self.project_name != None and self.project_location == None:
            self.project_location = os.path.join(self.workspace,
                                                 self.project_name)

        self.project_id = params.get('project_id', None)
        self.project = None
        self.sfdc_api_version = self.get_sfdc_api_version()
        self.ui = params.get(
            'ui', False
        )  #=> whether this connection was created for the purposes of generating a UI
        self.verbose = params.get('verbose', False)

        if 'wsdl_path' in params:
            util.WSDL_PATH = params.get('wsdl_path')

        self.setup_logging()

        if self.get_plugin_client_setting('mm_timeout', None) != None:
            socket.setdefaulttimeout(
                self.get_plugin_client_setting('mm_timeout'))

        debug('')
        debug('--------------------------------------------')
        debug('---------- NEW OPERATION REQUESTED ---------')
        debug('--------------------------------------------')
        debug('')
        debug(self.operation)
        debug(self.args)
        debug(params)
        debug('')
        debug('--------------------------------------------')

        if self.sfdc_api_version != None:
            util.SFDC_API_VERSION = self.sfdc_api_version  #setting api version based on plugin settings
            util.set_endpoints()

        if self.operation != 'new_project' and self.operation != 'upgrade_project' and self.operation != 'new_project_from_existing_directory' and self.project_location != None:
            if not os.path.exists(os.path.join(self.project_location)):
                raise MMException('Could not find project in workspace: ' +
                                  self.workspace)
            if not os.path.exists(
                    os.path.join(self.project_location, "config",
                                 ".settings")):
                raise MMException(
                    'This does not seem to be a valid MavensMate project, missing config/.settings'
                )
            #if not os.path.exists(os.path.join(self.project_location,"src","package.xml")):
            #    raise MMException('This does not seem to be a valid MavensMate project, missing package.xml')
        if self.project_name != None and self.project_name != '' and not os.path.exists(
                self.project_location
        ) and self.operation != 'new_project_from_existing_directory' and self.operation != 'new_project':
            raise MMException('The project could not be found')
        elif self.project_name != None and self.project_name != '' and os.path.exists(
                os.path.join(
                    self.workspace,
                    self.project_name)) and self.operation == 'new_project':
            raise MMException(
                'A project with this name already exists in your workspace. To create a MavensMate project from an existing non-MavensMate Force.com project, open the project directory in Sublime Text, right click the project name in the sidebar and select "Create MavensMate Project"'
            )
        elif self.project_name != None and self.project_name != '' and os.path.exists(
                os.path.join(self.workspace, self.project_name)
        ) and self.operation != 'new_project_from_existing_directory':
            params['location'] = self.project_location
            params['ui'] = self.ui
Ejemplo n.º 6
0
    def get_retrieve_result(self, params):
        if 'directories' in params and len(
                params['directories']) > 0 and 'files' in params and len(
                    params['files']) > 0:
            raise MMException(
                "Please select either directories or files to refresh, not both"
            )
        elif 'directories' in params and len(params['directories']) > 0:
            metadata = {}
            types = []
            for d in params['directories']:
                basename = os.path.basename(d)
                # refresh all if it's the project base or src directory
                if basename == config.project.project_name or basename == "src":
                    data = util.get_default_metadata_data()
                    if type(data) is dict and 'metadataObjects' in data:
                        data = data['metadataObjects']
                    for item in data:
                        if 'directoryName' in item:
                            types.append(item['xmlName'])
                else:
                    metadata_type = util.get_meta_type_by_dir(basename)
                    if metadata_type:
                        types.append(metadata_type['xmlName'])
                        if 'childXmlNames' in metadata_type:
                            for child in metadata_type['childXmlNames']:
                                types.append(child)

            custom_fields = []
            for val in self.project.get_package_types():
                package_type = val['name']
                members = val['members']
                if package_type not in types:
                    continue

                metadata[package_type] = members

                if package_type == 'CustomObject':
                    for member in members:
                        if members == "*":
                            for item in self.project.get_org_metadata():
                                if item['xmlName'] == 'CustomObject':
                                    for child in item['children']:
                                        if not child['title'].endswith("__c"):
                                            for props in child['children']:
                                                if props['title'] == 'fields':
                                                    for field in props[
                                                            'children']:
                                                        custom_fields.append(
                                                            child['title'] +
                                                            '.' +
                                                            field['title'])
                                                    break
                                            if member != "*":
                                                break
                                    break

                    if len(custom_fields):
                        if 'CustomField' not in metadata:
                            metadata['CustomField'] = []
                        metadata['CustomField'] = list(
                            set(metadata['CustomField'] + custom_fields))

            if len(metadata) == 0:
                raise MMException("Could not find metadata types to refresh")
        elif 'files' in params and len(params['files']) > 0:
            metadata = util.get_metadata_hash(params['files'])
        else:
            raise MMException(
                "Please provide either an array of 'directories' or an array of 'files'"
            )

        #retrieves a fresh set of metadata based on the files that have been requested
        retrieve_result = self.project.sfdc_client.retrieve(package=metadata)
        return retrieve_result