def deploy(bundle_name):
    if '.resource' not in bundle_name:
        bundle_name = bundle_name + '.resource'
    message = 'Bundling and deploying to server: ' + bundle_name
    # delete existing sr
    if os.path.exists(os.path.join(util.mm_project_directory(),"src","staticresources",bundle_name)):
        os.remove(os.path.join(util.mm_project_directory(),"src","staticresources",bundle_name))
    # zip bundle to static resource dir 
    os.chdir(os.path.join(util.mm_project_directory(),"resource-bundles",bundle_name))
    if 'darwin' in sys.platform or 'linux' in sys.platform:
        #cmd = "zip -r -X '"+util.mm_project_directory()+"/src/staticresources/"+bundle_name+"' *"      
        #os.system(cmd)
        zip_file = util.zip_directory(os.path.join(util.mm_project_directory(),"resource-bundles",bundle_name), os.path.join(util.mm_project_directory(),"src","staticresources",bundle_name))
    elif 'win32' in sys.platform:
        zip_file = util.zip_directory(os.path.join(util.mm_project_directory(),"resource-bundles",bundle_name), os.path.join(util.mm_project_directory(),"src","staticresources",bundle_name))
    print(zip_file)
    if zip_file.endswith(".zip"):
        os.rename(zip_file, zip_file[:-4])
    #compile
    file_path = os.path.join(util.mm_project_directory(),"src","staticresources",bundle_name)
    params = {
        "files" : [file_path]
    }
    mm.call('compile', params=params, message=message)
    community.sync_activity('deploy_resource_bundle')
def call(operation, use_mm_panel=True, **kwargs):
    debug('Calling mavensmate adapter')
    debug('OPERATION: '+operation)
    debug(kwargs)

    window, view = util.get_window_and_view_based_on_context(kwargs.get('context', None))

    if operation != 'compile-metadata':
        community.sync_activity(operation)

    threads = []
    thread = MavensMateAdapterCall(
        operation,
        active_file=util.get_active_file(),
        body=kwargs.get('body', None),
        context=kwargs.get('context', None),
        message=kwargs.get('message', None),
        use_mm_panel=use_mm_panel,
        process_id=util.get_random_string(10),
        callback=kwargs.get('callback', None),
        flags=kwargs.get('flags', None)
    )
    if operation == 'index_apex':
        thread.daemon = True
    threads.append(thread)
    thread.start()
Esempio n. 3
0
def call(operation, use_mm_panel=True, **kwargs):
    debug('Calling mavensmate adapter')
    debug('OPERATION: ' + operation)
    debug(kwargs)

    window, view = util.get_window_and_view_based_on_context(
        kwargs.get('context', None))

    if operation != 'compile-metadata':
        community.sync_activity(operation)

    threads = []
    thread = MavensMateAdapterCall(operation,
                                   active_file=util.get_active_file(),
                                   body=kwargs.get('body', None),
                                   context=kwargs.get('context', None),
                                   message=kwargs.get('message', None),
                                   use_mm_panel=use_mm_panel,
                                   process_id=util.get_random_string(10),
                                   callback=kwargs.get('callback', None),
                                   flags=kwargs.get('flags', None))
    if operation == 'index_apex':
        thread.daemon = True
    threads.append(thread)
    thread.start()
def create(self, files, refresh=False):
    for file in files:
        fileName, fileExtension = os.path.splitext(file)
        if fileExtension != '.resource':
            sublime.message_dialog("You can only create resource bundles for static resources")
            return
    
    printer = PanelPrinter.get(self.window.id())
    printer.show()
    if refresh:
        printer.write('\nRefreshing Resource Bundle(s)\n')
    else:
        printer.write('\nCreating Resource Bundle(s)\n')

    if not os.path.exists(os.path.join(util.mm_project_directory(),'resource-bundles')):
        os.makedirs(os.path.join(util.mm_project_directory(),'resource-bundles'))

    for f in files:
        fileName, fileExtension = os.path.splitext(f)
        if sys.platform == "win32":
            baseFileName = fileName.split("\\")[-1]
        else:
            baseFileName = fileName.split("/")[-1]
        if not refresh:
            if os.path.exists(os.path.join(util.mm_project_directory(),'resource-bundles',baseFileName+fileExtension)):
                printer.write('[OPERATION FAILED]: The resource bundle already exists\n')
                return
        if sys.platform == "win32":
            fz = zipfile.ZipFile(f, 'r')
            for fileinfo in fz.infolist():
                path = os.path.join(util.mm_project_directory(),'resource-bundles',baseFileName+fileExtension)
                directories = fileinfo.filename.split('/')
                #directories = fileinfo.filename.split('\\')
                for directory in directories:
                    if directory.startswith('__MACOSX'):
                        continue
                    path = os.path.join(path, directory)
                    if directory == directories[-1]: break # the file
                    if not os.path.exists(path):
                        os.makedirs(path)
                try:
                    outputfile = open(path, "wb")
                    shutil.copyfileobj(fz.open(fileinfo.filename), outputfile)
                except:
                    pass
        else:
            cmd = 'unzip \''+f+'\' -d \''+util.mm_project_directory()+'/resource-bundles/'+baseFileName+fileExtension+'\''
            os.system(cmd)

    printer.write('[Resource bundle creation complete]\n')
    printer.hide()
    community.sync_activity('new_resource_bundle')
