Beispiel #1
0
    def __init__(self, defaults=(None, None)):

        super(RemoteDialog, self).__init__()

        token_file = os.path.join(os.path.expanduser('~'), '.nexpy',
                                  'globusonline', 'gotoken.txt')
        self.globus = GlobusCatalog(token_file)

        catalog_layout = QtGui.QHBoxLayout()
        self.catalog_combo = QtGui.QComboBox()
        for catalog in self.globus.get_catalogs():
            try:
                self.catalog_combo.addItem(catalog['config']['name'])
            except:
                pass
        self.catalog_combo.setSizeAdjustPolicy(
            QtGui.QComboBox.AdjustToContents)
        self.catalog_combo.currentIndexChanged.connect(self.get_datasets)
        catalog_layout.addWidget(QtGui.QLabel('Catalog: '))
        catalog_layout.addWidget(self.catalog_combo)
        catalog_layout.addStretch()
        self.layout = QtGui.QVBoxLayout()
        self.layout.addLayout(catalog_layout)
        self.layout.addWidget(self.close_buttons())
        self.setLayout(self.layout)
        self.dataset_combo = None
        self.member_combo = None
        self.ssh_controls = False  # SSH controls not yet constructed

        catalog, dataset = defaults

        if catalog:
            try:
                idx = self.catalog_combo.findText(catalog)
                self.catalog_combo.setCurrentIndex(idx)
                self.get_datasets()
                if dataset:
                    idx = self.dataset_combo.findText(dataset)
                    self.dataset_combo.setCurrentIndex(idx)
                    self.get_members()
            except:
                pass

        self.setWindowTitle("Open Remote File")
Beispiel #2
0
    def __init__(self, defaults=(None, None)):

        super(RemoteDialog, self).__init__()

        token_file = os.path.join(
            os.path.expanduser('~'), '.nexpy', 'globusonline', 'gotoken.txt')
        self.globus = GlobusCatalog(token_file)

        catalog_layout = QtGui.QHBoxLayout()
        self.catalog_combo = QtGui.QComboBox()
        for catalog in self.globus.get_catalogs():
            try:
                self.catalog_combo.addItem(catalog['config']['name'])
            except:
                pass
        self.catalog_combo.setSizeAdjustPolicy(
            QtGui.QComboBox.AdjustToContents)
        self.catalog_combo.currentIndexChanged.connect(self.get_datasets)
        catalog_layout.addWidget(QtGui.QLabel('Catalog: '))
        catalog_layout.addWidget(self.catalog_combo)
        catalog_layout.addStretch()
        self.layout = QtGui.QVBoxLayout()
        self.layout.addLayout(catalog_layout)
        self.layout.addWidget(self.close_buttons())
        self.setLayout(self.layout)
        self.dataset_combo = None
        self.member_combo = None
        self.ssh_controls = False  # SSH controls not yet constructed

        catalog, dataset = defaults

        if catalog:
            try:
                idx = self.catalog_combo.findText(catalog)
                self.catalog_combo.setCurrentIndex(idx)
                self.get_datasets()
                if dataset:
                    idx = self.dataset_combo.findText(dataset)
                    self.dataset_combo.setCurrentIndex(idx)
                    self.get_members()
            except:
                pass

        self.setWindowTitle("Open Remote File")
