def _load_data(self): self.Warning.using_local_files.clear() found_sources = {} try: found_sources.update( serverfiles.ServerFiles().allinfo(serverfiles_domain)) except requests.exceptions.ConnectionError: found_sources.update(serverfiles.allinfo(serverfiles_domain)) self.Warning.using_local_files() self.available_db_sources = { item.get('title').split(': ')[-1]: item for item in found_sources.values() } if self.available_db_sources: file_name = self.available_db_sources[ self.selected_db_source]['filename'] try: serverfiles.update(serverfiles_domain, file_name) except requests.exceptions.ConnectionError: # try to update file. Ignore network errors. pass try: file_path = serverfiles.localpath_download( serverfiles_domain, file_name) except requests.exceptions.ConnectionError as err: # Unexpected error. raise err data = Table(file_path) # enforce order old_domain = data.domain new_domain = Domain( [], metas=[ old_domain['Organism'], old_domain['Name'], old_domain['Entrez ID'], old_domain['Cell Type'], old_domain['Function'], old_domain['Reference'], old_domain['URL'], ], ) data = data.transform(new_domain) self.data = data
def _load_data(self) -> None: """ Collect available data sources (marker genes data sets). """ self.Warning.using_local_files.clear() found_sources = {} try: found_sources.update(serverfiles.ServerFiles().allinfo(SERVER_FILES_DOMAIN)) except requests.exceptions.ConnectionError: found_sources.update(serverfiles.allinfo(SERVER_FILES_DOMAIN)) self.Warning.using_local_files() self.available_sources = {item.get('title').split(': ')[-1]: item for item in found_sources.values()}
def get_available_db_sources(): found_sources = {} try: found_sources.update( serverfiles.ServerFiles().allinfo(serverfiles_domain)) except ConnectionError: raise ConnectionError( 'Can not connect to {}. Using only local files.'.format( serverfiles.server_url)) finally: found_sources.update(serverfiles.allinfo(serverfiles_domain)) return { item.get('title').split(': ')[-1]: item for item in found_sources.values() }
def evaluate_files_state(progress_callback): progress_callback.emit() files = [] # fetch remote info try: server_info = serverfiles.ServerFiles().allinfo() except (Timeout, ConnectionError) as e: raise e progress_callback.emit() # fetch local info local_info = serverfiles.allinfo() all_info = set(local_info.keys()).union(server_info.keys()) for domain, file_name in sorted(all_info): files.append( FileState(domain, file_name, server_info.get((domain, file_name), None), local_info.get((domain, file_name), None))) progress_callback.emit() return files
def SetFilesList(self, serverInfo): """ Set the files to show. """ self.setEnabled(True) localInfo = serverfiles.allinfo() all_tags = set() self.filesView.clear() self.updateItems = [] for item in join_info_dict(localInfo, serverInfo): tree_item = UpdateTreeWidgetItem(item) options_widget = UpdateOptionsWidget(item.state) options_widget.item = item options_widget.installClicked.connect( partial(self.SubmitDownloadTask, item.domain, item.filename) ) options_widget.removeClicked.connect( partial(self.SubmitRemoveTask, item.domain, item.filename) ) self.updateItems.append((item, tree_item, options_widget)) all_tags.update(item.tags) self.filesView.addTopLevelItems( [tree_item for _, tree_item, _ in self.updateItems] ) for item, tree_item, options_widget in self.updateItems: self.filesView.setItemWidget(tree_item, 0, options_widget) # Add an update button if the file is updateable if item.state == OUTDATED: button = QToolButton( None, text="Update", maximumWidth=120, minimumHeight=20, maximumHeight=20 ) if sys.platform == "darwin": button.setAttribute(Qt.WA_MacSmallSize) button.clicked.connect( partial(self.SubmitDownloadTask, item.domain, item.filename) ) self.filesView.setItemWidget(tree_item, 2, button) self.progress.advance() self.filesView.setColumnWidth(0, self.filesView.sizeHintForColumn(0)) for column in range(1, 4): contents_hint = self.filesView.sizeHintForColumn(column) header_hint = self.filesView.header().sectionSizeHint(column) width = max(min(contents_hint, 400), header_hint) self.filesView.setColumnWidth(column, width) hints = [hint for hint in sorted(all_tags) if not hint.startswith("#")] self.completer.setTokenList(hints) self.SearchUpdate() self.UpdateInfoLabel() self.toggleButtons() self.cancelButton.setEnabled(False) self.progress.setRange(0, 0)