def SetFilesList(self, serverInfo): self.setEnabled(True) domains = serverInfo.keys() or orngServerFiles.listdomains() localInfo = dict([(dom, orngServerFiles.allinfo(dom)) for dom in domains]) items = [] self.allTags = set() allTitles = set() self.updateItems = [] for i, domain in enumerate(set(domains) - set(["test", "demo"])): local = localInfo.get(domain, {}) server = serverInfo.get(domain, {}) files = sorted(set(server.keys() + local.keys())) for j, file in enumerate(files): infoServer = server.get(file, None) infoLocal = local.get(file, None) items.append((self.filesView, domain, file, infoLocal, infoServer)) displayInfo = infoServer if infoServer else infoLocal self.allTags.update(displayInfo["tags"]) allTitles.update(displayInfo["title"].split()) for i, item in enumerate(items): self.updateItems.append(UpdateTreeWidgetItem(self, *item)) self.pb.advance() self.filesView.resizeColumnToContents(0) self.filesView.resizeColumnToContents(1) self.filesView.resizeColumnToContents(2) self.lineEditFilter.setItems([hint for hint in sorted(self.allTags) if not hint.startswith("#")]) self.SearchUpdate() self.UpdateInfoLabel() self.pb.finish()
def files_report(): import orngServerFiles as sf sf = sf.ServerFiles() html = [] for domain in sf.listdomains(): if domain not in ["demo", "demo2", "test", "gad"]: allinfo = sf.allinfo(domain) html += ["<h2>%s</h2>" % domain, "<table><tr><th>Title</th><th>Date</th><th>Filename</th></tr>"] + \ ["<tr><td>%s</td><td>%s</td><td>%s</td></tr>" % (info["title"], info["datetime"], file) \ for file, info in allinfo.items()] + \ ["</table>"] return "\n".join(html)
def SetFilesList(self, serverInfo): self.setEnabled(True) domains = list(serverInfo.keys()) or orngServerFiles.listdomains() localInfo = dict([(dom, orngServerFiles.allinfo(dom)) for dom in domains]) items = [] self.allTags = set() allTitles = set() self.updateItems = [] for i, domain in enumerate(set(domains) - set(["test", "demo"])): local = localInfo.get(domain, {}) server = serverInfo.get(domain, {}) files = sorted(set(server.keys)) + list(local.keys()))) for j, file in enumerate(files):
class OWDatabasesUpdate(OWWidget): def __init__(self, parent=None, signalManager=None, name="Databases update", wantCloseButton=False, searchString="", showAll=True, domains=None, accessCode=""): OWWidget.__init__(self, parent, signalManager, name) self.searchString = searchString self.accessCode = accessCode self.showAll = showAll self.domains = domains self.serverFiles = orngServerFiles.ServerFiles() box = OWGUI.widgetBox(self.mainArea, orientation="horizontal") import OWGUIEx self.lineEditFilter = OWGUIEx.lineEditHint( box, self, "searchString", "Filter", caseSensitive=False, delimiters=" ", matchAnywhere=True, listUpdateCallback=self.SearchUpdate, callbackOnType=True, callback=self.SearchUpdate) box = OWGUI.widgetBox(self.mainArea, "Files") self.filesView = QTreeWidget(self) self.filesView.setHeaderLabels(["Options", "Title", "Size"]) self.filesView.setRootIsDecorated(False) self.filesView.setSelectionMode(QAbstractItemView.NoSelection) self.filesView.setSortingEnabled(True) self.filesView.setItemDelegate(UpdateItemDelegate(self.filesView)) self.connect(self.filesView.model(), SIGNAL("layoutChanged()"), self.SearchUpdate) box.layout().addWidget(self.filesView) box = OWGUI.widgetBox(self.mainArea, orientation="horizontal") OWGUI.button(box, self, "Update all local files", callback=self.UpdateAll, tooltip="Update all updatable files") OWGUI.button(box, self, "Download filtered", callback=self.DownloadFiltered, tooltip="Download all filtered files shown") OWGUI.rubber(box) OWGUI.lineEdit(box, self, "accessCode", "Access Code", orientation="horizontal", callback=self.UpdateFilesList) self.retryButton = OWGUI.button(box, self, "Retry", callback=self.UpdateFilesList) self.retryButton.hide() box = OWGUI.widgetBox(self.mainArea, orientation="horizontal") OWGUI.rubber(box) if wantCloseButton: OWGUI.button(box, self, "Close", callback=self.accept, tooltip="Close") ## statusBar = QStatusBar() self.infoLabel = QLabel() self.infoLabel.setAlignment(Qt.AlignCenter) ## statusBar.addWidget(self.infoLabel) ## self.mainArea.layout().addWidget(statusBar) self.mainArea.layout().addWidget(self.infoLabel) self.infoLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.updateItems = [] self.allTags = [] self.resize(800, 600) QTimer.singleShot(50, self.UpdateFilesList) def UpdateFilesList(self): self.retryButton.hide() # self.progressBarInit() pb = OWGUI.ProgressBar(self, 3) self.filesView.clear() # self.tagsWidget.clear() self.allTags = set() allTitles = set() self.updateItems = [] if self.accessCode: self.serverFiles = orngServerFiles.ServerFiles( access_code=self.accessCode) self.error(0) try: domains = self.serverFiles.listdomains( ) if self.domains is None else self.domains pb.advance() serverInfo = dict([(dom, self.serverFiles.allinfo(dom)) for dom in domains]) pb.advance() except IOError, ex: self.error( 0, "Could not connect to server! Press the Retry button to try again." ) self.retryButton.show() domains = orngServerFiles.listdomains( ) if self.domains is None else self.domains pb.advance() serverInfo = {} pb.advance() localInfo = dict([(dom, orngServerFiles.allinfo(dom)) for dom in domains]) items = [] for i, domain in enumerate(set(domains) - set(["test", "demo"])): local = localInfo.get(domain, {}) #orngServerFiles.listfiles(domain) or [] # files = self.serverFiles.listfiles(domain) server = serverInfo.get(domain, {}) #self.serverFiles.allinfo(domain) files = sorted(set(server.keys() + local.keys())) for j, file in enumerate(files): infoServer = server.get(file, None) infoLocal = local.get(file, None) items.append( (self.filesView, domain, file, infoLocal, infoServer)) displayInfo = infoServer if infoServer else infoLocal self.allTags.update(displayInfo["tags"]) allTitles.update(displayInfo["title"].split()) # self.progressBarSet(100.0 * i / len(domains) + 100.0 * j / (len(files) * len(domains))) for i, item in enumerate(items): self.updateItems.append(UpdateTreeWidgetItem(self, *item)) pb.advance() self.filesView.resizeColumnToContents(0) self.filesView.resizeColumnToContents(1) self.filesView.resizeColumnToContents(2) self.lineEditFilter.setItems([ hint for hint in sorted(self.allTags) if not hint.startswith("#") ]) self.SearchUpdate() self.UpdateInfoLabel() self.progressBarFinished()