Beispiel #3
0
class RemoteDialog(BaseDialog):
    """Dialog to open a remote file.
    """ 
    def __init__(self, defaults=(None, None)):

        super(RemoteDialog, self).__init__()
 
        token_file = os.path.join(os.path.expanduser('~'),'.nexpy',
                                  'globusonline', 'gotoken.txt')
        self.globus = GlobusCatalog(token_file)

        catalog_layout = QtGui.QHBoxLayout()
        self.catalog_combo = QtGui.QComboBox()
        for catalog in self.globus.get_catalogs():
            try:
                self.catalog_combo.addItem(catalog['config']['name'])
            except:
                pass
        self.catalog_combo.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
        self.catalog_combo.currentIndexChanged.connect(self.get_datasets)
        catalog_layout.addWidget(QtGui.QLabel('Catalog: '))
        catalog_layout.addWidget(self.catalog_combo)
        catalog_layout.addStretch()
        self.layout = QtGui.QVBoxLayout()
        self.layout.addLayout(catalog_layout)
        self.layout.addWidget(self.close_buttons())
        self.setLayout(self.layout)
        self.dataset_combo = None
        self.member_combo = None
        self.ssh_controls = False # SSH controls not yet constructed

        catalog, dataset = defaults
        
        if catalog:
            try:
                idx = self.catalog_combo.findText(catalog)
                self.catalog_combo.setCurrentIndex(idx)
                self.get_datasets()
                if dataset:
                    idx = self.dataset_combo.findText(dataset)
                    self.dataset_combo.setCurrentIndex(idx)
                    self.get_members()
            except:
                pass                    
  
        self.setWindowTitle("Open Remote File")

    def get_datasets(self):
        if self.dataset_combo is None:
            dataset_layout = QtGui.QHBoxLayout()
            self.dataset_combo = QtGui.QComboBox()
            self.dataset_combo.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
            self.dataset_combo.currentIndexChanged.connect(self.get_members)
            dataset_layout.addWidget(QtGui.QLabel('Dataset: '))
            dataset_layout.addWidget(self.dataset_combo)
            dataset_layout.addStretch()
            self.layout.insertLayout(1, dataset_layout)       
        else:
            self.dataset_combo.clear()
            if self.member_combo is not None:
                self.member_combo.clear()
        for dataset in self.globus.get_datasets(self.catalog):
            try:
                self.dataset_combo.addItem(dataset['name'])
            except:
                pass

    def get_members(self):
        if self.member_combo is None:
            member_layout = QtGui.QHBoxLayout()
            self.member_combo = QtGui.QComboBox()
            self.member_combo.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
            self.member_combo.currentIndexChanged.connect(self.get_member)
            member_layout.addWidget(QtGui.QLabel('Member: '))
            member_layout.addWidget(self.member_combo)
            member_layout.addStretch()
            self.layout.insertLayout(2, member_layout) 
        else:
            self.member_combo.clear()
        for member in self.globus.get_members(self.dataset):
            try:
                self.member_combo.addItem(member['data_uri'])
            except:
                pass

    def get_member(self):
        self.globus.get_member(self.member)
        if not self.ssh_controls:
            self.layout.insertLayout(3, self.ssh_box())
            self.ssh_controls = True

    def ssh_box(self):
        pyro_layout = QtGui.QHBoxLayout()
        user_label = QtGui.QLabel('Remote user:'******'USER'))
        self.user_box.setMinimumWidth(100)
        port_label = QtGui.QLabel('Local port:')
        self.port_box = QtGui.QLineEdit('8801')
        self.port_box.setMinimumWidth(100)
        self.ssh_start_button = QtGui.QPushButton("Start SSH")
        self.ssh_stop_button = QtGui.QPushButton("Stop SSH")
        if self.globus.ssh_session is not None:
            self.ssh_start_button.setEnabled(False)
            self.ssh_stop_button.setEnabled(True)
        else:
            self.ssh_start_button.setEnabled(True)
            self.ssh_stop_button.setEnabled(False)
        self.ssh_start_button.clicked.connect(self.ssh_start)
        self.ssh_stop_button.clicked.connect(self.ssh_stop)

        pyro_layout.addStretch()
        pyro_layout.addWidget(user_label)
        pyro_layout.addWidget(self.user_box)
        pyro_layout.addWidget(port_label)
        pyro_layout.addWidget(self.port_box)
        pyro_layout.addWidget(self.ssh_start_button)
        pyro_layout.addWidget(self.ssh_stop_button)
        pyro_layout.addStretch()
        return pyro_layout

    def ssh_start(self):
        logging.info("")
        self.globus.ssh_start(self.user, self.port)
        self.ssh_stop_button.setEnabled(True)
        self.ssh_start_button.setEnabled(False)

    def ssh_stop(self):
        logging.info("")
        assert(self.globus.ssh_session != None)
        self.globus.ssh_stop()
        self.ssh_start_button.setEnabled(True)
        self.ssh_stop_button.setEnabled(False)

    @property
    def catalog(self):
        try:
            return self.catalog_combo.currentText()
        except Exception:
            return None

    @property
    def dataset(self):
        try:
            return self.dataset_combo.currentText()
        except Exception:
            return None

    @property
    def member(self):
        try:
            return self.member_combo.currentText()
        except Exception:
            return None

    @property
    def user(self):
        try:
            return self.user_box.text()
        except Exception:
            return None

    @property
    def port(self):
        try:
            return int(self.port_box.text())
        except Exception:
            return None

    def finalize(self):
        self.globus.finalize()

    def accept(self):
        try:
            root = self.globus.load(self.user, self.port)
            from nexpy.gui.consoleapp import _mainwindow, _shell
            name = _mainwindow.treeview.tree.get_name(root.nxfilename)               
            _mainwindow.treeview.tree[name] = _shell[name] = root
            _mainwindow.remote_defaults = (self.catalog, self.dataset)
            logging.info(
                "Opening remote NeXus file '%s' on '%s' as workspace '%s'"
                % (root.nxfilename, root._file, name))
            self.setVisible(False)
        except CommunicationError as e:
            msgBox = QtGui.QMessageBox()
            msgBox.setText("Could not connect to: " + self.globus.uri)
            msgBox.setIcon(QtGui.QMessageBox.Critical)
            logging.debug("Connection failed to: "+self.globus.uri+"\n\n"+str(e))
            msgBox.exec_()
        except NeXusError:
            super(RemoteDialog, self).reject()