Esempio n. 5
0
def deploy(bundle_name):
    if '.resource' not in bundle_name:
        bundle_name = bundle_name + '.resource'
    message = 'Bundling and deploying to server: ' + bundle_name
    # delete existing sr
    if os.path.exists(
            os.path.join(util.mm_project_directory(), "src", "staticresources",
                         bundle_name)):
        os.remove(
            os.path.join(util.mm_project_directory(), "src", "staticresources",
                         bundle_name))
    # zip bundle to static resource dir
    os.chdir(
        os.path.join(util.mm_project_directory(), "resource-bundles",
                     bundle_name))
    if 'darwin' in sys.platform or 'linux' in sys.platform:
        #cmd = "zip -r -X '"+util.mm_project_directory()+"/src/staticresources/"+bundle_name+"' *"
        #os.system(cmd)
        zip_file = util.zip_directory(
            os.path.join(util.mm_project_directory(), "resource-bundles",
                         bundle_name),
            os.path.join(util.mm_project_directory(), "src", "staticresources",
                         bundle_name))
    elif 'win32' in sys.platform:
        zip_file = util.zip_directory(
            os.path.join(util.mm_project_directory(), "resource-bundles",
                         bundle_name),
            os.path.join(util.mm_project_directory(), "src", "staticresources",
                         bundle_name))
    print(zip_file)
    if zip_file.endswith(".zip"):
        os.rename(zip_file, zip_file[:-4])
    #compile
    file_path = os.path.join(util.mm_project_directory(), "src",
                             "staticresources", bundle_name)
    params = {"files": [file_path]}
    mm.call('compile', params=params, message=message)
    community.sync_activity('deploy_resource_bundle')
