def _on_file_compiled(self, filename, status, messages): """ Displays compilation status in errors table. """ self.ui.dockWidgetLogs.show() self.ui.tabWidgetLogs.setCurrentIndex(LOG_PAGE_COMPILER) if len(messages) == 0 and status == 0: ext = GnuCobolCompiler().extension_for_type( get_file_type(filename)) name = os.path.splitext(os.path.split(filename)[1])[0] output_dir = Settings().output_directory if not os.path.isabs(output_dir): path = os.path.dirname(filename) output_dir = os.path.abspath(os.path.join(path, output_dir)) path = os.path.join(output_dir, name + ext) self.ui.errorsTable.add_message( CheckerMessage('Compilation succeeded (output: %s)' % path, CheckerMessages.INFO, -1, path=filename)) else: for msg in messages: msg = CheckerMessage(*msg) if msg.status == CheckerMessages.ERROR: self._errors += 1 if len(msg.description.splitlines()) > 1: msg.description = 'For full output see compiler tab...' self.ui.errorsTable.add_message(msg)
def _on_file_compiled(self, filename, status, messages): """ Displays compilation status in errors table. """ self.ui.dockWidgetLogs.show() self.ui.tabWidgetLogs.setCurrentIndex(LOG_PAGE_COMPILER) if len(messages) == 0 and status == 0: ext = GnuCobolCompiler().extension_for_type( get_file_type(filename)) name = os.path.splitext(os.path.split(filename)[1])[0] output_dir = Settings().output_directory if not os.path.isabs(output_dir): path = os.path.dirname(filename) output_dir = os.path.abspath(os.path.join(path, output_dir)) path = os.path.join(output_dir, name + ext) self.ui.errorsTable.add_message( CheckerMessage( 'Compilation succeeded (output: %s)' % path, CheckerMessages.INFO, -1, path=filename)) else: for msg in messages: msg = CheckerMessage(*msg) if msg.status == CheckerMessages.ERROR: self._errors += 1 if len(msg.description.splitlines()) > 1: msg.description = 'For full output see compiler tab...' self.ui.errorsTable.add_message(msg)
def clean_file(path): output_path = GnuCobolCompiler().get_output_filename( [os.path.split(path)[1]], get_file_type(path)) output_dir = Settings().output_directory if not os.path.isabs(output_dir): output_dir = os.path.abspath( os.path.join(os.path.dirname(path), output_dir)) output_path = os.path.join(output_dir, output_path) try: os.remove(output_path) except OSError: _logger().debug('failed to remove output file %r', output_path) else: _logger().debug('file removed: %s', output_path)
def clean_file(path): output_path = GnuCobolCompiler().get_output_filename( [os.path.split(path)[1]], get_file_type(path)) output_dir = Settings().output_directory if not os.path.isabs(output_dir): output_dir = os.path.abspath(os.path.join( os.path.dirname(path), output_dir)) output_path = os.path.join(output_dir, output_path) try: os.remove(output_path) except OSError: _logger().debug('failed to remove output file %r', output_path) else: _logger().debug('file removed: %s', output_path)
def run(self): """ Compiles the file and all its dependencies. """ def is_dbpre_cobol(path): if path.lower().endswith('.scb'): with open(path, 'r') as f: return 'exec sql' in f.read().lower() return False def is_esqloc_cobol(path): if path.lower().endswith('.sqb'): with open(path, 'r') as f: return 'exec sql' in f.read().lower() return False cobc = GnuCobolCompiler() cobc.started.connect(self.command_started.emit) cobc.output_available.connect(self.output_available.emit) dbpre = DbpreCompiler() dbpre.started.connect(self.command_started.emit) dbpre.output_available.connect(self.output_available.emit) esqloc = EsqlOCCompiler() esqloc.started.connect(self.command_started.emit) esqloc.output_available.connect(self.output_available.emit) files = [self.file_path] if Settings().autodetect_submodules: files += cobc.get_dependencies(self.file_path, recursive=True) _logger().info('running compilation thread: %r', files) for f in files: try: if is_dbpre_cobol(f): status, messages = dbpre.compile(f) elif is_esqloc_cobol(f): status, messages = esqloc.compile(f) else: status, messages = cobc.compile(f, get_file_type(f)) except Exception as e: _logger().exception('exception while compiling') self.errored.emit(f, e) else: self.file_compiled.emit(f, status, messages) self.finished.emit()
def file_type(self): return get_file_type(self.file.path)
def test_get_file_type(path, ftype): assert get_file_type(path) == ftype