Beispiel #4
0
class RemoteDialog(BaseDialog):
    """Dialog to open a remote file.
    """
    def __init__(self, defaults=(None, None)):

        super(RemoteDialog, self).__init__()

        token_file = os.path.join(os.path.expanduser('~'), '.nexpy',
                                  'globusonline', 'gotoken.txt')
        self.globus = GlobusCatalog(token_file)

        catalog_layout = QtGui.QHBoxLayout()
        self.catalog_combo = QtGui.QComboBox()
        for catalog in self.globus.get_catalogs():
            try:
                self.catalog_combo.addItem(catalog['config']['name'])
            except:
                pass
        self.catalog_combo.setSizeAdjustPolicy(
            QtGui.QComboBox.AdjustToContents)
        self.catalog_combo.currentIndexChanged.connect(self.get_datasets)
        catalog_layout.addWidget(QtGui.QLabel('Catalog: '))
        catalog_layout.addWidget(self.catalog_combo)
        catalog_layout.addStretch()
        self.layout = QtGui.QVBoxLayout()
        self.layout.addLayout(catalog_layout)
        self.layout.addWidget(self.close_buttons())
        self.setLayout(self.layout)
        self.dataset_combo = None
        self.member_combo = None
        self.ssh_controls = False  # SSH controls not yet constructed

        catalog, dataset = defaults

        if catalog:
            try:
                idx = self.catalog_combo.findText(catalog)
                self.catalog_combo.setCurrentIndex(idx)
                self.get_datasets()
                if dataset:
                    idx = self.dataset_combo.findText(dataset)
                    self.dataset_combo.setCurrentIndex(idx)
                    self.get_members()
            except:
                pass

        self.setWindowTitle("Open Remote File")

    def get_datasets(self):
        if self.dataset_combo is None:
            dataset_layout = QtGui.QHBoxLayout()
            self.dataset_combo = QtGui.QComboBox()
            self.dataset_combo.setSizeAdjustPolicy(
                QtGui.QComboBox.AdjustToContents)
            self.dataset_combo.currentIndexChanged.connect(self.get_members)
            dataset_layout.addWidget(QtGui.QLabel('Dataset: '))
            dataset_layout.addWidget(self.dataset_combo)
            dataset_layout.addStretch()
            self.layout.insertLayout(1, dataset_layout)
        else:
            self.dataset_combo.clear()
            if self.member_combo is not None:
                self.member_combo.clear()
        for dataset in self.globus.get_datasets(self.catalog):
            try:
                self.dataset_combo.addItem(dataset['name'])
            except:
                pass

    def get_members(self):
        if self.member_combo is None:
            member_layout = QtGui.QHBoxLayout()
            self.member_combo = QtGui.QComboBox()
            self.member_combo.setSizeAdjustPolicy(
                QtGui.QComboBox.AdjustToContents)
            self.member_combo.currentIndexChanged.connect(self.get_member)
            member_layout.addWidget(QtGui.QLabel('Member: '))
            member_layout.addWidget(self.member_combo)
            member_layout.addStretch()
            self.layout.insertLayout(2, member_layout)
        else:
            self.member_combo.clear()
        for member in self.globus.get_members(self.dataset):
            try:
                self.member_combo.addItem(member['data_uri'])
            except:
                pass

    def get_member(self):
        self.globus.get_member(self.member)
        if not self.ssh_controls:
            self.layout.insertLayout(3, self.ssh_box())
            self.ssh_controls = True

    def ssh_box(self):
        pyro_layout = QtGui.QHBoxLayout()
        user_label = QtGui.QLabel('Remote user:'******'USER'))
        self.user_box.setMinimumWidth(100)
        port_label = QtGui.QLabel('Local port:')
        self.port_box = QtGui.QLineEdit('8801')
        self.port_box.setMinimumWidth(100)
        self.ssh_start_button = QtGui.QPushButton("Start SSH")
        self.ssh_stop_button = QtGui.QPushButton("Stop SSH")
        if self.globus.ssh_session is not None:
            self.ssh_start_button.setEnabled(False)
            self.ssh_stop_button.setEnabled(True)
        else:
            self.ssh_start_button.setEnabled(True)
            self.ssh_stop_button.setEnabled(False)
        self.ssh_start_button.clicked.connect(self.ssh_start)
        self.ssh_stop_button.clicked.connect(self.ssh_stop)

        pyro_layout.addStretch()
        pyro_layout.addWidget(user_label)
        pyro_layout.addWidget(self.user_box)
        pyro_layout.addWidget(port_label)
        pyro_layout.addWidget(self.port_box)
        pyro_layout.addWidget(self.ssh_start_button)
        pyro_layout.addWidget(self.ssh_stop_button)
        pyro_layout.addStretch()
        return pyro_layout

    def ssh_start(self):
        logging.info("")
        self.globus.ssh_start(self.user, self.port)
        self.ssh_stop_button.setEnabled(True)
        self.ssh_start_button.setEnabled(False)

    def ssh_stop(self):
        logging.info("")
        assert (self.globus.ssh_session != None)
        self.globus.ssh_stop()
        self.ssh_start_button.setEnabled(True)
        self.ssh_stop_button.setEnabled(False)

    @property
    def catalog(self):
        try:
            return self.catalog_combo.currentText()
        except Exception:
            return None

    @property
    def dataset(self):
        try:
            return self.dataset_combo.currentText()
        except Exception:
            return None

    @property
    def member(self):
        try:
            return self.member_combo.currentText()
        except Exception:
            return None

    @property
    def user(self):
        try:
            return self.user_box.text()
        except Exception:
            return None

    @property
    def port(self):
        try:
            return int(self.port_box.text())
        except Exception:
            return None

    def finalize(self):
        self.globus.finalize()

    def accept(self):
        try:
            root = self.globus.load(self.user, self.port)
            from nexpy.gui.consoleapp import _mainwindow, _shell
            name = _mainwindow.treeview.tree.get_name(root.nxfilename)
            _mainwindow.treeview.tree[name] = _shell[name] = root
            _mainwindow.remote_defaults = (self.catalog, self.dataset)
            logging.info(
                "Opening remote NeXus file '%s' on '%s' as workspace '%s'" %
                (root.nxfilename, root._file, name))
            super(RemoteDialog, self).accept()
        except CommunicationError as e:
            msgBox = QtGui.QMessageBox()
            msgBox.setText("Could not connect to: " + uri)
            msgBox.setIcon(QtGui.QMessageBox.Critical)
            logging.debug("Connection failed to: " + uri + "\n\n" + str(e))
            msgBox.exec_()
        except NeXusError:
            super(RemoteDialog, self).reject()