def saveFilesToDB(self): selWindow = DBSelectorWindow(self) if not selWindow.exec_(): return dbName = selWindow.getDBName() if not dbName: messageBox(QMessageBox.Critical, "Fehler", "Der Name darf nicht leer sein!", self, QMessageBox.Ok) return self.currentReader = Reader() self._progresses.setEnabled(True) self.currentReader.ready.connect(self.readerReady) self.currentReader.folderStatusUpdated.connect(self.updateFolderStatus) self.currentReader.fileStatusUpdated.connect(self.updateFileStatus) self.currentReader.save_folder(str(self.currentFolder), "%s.sqlite" %str(dbName))
class AnalyzerTab(myWidget): def __init__(self, parent = None, *args): super(AnalyzerTab, self).__init__(parent, *args) self.currentFolder = QDir.currentPath() self.addFileRow() self.addListWidget() self.addReadRow() self.addProgressBars() def addFileRow(self): self._openBtn = QPushButton(QString.fromUtf8("Ordner auswählen"), self) self._openTextField = QLineEdit(self) self._openBtn.clicked.connect(self.openFolder) self.myLayout.addRow(self._openTextField, self._openBtn) def addListWidget(self): self._listWidget = QListWidget(self) self.myLayout.addRow(self._listWidget) def addReadRow(self): self._readBtn = QPushButton(QString.fromUtf8("Inhalt speichern"), self) self.myLayout.addRow(self._readBtn) self._readBtn.clicked.connect(self.saveFilesToDB) def addProgressBars(self): self._progresses = myWidget(self) self._progressFiles = QProgressBar(self._progresses) self._progressParagraphs = QProgressBar(self._progresses) self._progresses.myLayout.addRow("Dateien", self._progressFiles) self._progresses.myLayout.addRow("Paragraphen", self._progressParagraphs) self._progresses.setEnabled(False) self.myLayout.addRow(self._progresses) def openFolder(self): newFolder = str(QFileDialog.getExistingDirectory(parent=self, caption=QString.fromUtf8("Ordner auswählen"), directory = self.currentFolder)) if not newFolder: print "HIER: ", newFolder return self._openTextField.setText(newFolder) self.listFolderFiles(newFolder) self.currentFolder = newFolder def listFolderFiles(self, folderPath): if not os.path.isdir(folderPath): print "%s is not a folder!" %folderPath return self._listWidget.clear() for fName in os.listdir(folderPath): if fName.endswith(".doc") and not fName.startswith("~"): self._listWidget.addItem(fName) def saveFilesToDB(self): selWindow = DBSelectorWindow(self) if not selWindow.exec_(): return dbName = selWindow.getDBName() if not dbName: messageBox(QMessageBox.Critical, "Fehler", "Der Name darf nicht leer sein!", self, QMessageBox.Ok) return self.currentReader = Reader() self._progresses.setEnabled(True) self.currentReader.ready.connect(self.readerReady) self.currentReader.folderStatusUpdated.connect(self.updateFolderStatus) self.currentReader.fileStatusUpdated.connect(self.updateFileStatus) self.currentReader.save_folder(str(self.currentFolder), "%s.sqlite" %str(dbName)) def readerReady(self): self._progresses.setEnabled(False) def updateFolderStatus(self, ready, fileCount): self._progressFiles.setMaximum(100) self._progressFiles.setValue(self._calc_status(ready, fileCount)) def updateFileStatus(self, ready, paragraphCount): self._progressParagraphs.setMaximum(100) self._progressParagraphs.setValue(self._calc_status(ready, paragraphCount)) def _calc_status(self, done, toDo): r = done * 100 / toDo if r == 99: return 100 else: return r
#Check if ant variable of this file is in the random selection, if so add them to the list random_variable_declarations = list( set(random_sample) & set(variable_declarations)) if len(random_variable_declarations) > 0: files_and_docstrings[file_name] = random_variable_declarations # if verbose: # for key in files_and_docstrings.keys(): # print key # for docstring in files_and_docstrings[key]: # print docstring print(files_and_docstrings) if output_file_name: with open(output_file_name, "w") as output_file: for key in files_and_docstrings.keys(): output_file.write(key + "\n") for docstring in files_and_docstrings[key]: output_file.write(docstring + "\n") output_file.write("=" * 20 + "\n") if __name__ == "__main__": retriever = Retriever() reader = Reader("(Parameters|Returns).*[^ ]*( : )") selector = Selector(retriever, reader) if (len(sys.argv) < 2): raise Exception( "Usage: python fileSelector.py <path\\to\\root\\directory>") root_folder = sys.argv[1] selector.retrieve_random_sample_file_names(root_folder, 'test.txt', False)