Exemple #1
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)
Exemple #2
0
    def __init__(self, params={}, **kwargs):
        config.connection = self
        params = dict(params.items() + kwargs.items())
        self.operation              = params.get('operation', None)
        self.platform               = sys.platform
        self.plugin_client          = params.get('client', 'SUBLIME_TEXT_2') #=> "Sublime Text", "Notepad++", "TextMate"
        if self.plugin_client not in self.currently_supported_clients:
            self.plugin_client = 'SUBLIME_TEXT_2'
        self.plugin_client_version  = params.get('client_version', '2.0.1') #=> "1.0", "1.1.1", "v1"
        self.plugin_client_settings = self.get_plugin_client_settings()
        self.workspace              = self.get_workspace()
        self.project_name           = params.get('project_name', None)
        self.project_location       = None
        if self.project_name != 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
        if 'wsdl_path' in params:
            mm_util.WSDL_PATH = params.get('wsdl_path')

        self.setup_logging()

        if self.sfdc_api_version != None:
            mm_util.SFDC_API_VERSION = self.sfdc_api_version #setting api version based on plugin settings

        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(self.workspace+"/"+self.project_name) and self.operation != 'new_project_from_existing_directory':
            params['location'] = self.project_location
            params['ui'] = self.ui
            self.project = MavensMateProject(params)