예제 #1
0
    def _fillRightBottomOutputLogPanel(self, panel):
        """ Create and fill the output log with two tabs(plugin.log and
        plugin.err)"""
        # Fill the Output Log
        gui.configureWeigths(panel)
        self.terminal = tk.Frame(panel)
        self.terminal.grid(row=0, column=0, sticky='news')
        gui.configureWeigths(self.terminal)

        self.Textlog = TextFileViewer(self.terminal, font='black')
        self.Textlog.grid(row=0, column=0, sticky='news')

        self.file_log_path = os.path.join(os.environ['SCIPION_LOGS'],
                                          PLUGIN_LOG_NAME)
        self.file_errors_path = os.path.join(os.environ['SCIPION_LOGS'],
                                             PLUGIN_ERRORS_LOG_NAME)

        self.fileLog = open(self.file_log_path, 'w', 0)
        self.fileLogErr = open(self.file_errors_path, 'w', 0)
        self.plug_log = ScipionLogger(self.file_log_path)
        self.plug_errors_log = ScipionLogger(self.file_errors_path)
예제 #2
0

"""

import os
import errno
#import paramiko

from pyworkflow.utils.path import dirname, makeFilePath, join, isdir, isfile
from pyworkflow.utils.log import ScipionLogger

LOCAL_USER_AND_HOST = ''
SSH_PORT = 22
PAIRS_SEPARATOR = ':'

log = ScipionLogger()


def testHostConfig(host):
    """ Test the connection to a remote host give its configuration.(see HostConfig class)
    Params:
        host: configuration of the remote host, should contains hostName, userName and password.
    Returns: True if the host could be reached.
    """
    try:
        ssh = sshConnectFromHost(host)
        rpath = RemotePath(ssh)
        rpath.listdir('.')
        rpath.close()
        return True
    except Exception, ex:
예제 #3
0
class PluginBrowser(tk.Frame):
    """ This class will implement a frame.
        It will display a list of plugin at the left
        panel. A TreeProvider will be used to populate the list (Tree).
        At the right panel provide a plugin/binary information(top panel) and
        a list of operation (bottom panel)
        """
    def __init__(self, master, **args):
        tk.Frame.__init__(self, master, **args)
        self._lastSelected = None
        self.operationList = OperationList()
        gui.configureWeigths(self)

        # Creating the layout where all application elements will be placed
        parentFrame = tk.Frame(master)
        parentFrame.grid(row=0, column=0, sticky='news')
        gui.configureWeigths(parentFrame, 1)

        self._lunchProgressBar(master)
        self._fillPluginManagerGui(parentFrame)

    def _lunchProgressBar(self, parent):
        self.progressbarLabel = ttk.Label(parent,
                                          text='Loading Plugins...',
                                          background='white')
        self.progressbarLabel.place(x=450, y=65, width=200)
        self.progressbar = ttk.Progressbar(parent)
        self.progressbar.place(x=450, y=80, width=200)
        self.progressbar.step(1)
        self.progressbar.start(200)

    def _closeProgressBar(self):
        self.progressbar.stop()
        self.progressbar.destroy()
        self.progressbarLabel.destroy()

    def _fillPluginManagerGui(self, parentFrame):
        """
        Fill the Plugin Manager GUI
        """
        # The main layout will be two panes:
        # At the left containing the plugin list
        # and the right containing a description and the operation list
        mainFrame = tk.PanedWindow(parentFrame, orient=tk.HORIZONTAL)
        mainFrame.grid(row=1, column=0, sticky='news')
        # ---------------------------------------------------------------
        # Left Panel
        leftPanel = tk.Frame(mainFrame)  # Create a left panel to put the tree
        leftPanel.grid(row=0, column=0, padx=0, pady=0, sticky='news')
        self._fillLeftPanel(leftPanel)  # Fill the left panel

        # ---------------------------------------------------------------
        # Right Panel: will be two vertical panes
        # At the Top contain the plugin or binary information
        # At the Bottom contain a tab widget with an operation list and
        # a system terminal that show the operation steps
        rightPanel = tk.PanedWindow(mainFrame, orient=tk.VERTICAL)
        rightPanel.grid(row=0, column=1, padx=0, pady=0, sticky='news')

        # Top Panel
        # Panel to put the plugin information
        topPanel = ttk.Frame(rightPanel)
        topPanel.pack(side=TOP, fill=BOTH, expand=Y)
        topPanel.configure(cursor='hand1')
        self._createRightTopPanel(topPanel)

        # Bottom Panel
        # This section show the plugin operation and a console
        bottomPanel = ttk.Frame(rightPanel)
        tabControl = ttk.Notebook(bottomPanel)  # Create Tab Control
        tabControl.grid(row=1, column=0, sticky='news')

        operationTab = ttk.Frame(tabControl)  # Create a operation tab
        operationTab.grid(row=0, column=0, padx=0, pady=0)
        self._fillRightBottomOperationsPanel(operationTab)
        consoleTab = ttk.Frame(tabControl)  # Create a console
        self._fillRightBottomOutputLogPanel(consoleTab)

        tabControl.add(operationTab,
                       text='Operations')  # Add the Operation tab
        tabControl.add(consoleTab, text='Output Log')
        tabControl.pack(expand=1, fill="both")  # Pack to make visible

        # Add the widgets to Right Panel
        rightPanel.add(topPanel, padx=0, pady=0)
        rightPanel.add(bottomPanel, padx=0, pady=0)

        # Add the Plugin list at left
        mainFrame.add(leftPanel, padx=0, pady=0)
        mainFrame.paneconfig(leftPanel, minsize=200)

        # Add the Plugins or Binaries information and Operation list at right
        mainFrame.add(rightPanel, padx=0, pady=0)
        mainFrame.paneconfig(rightPanel, minsize=200)

    def _fillToolbar(self, frame):
        """ Fill the toolbar frame with some buttons. """
        self._col = 0
        self.executeOpsBtn = self._addButton(
            frame, '', Icon.TO_INSTALL,
            Message.EXECUTE_PLUGINS_MANAGER_OPERATION, 'disable',
            self._applyAllOperations)
        self.cancelOpsBtn = self._addButton(frame, '', Icon.DELETE_OPERATION,
                                            Message.CANCEL_SELECTED_OPERATION,
                                            'disable',
                                            self._deleteSelectedOperation)

        tk.Label(frame, text='Number of processors:').grid(row=0,
                                                           column=self._col,
                                                           padx=5)
        self._col += 1
        self.numberProcessors = tk.StringVar()
        self.numberProcessors.set('4')
        processorsEntry = tk.Entry(frame, textvariable=self.numberProcessors)
        processorsEntry.grid(row=0, column=self._col, sticky='ew', padx=5)

    def _addButton(self, frame, text, image, tooltip, state, command):
        btn = IconButton(frame,
                         text,
                         image,
                         command=command,
                         tooltip=tooltip,
                         bg=None)
        btn.config(relief="flat",
                   activebackground=None,
                   compound='left',
                   fg='black',
                   overrelief="raised",
                   state=state)
        btn.bind('<Button-1>', command)
        btn.grid(row=0, column=self._col, sticky='nw', padx=3, pady=7)
        self._col += 1
        return btn

    def _fillLeftPanel(self, leftFrame):
        """
        Fill the left Panel with the plugins list
        """
        gui.configureWeigths(leftFrame)
        self.tree = PluginTree(leftFrame, show="tree")
        self.tree.grid(row=0, column=0, sticky='news')

        self.yscrollbar = ttk.Scrollbar(leftFrame,
                                        orient='vertical',
                                        command=self.tree.yview)
        self.yscrollbar.grid(row=0, column=1, sticky='news')
        self.tree.configure(yscrollcommand=self.yscrollbar.set)
        self.yscrollbar.configure(command=self.tree.yview)

        # check / uncheck boxes(plugin or binary) on right click
        self.tree.bind("<Button-1>", self._onPluginTreeClick, True)

        # add a popup menu to update a selected plugin
        self.popup_menu = tk.Menu(self.tree, tearoff=0)
        self.popup_menu.add_command(label="Update ",
                                    underline=0,
                                    image=self.tree.im_to_update,
                                    compound=tk.LEFT,
                                    command=self._updatePlugin)

        self.popup_menu.add_command(label="Install",
                                    underline=1,
                                    image=self.tree.im_install,
                                    compound=tk.LEFT,
                                    command=self._treeOperation)

        self.popup_menu.add_command(label="Uninstall",
                                    underline=2,
                                    image=self.tree.im_uninstall,
                                    compound=tk.LEFT,
                                    command=self._treeOperation)

        self.popup_menu.add_separator()

        self.popup_menu.add_command(label="Undo",
                                    underline=4,
                                    image=self.tree.im_undo,
                                    compound=tk.LEFT,
                                    command=self._treeOperation)

        self.tree.bind("<Button-3>", self._popup)  # Button-3 on Plugin
        self.tree.bind("<FocusOut>", self._popupFocusOut)

        # Load all plugins and fill the tree view
        threadLoadPlugin = threading.Thread(name="loading_plugin",
                                            target=self.loadPlugins)
        threadLoadPlugin.start()

    def _popup(self, event):
        try:
            x, y, widget = event.x, event.y, event.widget
            self.tree.selectedItem = self.tree.identify_row(y)
            self.popup_menu.selection = self.tree.set(
                self.tree.identify_row(event.y))
            tags = self.tree.item(self.tree.selectedItem, "tags")
            self.popup_menu.entryconfigure(0, state=tk.DISABLED)
            self.popup_menu.entryconfigure(1, state=tk.DISABLED)
            self.popup_menu.entryconfigure(2, state=tk.DISABLED)
            self.popup_menu.entryconfigure(4, state=tk.DISABLED)
            # Activate the menu if the new plugin release is available
            if tags[0] == PluginStates.AVAILABLE_RELEASE:
                self.popup_menu.entryconfigure(0, state=tk.NORMAL)
            elif tags[0] == PluginStates.CHECKED:
                self.popup_menu.entryconfigure(2, state=tk.NORMAL)
            elif tags[0] == PluginStates.UNCHECKED:
                self.popup_menu.entryconfigure(1, state=tk.NORMAL)
            else:
                self.popup_menu.entryconfigure(4, state=tk.NORMAL)

            self.popup_menu.post(event.x_root, event.y_root)
        finally:
            self.popup_menu.grab_release()

    def _popupFocusOut(self, event=None):
        self.popup_menu.unpost()

    def _updatePlugin(self):
        objType = self.tree.item(self.tree.selectedItem, "value")
        parent = self.tree.parent(self.tree.selectedItem)
        operation = Operation(self.tree.selectedItem, objType[0],
                              PluginStates.TO_UPDATE, parent)
        self.operationList.insertOperation(operation)
        self.tree.update_item(self.tree.selectedItem)
        children = self.tree.get_children(self.tree.selectedItem)
        for iid in children:
            self.deleteOperation(iid)
            self.tree.delete(iid)
        self.showOperationList()
        self.executeOpsBtn.config(state='normal')

    def _treeOperation(self):
        tags = self.tree.item(self.tree.selectedItem, "tags")
        objType = self.tree.item(self.tree.selectedItem, "value")
        parent = self.tree.parent(self.tree.selectedItem)
        operation = Operation(self.tree.selectedItem, objType[0], tags[0],
                              parent)
        self.operationList.insertOperation(operation)
        if tags[0] == PluginStates.UNCHECKED:
            self.tree.check_item(self.tree.selectedItem)
        elif tags[0] == PluginStates.UNINSTALL:
            if objType[0] == PluginStates.PLUGIN:
                self.reloadInstalledPlugin(self.tree.selectedItem)
            else:
                self.tree.check_item(self.tree.selectedItem)
        elif tags[0] == PluginStates.TO_UPDATE:
            self.tree.check_item(self.tree.selectedItem)
            self.reloadInstalledPlugin(self.tree.selectedItem)
        else:
            children = self.tree.get_children(self.tree.selectedItem)
            for iid in children:
                self.deleteOperation(iid)
            self.tree.uncheck_item(self.tree.selectedItem)
        self.showPluginInformation(self.tree.selectedItem)
        self.cancelOpsBtn.config(state='disable')
        self.showOperationList()

    def _createRightTopPanel(self, topPanel):
        """
        Create a right top panel
        """
        self.topPanelTree = ttk.Treeview(topPanel, show='tree', cursor='hand2')
        self.topPanelTree.grid(row=0, column=0, sticky='news')

        # configure vertical scroollbar
        ysb = ttk.Scrollbar(topPanel,
                            orient='vertical',
                            command=self.topPanelTree.yview)
        ysb.grid(row=0, column=1, sticky='news')
        self.topPanelTree.configure(yscrollcommand=ysb.set)
        ysb.configure(command=self.topPanelTree.yview)
        xsb = ttk.Scrollbar(topPanel,
                            orient='horizontal',
                            command=self.topPanelTree.yview)
        xsb.grid(row=1, column=0, sticky='news')
        self.topPanelTree.configure(xscrollcommand=xsb.set)
        xsb.configure(command=self.topPanelTree.xview)
        topPanel.rowconfigure(0, weight=1)
        topPanel.columnconfigure(0, weight=1)
        self.topPanelTree.bind("<Button-1>", self.linkToWebSite, True)

    def _fillRightBottomOperationsPanel(self, panel):
        """
        Create the Operations Tab
        """
        gui.configureWeigths(panel)
        # Define a Tool Bar
        opPanel = tk.Frame(panel)
        opPanel.grid(row=0, column=0, sticky='news')
        gui.configureWeigths(opPanel, 1)

        toolBarFrame = tk.Frame(opPanel)
        toolBarFrame.grid(row=0, column=0, sticky=W)
        self._fillToolbar(toolBarFrame)
        gui.configureWeigths(toolBarFrame)

        # Fill the operation tab
        self.operationTree = PluginTree(opPanel, show="tree")
        self.operationTree.grid(row=1, column=0, sticky='news')
        yscrollbar = ttk.Scrollbar(opPanel,
                                   orient='vertical',
                                   command=self.operationTree.yview)
        yscrollbar.grid(row=1, column=1, sticky='news')
        self.operationTree.configure(yscrollcommand=yscrollbar.set)
        yscrollbar.configure(command=self.operationTree.yview)
        self.operationTree.bind("<Button-1>", self.operationInformation, True)

    def _fillRightBottomOutputLogPanel(self, panel):
        """ Create and fill the output log with two tabs(plugin.log and
        plugin.err)"""
        # Fill the Output Log
        gui.configureWeigths(panel)
        self.terminal = tk.Frame(panel)
        self.terminal.grid(row=0, column=0, sticky='news')
        gui.configureWeigths(self.terminal)

        self.Textlog = TextFileViewer(self.terminal, font='black')
        self.Textlog.grid(row=0, column=0, sticky='news')

        self.file_log_path = os.path.join(os.environ['SCIPION_LOGS'],
                                          PLUGIN_LOG_NAME)
        self.file_errors_path = os.path.join(os.environ['SCIPION_LOGS'],
                                             PLUGIN_ERRORS_LOG_NAME)

        self.fileLog = open(self.file_log_path, 'w', 0)
        self.fileLogErr = open(self.file_errors_path, 'w', 0)
        self.plug_log = ScipionLogger(self.file_log_path)
        self.plug_errors_log = ScipionLogger(self.file_errors_path)

    def _onPluginTreeClick(self, event):
        """ check or uncheck a plugin or binary box when clicked """
        if self.tree.is_enabled():
            self.popup_menu.unpost()
            x, y, widget = event.x, event.y, event.widget
            elem = widget.identify("element", x, y)
            self.tree.selectedItem = self.tree.identify_row(y)
            if "image" in elem:
                # a box was clicked
                self._treeOperation()
            else:
                if self.tree.selectedItem is not None:
                    if self.isPlugin(
                            self.tree.item(self.tree.selectedItem,
                                           "values")[0]):
                        self.showPluginInformation(self.tree.selectedItem)
                    else:
                        parent = self.tree.parent(self.tree.selectedItem)
                        self.showPluginInformation(parent)
            if len(self.operationList.getOperations(None)):
                self.executeOpsBtn.config(state='normal')
            else:
                self.executeOpsBtn.config(state='disable')

    def _deleteSelectedOperation(self, e=None):
        """
        Delete a selected operation
        """
        if self.operationTree.selectedItem:
            item = self.operationTree.selectedItem
            operation = self.operationList.getOperationByName(item)
            index = self.operationList.operationIndex(operation)
            if index is not None:
                self.operationList.removeOperation(index)
                self.showOperationList()
                if PluginStates.INSTALL in self.tree.item(item, 'tags'):
                    self.tree.item(self.operationTree.selectedItem,
                                   tags=(PluginStates.UNCHECKED, ))
                else:
                    if operation.getObjType() == PluginStates.PLUGIN:
                        self.reloadInstalledPlugin(item)
                    else:
                        self.reloadInstalledPlugin(self.tree.parent(item))
                self.operationTree.selectedItem = None
                self.cancelOpsBtn.config(state='disable')
                if not len(self.operationList.getOperations(None)):
                    self.executeOpsBtn.config(state='disable')

    def _applyAllOperations(self, event=None):
        """
        Execute the operation list
        """
        # Disable the execute and cancel button
        self.executeOpsBtn.config(state='disable')
        self.cancelOpsBtn.config(state='disable')
        # Disable the TreeView
        self.tree.disable()
        # Create two tabs where the log and errors will appears
        self.Textlog.createWidgets([self.file_log_path, self.file_errors_path])
        if event is not None:
            self.threadOp = threading.Thread(name="plugin-manager",
                                             target=self._applyOperations,
                                             args=(None, ))
            self.threadOp.start()

            self.threadRefresh = threading.Thread(
                name="refresh_log",
                target=self._refreshLogsComponent,
                args=(3, ))
            self.threadRefresh.start()

    def _refreshLogsComponent(self, wait=3):
        """
        Refresh the Plugin Manager log
        """
        import time
        while self.threadOp.isAlive():
            time.sleep(wait)
            self.Textlog.refreshAll(goEnd=True)

    def _applyOperations(self, operation=None):
        """
        Execute one operation. If operation is None, then execute the operation
        list
        """
        # Take the standard system out and errors
        oldstdout = sys.stdout
        oldstderr = sys.stderr
        sys.stdout = self.fileLog
        sys.stderr = self.fileLogErr
        strErr = None
        defaultModeMessage = 'Executing...'

        message = pwgui.FloatingMessage(self.operationTree,
                                        defaultModeMessage,
                                        xPos=300,
                                        yPos=20)
        message.show()
        for op in self.operationList.getOperations(operation):
            item = op.getObjName()
            try:
                self.operationTree.processing_item(item)
                self.operationTree.update()
                op.runOperation(self.numberProcessors.get())
                self.operationTree.installed_item(item)
                self.operationTree.update()
                self.Textlog.refreshAll(goEnd=True)
                self.Textlog.update()
                if (op.getObjStatus() == PluginStates.INSTALL
                        or op.getObjStatus() == PluginStates.TO_UPDATE):
                    if op.getObjType() == PluginStates.PLUGIN:
                        self.reloadInstalledPlugin(item)
                    else:
                        self.tree.check_item(item)
                else:
                    self.tree.uncheck_item(item)
            except AssertionError as err:
                self.operationTree.failure_item(item)
                if op.getObjType() == PluginStates.BINARY:
                    self.reloadInstalledPlugin(op.getObjParent())
                else:
                    self.reloadInstalledPlugin(item)
                self.operationTree.update()
                strErr = str('Error executing the operation: ' +
                             op.getObjStatus() + ' ' + op.getObjName())
                self.plug_log.info(redStr(strErr), False)
                self.plug_errors_log.error(redStr(strErr), False)
                self.Textlog.refreshAll(goEnd=True)
                self.Textlog.update()
        self.operationList.clearOperations()
        sys.stdout.flush()
        sys.stderr.flush()
        sys.stdout = oldstdout
        sys.stderr = oldstderr
        # Enable the treeview
        self.tree.enable()
        message.close()
        text = 'FINISHED SUCCESSFULLY'
        tag = PluginStates.SUCCESS
        self.operationTree.tag_configure(PluginStates.SUCCESS,
                                         foreground='green')

        if strErr is not None:
            text = 'FINISHED WITH ERRORS'
            tag = PluginStates.ERRORS
            self.operationTree.tag_configure(PluginStates.ERRORS,
                                             foreground='red')

        self.operationTree.insert("",
                                  'end',
                                  text,
                                  text=text,
                                  value=text,
                                  tags=tag)

    def linkToWebSite(self, event):
        """
        Load the plugin url
        """
        x, y, widget = event.x, event.y, event.widget
        item = self.topPanelTree.selectedItem = self.topPanelTree.identify_row(
            y)
        if (len(self.topPanelTree.selectedItem)
                and self.topPanelTree.item(item, 'value')[0] == 'pluginUrl'):
            browser = webbrowser.get()
            browser.open(item)

    def operationInformation(self, event):
        """Update the operationTree selected item"""
        x, y, widget = event.x, event.y, event.widget
        item = self.operationTree.selectedItem = self.operationTree.identify_row(
            y)
        if (len(item) and len(self.operationList.getOperations(None))
                and self.executeOpsBtn["state"] == tk.NORMAL):
            self.cancelOpsBtn.config(state='normal')

    def deleteOperation(self, operationName):
        """
        Delete an operation given the object name
        """
        for op in self.operationList.getOperations(None):
            if operationName == op.getObjName():
                self.operationList.insertOperation(op)

    def showOperationList(self):
        """
        Shows the operation list at left bottom panel
        :return:
        """
        self.operationTree.delete(*self.operationTree.get_children())
        operations = self.operationList.getOperations(None)
        if len(operations) > 0:
            for op in operations:
                self.operationTree.insert("",
                                          'end',
                                          op.getObjName(),
                                          text=str(op.getObjStatus().upper() +
                                                   ' --> ' + op.getObjName()),
                                          tags=op.getObjStatus())
            self.executeOpsBtn.config(state='normal')
        else:
            self.executeOpsBtn.config(state='disable')
        self.operationTree.update()

    def isPlugin(self, value):
        return value == PluginStates.PLUGIN

    def showPluginInformation(self, pluginName):
        """Shows the information associated with a given plugin"""
        plugin = pluginDict.get(pluginName, None)
        if plugin is not None:
            self.topPanelTree.delete(*self.topPanelTree.get_children())
            pluginName = plugin.getPipName()
            pluginVersion = plugin.latestRelease
            if pluginVersion:
                pluginUploadedDate = plugin.getReleaseDate(pluginVersion)
            else:
                pluginUploadedDate = ''
            pluginDescription = plugin.getSummary()
            pluginUrl = plugin.getHomePage()
            pluginAuthor = plugin.getAuthor()

            self.topPanelTree.tag_configure('pluginUrl', foreground='blue')

            self.topPanelTree.insert('',
                                     'end',
                                     pluginName,
                                     text='Name:              ' + pluginName,
                                     values='pluginName')
            if PluginStates.AVAILABLE_RELEASE in self.tree.item(
                    pluginName, 'tags'):
                pluginVersion = (plugin.getPipVersion() + '  *(Version ' +
                                 plugin.latestRelease +
                                 ' available. Right-click on the '
                                 'plugin to update it)')
                self.topPanelTree.tag_configure('pluginVersion',
                                                foreground=Color.RED_COLOR)
            else:
                self.topPanelTree.tag_configure('pluginVersion',
                                                foreground='black')
            self.topPanelTree.insert('',
                                     'end',
                                     pluginVersion,
                                     text='Version:            ' +
                                     pluginVersion,
                                     values='pluginVersion',
                                     tags=('pluginVersion', ))
            self.topPanelTree.insert('',
                                     'end',
                                     pluginUploadedDate,
                                     text='Release date:    ' +
                                     pluginUploadedDate.split('T')[0],
                                     values='pluginUploadedDate',
                                     tags=('pluginUploadedDate', ))
            self.topPanelTree.insert('',
                                     'end',
                                     pluginDescription,
                                     text='Description:      ' +
                                     pluginDescription,
                                     values='pluginDescription')
            self.topPanelTree.insert('',
                                     'end',
                                     pluginUrl,
                                     text='URL:                 ' + pluginUrl,
                                     values='pluginUrl',
                                     tags=('pluginUrl', ))
            self.topPanelTree.insert('',
                                     'end',
                                     pluginAuthor,
                                     text='Author:             ' +
                                     pluginAuthor,
                                     values='pluginAuthor')

    def reloadInstalledPlugin(self, pluginName):
        """
        Reload a given plugin and update the tree view
        """
        plugin = PluginInfo(pluginName, pluginName, remote=True)
        if plugin is not None:
            # Insert all binaries of plugin on the tree
            if plugin.isInstalled():
                pluginBinaryList = plugin.getInstallenv()
                if pluginBinaryList is not None:
                    binaryList = pluginBinaryList.getPackages()
                    keys = sorted(binaryList.keys())
                    for k in keys:
                        pVersions = binaryList[k]
                        for binary, version in pVersions:
                            installed = pluginBinaryList._isInstalled(
                                binary, version)
                            tag = PluginStates.UNCHECKED
                            if installed:
                                tag = PluginStates.CHECKED
                            binaryName = str(binary + '-' + version)
                            if binaryName in self.tree.get_children(
                                    pluginName):
                                self.tree.item(binaryName, tags=(tag, ))
                            else:
                                self.tree.insert(pluginName,
                                                 "end",
                                                 binaryName,
                                                 text=binaryName,
                                                 tags=tag,
                                                 values='binary')
                tag = PluginStates.CHECKED
                if plugin.latestRelease != plugin.pipVersion:
                    tag = PluginStates.AVAILABLE_RELEASE
                self.tree.item(pluginName, tags=(tag, ))
                self.showPluginInformation(pluginName)
            else:
                if PluginStates.UNINSTALL in self.tree.item(
                        pluginName, 'tags'):
                    self.tree.item(pluginName, tags=(PluginStates.UNCHECKED, ))
        else:
            self.tree.item(pluginName, tags=(PluginStates.UNCHECKED, ))

    def loadPlugins(self):
        """
        Load all plugins and fill the tree view widget
        """
        global pluginDict
        pluginDict = pluginRepo.getPlugins(getPipData=True)
        pluginList = sorted(pluginDict.keys(), reverse=True)
        countPlugin = self.progressbar['value']
        self.tree.delete(*self.tree.get_children())
        self.progressbar["maximum"] = countPlugin + len(pluginList)
        for pluginName in pluginList:
            countPlugin = countPlugin + 1
            self.progressbar['value'] = countPlugin
            plugin = PluginInfo(pluginName, pluginName, remote=False)
            if plugin is not None:
                tag = PluginStates.UNCHECKED
                if plugin._getPlugin():
                    # Insert the plugin name in the tree
                    latestRelease = pluginDict.get(
                        pluginName).getLatestRelease()
                    tag = PluginStates.CHECKED
                    if latestRelease and plugin.pipVersion != latestRelease:
                        tag = PluginStates.AVAILABLE_RELEASE
                    self.tree.insert("",
                                     0,
                                     pluginName,
                                     text=pluginName,
                                     tags=tag,
                                     values=PluginStates.PLUGIN)
                    # Insert all binaries of plugin on the tree
                    pluginBinaryList = plugin.getInstallenv()
                    if pluginBinaryList is not None:
                        binaryList = pluginBinaryList.getPackages()
                        keys = sorted(binaryList.keys())
                        for k in keys:
                            pVersions = binaryList[k]
                            for binary, version in pVersions:
                                installed = pluginBinaryList._isInstalled(
                                    binary, version)
                                tag = PluginStates.UNCHECKED
                                if installed:
                                    tag = PluginStates.CHECKED
                                binaryName = str(binary + '-' + version)
                                self.tree.insert(pluginName,
                                                 "end",
                                                 binaryName,
                                                 text=binaryName,
                                                 tags=tag,
                                                 values=PluginStates.BINARY)
                else:
                    latestRelease = pluginDict.get(
                        pluginName).getLatestRelease()
                    if latestRelease and latestRelease != '0.0.0':
                        self.tree.insert("",
                                         0,
                                         pluginName,
                                         text=pluginName,
                                         tags=tag,
                                         values=PluginStates.PLUGIN)
        self._closeProgressBar()
예제 #4
0
    def testSimpleFileLog(self):
        import random
        logTestCode = random.randint(1, 100000)

        genLogFn = LOG_FILE
        log1 = logging.getLogger('pyworkflow.test.log.test_scipon_log')
        genInfoTest = 'Testing general info [%d]' % logTestCode
        genDebugTest = 'Testing general debug [%d]' % logTestCode
        genWarningTest = 'Testing general warning [%d]' % logTestCode
        genErrorTest = 'Testing general error [%d]' % logTestCode
        log1.info(genInfoTest)
        #log.debug(genDebugTest)
        log1.warning(genWarningTest)

        logFn = self.getOutputPath('fileLog.log')
        log2 = ScipionLogger(logFn)
        fileInfoTest = 'Not really info, just testing logger  [%d]' % logTestCode
        fileDebugTest = 'Not really debug, just testing logger  [%d]' % logTestCode
        fileWarningTest = 'Not really a warning, just testing logger [%d]' % logTestCode
        fileErrorTest = 'Not really an error, just testing logger [%d]' % logTestCode
        log2.info(fileInfoTest)
        #log.debug(fileDebugTest)
        log2.warning(fileWarningTest)
        log3 = logging.getLogger('pyworkflow.tests.log')
        log3.error(genErrorTest)
        
        log4 = ScipionLogger(logFn)
        log4.error(fileErrorTest)
        
        # Check general logs
        lineGenInfoTest = getLineInFile(genInfoTest, genLogFn)
        lineGenWarningTest = getLineInFile(genWarningTest, genLogFn)
        lineGenErrorTest = getLineInFile(genErrorTest, genLogFn)
        
        isFileInfoTest = isInFile(fileInfoTest, genLogFn)
        isFileWarningTest = isInFile(fileWarningTest, genLogFn)
        isFileErrorTest = isInFile(fileErrorTest, genLogFn)     
        
        genLoggerChecked = True
        if lineGenInfoTest is None:
            print ('General info log failed!!!')
            genLoggerChecked = False
        if lineGenWarningTest is None:
            print ('General warning log failed!!!')
            genLoggerChecked = False
        if lineGenErrorTest is None:
            print ('General error log failed!!!')
            genLoggerChecked = False
        
        if not((lineGenInfoTest<lineGenWarningTest) & (lineGenWarningTest<lineGenErrorTest)):
            print ('General logs have an incorrect order!!!')
            genLoggerChecked = False
        
        if (isFileInfoTest | isFileWarningTest | isFileErrorTest):
            print ('File logs in general log!!!')
            genLoggerChecked = False
        
        # Check file logs
        lineFileInfoTest = getLineInFile(fileInfoTest, logFn)
        lineFileWarningTest = getLineInFile(fileWarningTest, logFn)
        lineFileErrorTest = getLineInFile(fileErrorTest, logFn)
        
        isGenInfoTest = isInFile(genInfoTest, logFn)
        isGenWarningTest = isInFile(genWarningTest, logFn)
        isGenErrorTest = isInFile(genErrorTest, logFn)    
        
        fileLoggerChecked = True
        if lineFileInfoTest is None:
            print ('File info log failed!!!')
            fileLoggerChecked = False
        if lineFileWarningTest is None:
            print ('File warning log failed!!!')
            fileLoggerChecked = False
        if lineFileErrorTest is None:
            print ('File error log failed!!!')
            fileLoggerChecked = False
        
        if not((lineFileInfoTest<lineFileWarningTest) & (lineFileWarningTest<lineFileErrorTest)):
            print ('File logs have an incorrect order!!!')
            fileLoggerChecked = False
        
        if (isGenInfoTest | isGenWarningTest | isGenErrorTest):
            print ('General logs in file log!!!')
            fileLoggerChecked = False 
        
        self.assertTrue(genLoggerChecked & fileLoggerChecked)