def on_actionAdd_triggered(self):
        hostname = self.ui.serverComboBox.currentText()
        host = re.sub("(?i)^.*https?://", '', hostname)
        if not host:
            return
        index = self.ui.serverComboBox.findText(host, Qt.MatchFixedString)
        if index != -1:
            for i in range(self.ui.tabWidget.count()):
                if host == self.ui.tabWidget.tabText(i):
                    self.ui.tabWidget.setCurrentIndex(i)
                    return

        server = self.ui.serverComboBox.itemData(index, Qt.UserRole)
        if not server:
            server = {"host": host, "protocol": "https"}
        if index == -1:
            self.ui.serverComboBox.addItem(host, server)
        else:
            self.ui.serverComboBox.setItemData(index, server)
        index = self.addAuthTab(server, self.credential_file,
                                self.cookie_persistence,
                                self.authentication_success_callback,
                                self.authentication_failure_callback)
        self.ui.tabWidget.setTabEnabled(index, False)
        widget = self.ui.tabWidget.widget(index)
        if isinstance(widget, AuthWidget):
            widget.login()
        self.ui.tabWidget.setTabEnabled(index, True)
        self.ui.tabWidget.setCurrentIndex(index)

        config = self.getConfiguredServers()
        write_config(DEFAULT_CONFIG_FILE, config)
    def onUpdateConfigResult(self, success, status, detail, result):
        self.restoreCursor()
        if not success:
            self.resetUI(status, detail)
            return
        if not result:
            return
        confirm_updates = stob(self.uploader.server.get("confirm_updates", False))
        if confirm_updates:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setWindowTitle("Updated Configuration Available")
            msg.setText("Apply updated configuration?")
            msg.setInformativeText(
                "Selecting \"Yes\" will apply the latest configuration from the server and overwrite the existing "
                "default configuration file.\n\nSelecting \"No\" will ignore these updates and continue to use the "
                "existing configuration.\n\nYou should always apply the latest configuration changes from the server "
                "unless you understand the risk involved with using a potentially out-of-date configuration.")

            msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
            ret = msg.exec_()
            if ret == QMessageBox.No:
                return

        write_config(self.uploader.getDeployedConfigFilePath(), result)
        self.uploader.initialize(cleanup=False)
        if not self.checkVersion():
            return
        self.on_actionRescan_triggered()
示例#3
0
    def configure(self, config_path):
        # configure logging
        self.ui.logTextBrowser.widget.log_update_signal.connect(self.updateLog)
        self.ui.logTextBrowser.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
        logging.getLogger().addHandler(self.ui.logTextBrowser)
        logging.getLogger().setLevel(logging.INFO)

        # configure Ermrest/Hatrac
        if not config_path:
            config_path = os.path.join(os.path.expanduser(
                os.path.normpath("~/.deriva/synapse/synspy-launcher")), "config.json")
        self.config_path = config_path
        config = read_config(self.config_path, create_default=True, default=DEFAULT_CONFIG)
        protocol = config["server"]["protocol"]
        self.server = config["server"]["host"]
        catalog_id = config["server"]["catalog_id"]
        session_config = config.get("session")
        self.catalog = ErmrestCatalog(protocol, self.server, catalog_id, self.credential, session_config=session_config)
        self.store = HatracStore(protocol, self.server, self.credential, session_config=session_config)

        # create working dir (tempdir)
        self.tempdir = tempfile.mkdtemp(prefix="synspy_")

        # determine viewer mode
        self.use_3D_viewer = True if config.get("viewer_mode", "2d").lower() == "3d" else False

        # curator mode?
        curator_mode = config.get("curator_mode")
        if not curator_mode:
            config["curator_mode"] = False
        self.curator_mode = config.get("curator_mode")

        # save config
        self.config = config
        write_config(self.config_path, self.config)
    def on_actionRemove_triggered(self):
        host = self.ui.serverComboBox.currentText()
        index = self.ui.serverComboBox.currentIndex()
        self.ui.serverComboBox.removeItem(index)
        for i in range(self.ui.tabWidget.count()):
            if host == self.ui.tabWidget.tabText(i):
                widget = self.ui.tabWidget.widget(i)
                if isinstance(widget, AuthWidget):
                    widget.logout()
                    del widget
                self.ui.tabWidget.removeTab(i)

        config = self.getConfiguredServers()
        write_config(DEFAULT_CONFIG_FILE, config)