def call(operation, use_mm_panel=True, **kwargs):
    debug('Calling mm_interface')
    debug('OPERATION: ' + operation)
    debug(kwargs)

    settings = sublime.load_settings('mavensmate.sublime-settings')

    if settings.get("mm_developer_mode", False) and not os.path.isfile(
            settings.get("mm_python_location")):
        active_window_id = sublime.active_window().id()
        printer = PanelPrinter.get(active_window_id)
        printer.show()
        message = '[OPERATION FAILED]: mm_developer_mode is set to true, but we could not find your system python install. Please set the location at mm_python_location'
        printer.write('\n' + message + '\n')
        return
    else:
        if settings.get('mm_path',
                        'default') != 'default' and not os.path.isfile(
                            settings.get('mm_path')):
            active_window_id = sublime.active_window().id()
            printer = PanelPrinter.get(active_window_id)
            printer.show()
            message = '[OPERATION FAILED]: Could not find the mm executable. If you wish to use the default location, ensure your mm_path setting is set to "default", then run MavensMate > Install/Update MavensMate API (mm). If you wish to run mm from a different location, ensure mm_path is pointed to that location on your local drive.'
            printer.write('\n' + message + '\n')
            return

        if sys.platform == 'linux' or sys.platform == 'darwin':
            if settings.get('mm_path',
                            'default') == 'default' and not os.path.isfile(
                                os.path.join(sublime.packages_path(), "User",
                                             "MavensMate", "mm", "mm")):
                active_window_id = sublime.active_window().id()
                printer = PanelPrinter.get(active_window_id)
                printer.show()
                message = '[OPERATION FAILED]: Could not find the mm executable. Please run MavensMate > Install/Update MavensMate API (mm) to install mm to your MavensMate for Sublime Text plugin directory.'
                printer.write('\n' + message + '\n')
                return
        else:
            if settings.get('mm_path',
                            'default') == 'default' and not os.path.isfile(
                                os.path.join(sublime.packages_path(), "User",
                                             "MavensMate", "mm", "mm.exe")):
                active_window_id = sublime.active_window().id()
                printer = PanelPrinter.get(active_window_id)
                printer.show()
                message = '[OPERATION FAILED]: Could not find the mm executable. Please run MavensMate > Install/Update MavensMate API (mm) to install mm to your MavensMate for Sublime Text plugin directory.'
                printer.write('\n' + message + '\n')
                return

    if 'linux' in sys.platform:
        if not os.path.isfile(settings.get('mm_subl_location')):
            active_window_id = sublime.active_window().id()
            printer = PanelPrinter.get(active_window_id)
            printer.show()
            message = '[OPERATION FAILED]: Could not locate Sublime Text "subl" executable. Please set mm_subl_location to location of "subl" on the disk.'
            printer.write('\n' + message + '\n')
            return

    if 'win32' in sys.platform:
        if not os.path.isfile(settings.get('mm_windows_subl_location')):
            active_window_id = sublime.active_window().id()
            printer = PanelPrinter.get(active_window_id)
            printer.show()
            message = '[OPERATION FAILED]: Could not locate Sublime Text. Please set mm_windows_subl_location to location of sublime_text.exe on the disk.'
            printer.write('\n' + message + '\n')
            return

    if not util.valid_workspace():
        active_window_id = sublime.active_window().id()
        printer = PanelPrinter.get(active_window_id)
        printer.show()
        message = '[OPERATION FAILED]: Please ensure mm_workspace is set to existing location(s) on your local drive'
        printer.write('\n' + message + '\n')
        return

    window, view = util.get_window_and_view_based_on_context(
        kwargs.get('context', None))

    #if it's a legacy project, need to intercept the call and open the upgrade ui
    #TODO: this should probably be handled in mm
    if operation != 'new_project' and operation != 'new_project_from_existing_directory' and util.is_project_legacy(
            window) == True:
        operation = 'upgrade_project'

    community.sync_activity(operation)

    threads = []
    thread = MavensMateTerminalCall(operation,
                                    project_name=util.get_project_name(window),
                                    active_file=util.get_active_file(),
                                    params=kwargs.get('params', None),
                                    context=kwargs.get('context', None),
                                    message=kwargs.get('message', None),
                                    use_mm_panel=use_mm_panel,
                                    process_id=util.get_random_string(10),
                                    mm_path=settings.get('mm_path'),
                                    callback=kwargs.get('callback', None))
    if operation == 'index_apex':
        thread.daemon = True
    threads.append(thread)
    thread.start()
Esempio n. 7
0
def create(self, files, refresh=False):
    for file in files:
        fileName, fileExtension = os.path.splitext(file)
        if fileExtension != '.resource':
            sublime.message_dialog(
                "You can only create resource bundles for static resources")
            return

    printer = PanelPrinter.get(self.window.id())
    printer.show()
    if refresh:
        printer.write('\nRefreshing Resource Bundle(s)\n')
    else:
        printer.write('\nCreating Resource Bundle(s)\n')

    if not os.path.exists(
            os.path.join(util.mm_project_directory(), 'resource-bundles')):
        os.makedirs(
            os.path.join(util.mm_project_directory(), 'resource-bundles'))

    for f in files:
        fileName, fileExtension = os.path.splitext(f)
        if sys.platform == "win32":
            baseFileName = fileName.split("\\")[-1]
        else:
            baseFileName = fileName.split("/")[-1]
        if not refresh:
            if os.path.exists(
                    os.path.join(util.mm_project_directory(),
                                 'resource-bundles',
                                 baseFileName + fileExtension)):
                printer.write(
                    '[OPERATION FAILED]: The resource bundle already exists\n')
                return
        if sys.platform == "win32":
            fz = zipfile.ZipFile(f, 'r')
            for fileinfo in fz.infolist():
                path = os.path.join(util.mm_project_directory(),
                                    'resource-bundles',
                                    baseFileName + fileExtension)
                directories = fileinfo.filename.split('/')
                #directories = fileinfo.filename.split('\\')
                for directory in directories:
                    if directory.startswith('__MACOSX'):
                        continue
                    path = os.path.join(path, directory)
                    if directory == directories[-1]: break  # the file
                    if not os.path.exists(path):
                        os.makedirs(path)
                try:
                    outputfile = open(path, "wb")
                    shutil.copyfileobj(fz.open(fileinfo.filename), outputfile)
                except:
                    pass
        else:
            cmd = 'unzip \'' + f + '\' -d \'' + util.mm_project_directory(
            ) + '/resource-bundles/' + baseFileName + fileExtension + '\''
            os.system(cmd)

    printer.write('[Resource bundle creation complete]\n')
    printer.hide()
    community.sync_activity('new_resource_bundle')
