def updateIndex(self): file_list = [] def accumulate_files(flist, directory, files): for fname in [ afname for afname in files if afname.endswith('.h5') ]: flist.append(os.path.realpath(os.path.join(directory, fname))) os.path.walk(getPyphantPath(KM_PATH), accumulate_files, file_list) try: from wx import (ProgressDialog, PyNoAppError) try: pdial = ProgressDialog('Rebuilding index...', ' ' * 100, maximum=len(file_list)) except PyNoAppError: pdial = None except ImportError: pdial = None count = 1 for realname in file_list: if pdial is not None: pdial.Update(count, os.path.basename(realname)) count += 1 try: self.registerH5(realname) except: self.logger.warn("Could not extract meta data from '%s'."\ % realname) if pdial is not None: pdial.Destroy()
def reversePython(self, umlFrame: UmlClassDiagramsFrame, directoryName: str, files: List[str]): """ Reverse engineering Python files to OglClass's Args: umlFrame: The uml frame to display on directoryName: The directory name where the selected files reside files: A list of files to parse """ fileCount: int = len(files) dlg = ProgressDialog('Parsing Files', 'Starting', parent=umlFrame, style=PD_APP_MODAL | PD_ELAPSED_TIME) dlg.SetRange(fileCount) currentFileCount: int = 0 onGoingParents: Parents = Parents({}) for fileName in files: try: fqFileName: str = f'{directoryName}{osSep}{fileName}' self.logger.info(f'Processing file: {fqFileName}') dlg.Update(currentFileCount, f'Processing: {fileName}') fileStream: FileStream = FileStream(fqFileName) lexer: Python3Lexer = Python3Lexer(fileStream) stream: CommonTokenStream = CommonTokenStream(lexer) parser: Python3Parser = Python3Parser(stream) tree: Python3Parser.File_inputContext = parser.file_input() if parser.getNumberOfSyntaxErrors() != 0: self.logger.error( f"File {fileName} contains {parser.getNumberOfSyntaxErrors()} syntax errors" ) # TODO: Put up a dialog continue self.visitor = PyutPythonVisitor() self.visitor.parents = onGoingParents self.visitor.visit(tree) self._generatePyutClasses() onGoingParents = self.visitor.parents currentFileCount += 1 except (ValueError, Exception) as e: from org.pyut.errorcontroller.ErrorManager import ErrorManager eMsg: str = f'file: {fileName}\n{e} - {ErrorManager.getErrorInfo()}' self.logger.error(eMsg) dlg.Destroy() raise PythonParseException(eMsg) dlg.Destroy() self._generateOglClasses(umlFrame) self._layoutUmlClasses(umlFrame) self._generateInheritanceLinks(umlFrame)
class progressDialog(object): """Simple wrapper for wxPython's ProgressDialog, creates a pulsing progress bar to indicate busy status. Call close() when complete. Recommended only when a very simple wait message is required. """ def __init__(self, dlg_title, dlg_msg="Please wait..."): self.pdlg = ProgressDialog(message=dlg_msg, title=dlg_title, maximum=100#, ) self.pdlg.Pulse() module_logger.info("Successfully initialized progressDialog.") def update(self): self.pdlg.UpdatePulse() def close(self): self.pdlg.Update(100) module_logger.info("Closing progressDialog.") self.pdlg.Destroy()