示例#5
0
    def upload(uploader,
               data_path,
               hostname,
               catalog=1,
               token=None,
               config_file=None,
               credential_file=None,
               no_update=False,
               purge=False):

        if not issubclass(uploader, DerivaUpload):
            raise TypeError("DerivaUpload subclass required")

        assert hostname
        server = dict()
        server["catalog_id"] = catalog
        if hostname.startswith("http"):
            url = urlparse(hostname)
            server["protocol"] = url.scheme
            server["host"] = url.netloc
        else:
            server["protocol"] = "https"
            server["host"] = hostname

        deriva_uploader = uploader(config_file, credential_file, server)
        deriva_uploader.set_dcctx_cid(deriva_uploader.__class__.__name__)
        if token:
            deriva_uploader.setCredentials(format_credential(token))
        if not config_file and not no_update:
            config = deriva_uploader.getUpdatedConfig()
            if config:
                write_config(deriva_uploader.getDeployedConfigFilePath(), config)
        if not deriva_uploader.isVersionCompatible():
            raise RuntimeError("Version incompatibility detected", "Current version: [%s], required version(s): %s." % (
                deriva_uploader.getVersion(), deriva_uploader.getVersionCompatibility()))
        deriva_uploader.scanDirectory(data_path, abort_on_invalid_input=False, purge_state=purge)
        deriva_uploader.uploadFiles(file_callback=deriva_uploader.defaultFileCallback)
        deriva_uploader.cleanup()
示例#6
0
 def getOptions(parent):
     dialog = OptionsDialog(parent)
     dialog.exec_()
     write_config(parent.config_path, parent.config)
     if dialog.refreshWorklist:
         parent.on_actionRefresh_triggered()
示例#7
0
    def initialize(self, cleanup=False):
        info = "%s v%s [Python %s, %s]" % (self.__class__.__name__, VERSION,
                                           platform.python_version(),
                                           platform.platform(aliased=True))
        logging.info("Initializing uploader: %s" % info)

        # cleanup invalidates the current configuration and credentials in addition to clearing internal state
        if cleanup:
            self.cleanup()
        # reset just clears the internal state
        else:
            self.reset()

        if not self.server:
            logging.warning(
                "A server was not specified and an internal default has not been set."
            )
            return

        # server variable initialization
        protocol = self.server.get('protocol', 'https')
        host = self.server.get('host', '')
        self.server_url = protocol + "://" + host
        catalog_id = self.server.get("catalog_id", "1")
        session_config = self.server.get('session')

        # overriden credential initialization
        if self.override_credential_file:
            self.credentials = get_credential(host, self.override_config_file)

        # catalog and file store initialization
        if self.catalog:
            del self.catalog
        self.catalog = ErmrestCatalog(protocol,
                                      host,
                                      catalog_id,
                                      self.credentials,
                                      session_config=session_config)
        if self.store:
            del self.store
        self.store = HatracStore(protocol,
                                 host,
                                 self.credentials,
                                 session_config=session_config)

        # transfer state initialization
        self.loadTransferState()
        """
         Configuration initialization - this is a bit complex because we allow for:
             1. Run-time overriding of the config file location.
             2. Sub-classes of this class to bundle their own default configuration files in an arbitrary location.
             3. The updating of already deployed configuration files if bundled internal defaults are newer.             
        """
        config_file = self.override_config_file if self.override_config_file else None
        # 1. If we don't already have a valid (i.e., overridden) path to a config file...
        if not (config_file and os.path.isfile(config_file)):
            # 2. Get the currently deployed config file path, which could possibly be overridden by subclass
            config_file = self.getDeployedConfigFilePath()
            # 3. If the deployed default path is not valid, OR, it is valid AND is older than the bundled default
            if (not (config_file and os.path.isfile(config_file))
                    or self.isFileNewer(self.getDefaultConfigFilePath(),
                                        self.getDeployedConfigFilePath())):
                # 4. If we can locate a bundled default config file,
                if os.path.isfile(self.getDefaultConfigFilePath()):
                    # 4.1 Copy the bundled default config file to the deployment-specific config path
                    copy_config(self.getDefaultConfigFilePath(), config_file)
                else:
                    # 4.2 Otherwise, fallback to writing a failsafe default based on internal hardcoded settings
                    write_config(config_file, DefaultConfig)
        # 5. Finally, read the resolved configuration file into a config object
        self._update_internal_config(read_config(config_file))
示例#8
0
 def setServers(cls, servers):
     return write_config(
         os.path.join(cls.getDeployedConfigPath(),
                      cls.DefaultServerListFileName), servers)