def call(operation, use_mm_panel=True, **kwargs):
    debug('Calling mm_interface')
    debug('OPERATION: '+operation)
    debug(kwargs)

    settings = sublime.load_settings('mavensmate.sublime-settings')
    
    if settings.get("mm_developer_mode", False) and not os.path.isfile(settings.get("mm_python_location")):
        active_window_id = sublime.active_window().id()
        printer = PanelPrinter.get(active_window_id)
        printer.show()
        message = '[OPERATION FAILED]: mm_developer_mode is set to true, but we could not find your system python install. Please set the location at mm_python_location'
        printer.write('\n'+message+'\n')
        return
    else:
        if settings.get('mm_path', 'default') != 'default' and not os.path.isfile(settings.get('mm_path')):
            active_window_id = sublime.active_window().id()
            printer = PanelPrinter.get(active_window_id)
            printer.show()
            message = '[OPERATION FAILED]: Could not find the mm executable. If you wish to use the default location, ensure your mm_path setting is set to "default", then run MavensMate > Install/Update MavensMate API (mm). If you wish to run mm from a different location, ensure mm_path is pointed to that location on your local drive.'
            printer.write('\n'+message+'\n')
            return

        if sys.platform == 'linux' or sys.platform == 'darwin':
            if settings.get('mm_path', 'default') == 'default' and not os.path.isfile(os.path.join(sublime.packages_path(),"User","MavensMate","mm","mm")):
                active_window_id = sublime.active_window().id()
                printer = PanelPrinter.get(active_window_id)
                printer.show()
                message = '[OPERATION FAILED]: Could not find the mm executable. Please run MavensMate > Install/Update MavensMate API (mm) to install mm to your MavensMate for Sublime Text plugin directory.'
                printer.write('\n'+message+'\n')
                return
        else:
            if settings.get('mm_path', 'default') == 'default' and not os.path.isfile(os.path.join(sublime.packages_path(),"User","MavensMate","mm","mm.exe")):
                active_window_id = sublime.active_window().id()
                printer = PanelPrinter.get(active_window_id)
                printer.show()
                message = '[OPERATION FAILED]: Could not find the mm executable. Please run MavensMate > Install/Update MavensMate API (mm) to install mm to your MavensMate for Sublime Text plugin directory.'
                printer.write('\n'+message+'\n')
                return 

    if 'linux' in sys.platform:
        if not os.path.isfile(settings.get('mm_subl_location')):
            active_window_id = sublime.active_window().id()
            printer = PanelPrinter.get(active_window_id)
            printer.show()
            message = '[OPERATION FAILED]: Could not locate Sublime Text "subl" executable. Please set mm_subl_location to location of "subl" on the disk.'
            printer.write('\n'+message+'\n')
            return

    if 'win32' in sys.platform:
        if not os.path.isfile(settings.get('mm_windows_subl_location')):
            active_window_id = sublime.active_window().id()
            printer = PanelPrinter.get(active_window_id)
            printer.show()
            message = '[OPERATION FAILED]: Could not locate Sublime Text. Please set mm_windows_subl_location to location of sublime_text.exe on the disk.'
            printer.write('\n'+message+'\n')
            return

    if not util.valid_workspace():
        active_window_id = sublime.active_window().id()
        printer = PanelPrinter.get(active_window_id)
        printer.show()
        message = '[OPERATION FAILED]: Please ensure mm_workspace is set to existing location(s) on your local drive'
        printer.write('\n'+message+'\n')
        return

    window, view = util.get_window_and_view_based_on_context(kwargs.get('context', None))

    #if it's a legacy project, need to intercept the call and open the upgrade ui
    #TODO: this should probably be handled in mm
    if operation != 'new_project' and operation != 'new_project_from_existing_directory' and util.is_project_legacy(window) == True:
        operation = 'upgrade_project'
    
    community.sync_activity(operation)

    threads = []
    thread = MavensMateTerminalCall(
        operation, 
        project_name=util.get_project_name(window), 
        active_file=util.get_active_file(), 
        params=kwargs.get('params', None),
        context=kwargs.get('context', None),
        message=kwargs.get('message', None),
        use_mm_panel=use_mm_panel,
        process_id=util.get_random_string(10),
        mm_path=settings.get('mm_path'),
        callback=kwargs.get('callback', None)
    )
    if operation == 'index_apex':
        thread.daemon = True
    threads.append(thread)        
    thread.start()