Exemplo n.º 1
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.checkBoxVerbose.setChecked(Settings().verbose)
        self.tabWidget.setCurrentIndex(0)
        self.tbwVersions.setColumnCount(1)
        self.tbwVersions.setRowCount(len(self.HEADERS))
        self.tbwVersions.setVerticalHeaderLabels(self.HEADERS)
        self.tbwVersions.setHorizontalHeaderLabels(['Version'])
        self.tbwVersions.verticalHeader().setStretchLastSection(False)
        self.labelMain.setText(self.labelMain.text() % __version__)
        self.setMinimumWidth(640)
        self.setMinimumHeight(480)
        self.setWindowIcon(
            QtGui.QIcon.fromTheme(
                'help-about',
                QtGui.QIcon(':/ide-icons/rc/dialog-information.png')))
        try:
            import qdarkstyle
        except ImportError:
            qdarkstyle_version = 'Not installed'
        else:
            qdarkstyle_version = qdarkstyle.__version__
        versions = [
            GnuCobolCompiler().get_version(), QtCore.QT_VERSION_STR,
            QtCore.PYQT_VERSION_STR, pyqode.core.__version__,
            pyqode.cobol.__version__, pygments.__version__, qdarkstyle_version
        ]
        for i, version in enumerate(versions):
            item = QtWidgets.QTableWidgetItem(version)
            self.tbwVersions.setItem(i, 0, item)
        with open(logger.get_path(), 'r') as f:
            self.textEditLog.setText(f.read())
        self.checkBoxVerbose.toggled.connect(self._on_verbose_toggled)

        self.edit_compiler_infos.setFont(QtGui.QFont(Settings().font, 9))

        # from pyqode.core._forms.pyqode_core_rc
        QtGui.QFontDatabase.addApplicationFont(
            ':/fonts/rc/SourceCodePro-Regular.ttf')
        QtGui.QFontDatabase.addApplicationFont(
            ':/fonts/rc/SourceCodePro-Bold.ttf')

        template = '''cobc --info
============

%(cobc_infos)s

cobcrun --runtime-env
=====================

%(cobcrun_infos)s
'''

        gnucobol_infos = template % {
            'cobc_infos': GnuCobolCompiler.get_cobc_infos(),
            'cobcrun_infos': GnuCobolCompiler.get_cobcrun_infos()
        }
        self.edit_compiler_infos.setPlainText(gnucobol_infos)
Exemplo n.º 2
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.checkBoxVerbose.setChecked(Settings().verbose)
        self.tabWidget.setCurrentIndex(0)
        self.tbwVersions.setColumnCount(1)
        self.tbwVersions.setRowCount(len(self.HEADERS))
        self.tbwVersions.setVerticalHeaderLabels(self.HEADERS)
        self.tbwVersions.setHorizontalHeaderLabels(["Version"])
        self.tbwVersions.verticalHeader().setStretchLastSection(False)
        self.labelMain.setText(self.labelMain.text() % __version__)
        self.setMinimumWidth(640)
        self.setMinimumHeight(480)
        self.setWindowIcon(QtGui.QIcon.fromTheme("help-about", QtGui.QIcon(":/ide-icons/rc/dialog-information.png")))
        try:
            import qdarkstyle
        except ImportError:
            qdarkstyle_version = "Not installed"
        else:
            qdarkstyle_version = qdarkstyle.__version__
        versions = [
            GnuCobolCompiler().get_version(),
            QtCore.QT_VERSION_STR,
            QtCore.PYQT_VERSION_STR,
            pyqode.core.__version__,
            pyqode.cobol.__version__,
            pygments.__version__,
            qdarkstyle_version,
        ]
        for i, version in enumerate(versions):
            item = QtWidgets.QTableWidgetItem(version)
            self.tbwVersions.setItem(i, 0, item)
        with open(logger.get_path(), "r") as f:
            self.textEditLog.setText(f.read())
        self.checkBoxVerbose.toggled.connect(self._on_verbose_toggled)

        self.edit_compiler_infos.setFont(QtGui.QFont(Settings().font, 9))

        # from pyqode.core._forms.pyqode_core_rc
        QtGui.QFontDatabase.addApplicationFont(":/fonts/rc/SourceCodePro-Regular.ttf")
        QtGui.QFontDatabase.addApplicationFont(":/fonts/rc/SourceCodePro-Bold.ttf")

        template = """cobc --info
============

%(cobc_infos)s

cobcrun --runtime-env
=====================

%(cobcrun_infos)s
"""

        gnucobol_infos = template % {
            "cobc_infos": GnuCobolCompiler.get_cobc_infos(),
            "cobcrun_infos": GnuCobolCompiler.get_cobcrun_infos(),
        }
        self.edit_compiler_infos.setPlainText(gnucobol_infos)
Exemplo n.º 3
0
def test_make_command_exe(free, std, ftype, expected_opts):
    compiler = GnuCobolCompiler()
    settings = Settings()
    settings.free_format = free
    settings.cobol_standard = std
    pgm, options = compiler.make_command(['HelloWorld.cbl'], ftype, 'bin')
    assert pgm == Settings().compiler_path
    for o, eo in zip(options, expected_opts):
        assert o == eo
    settings.free_format = free
    settings.cobol_standard = GnuCobolStandard.default
    settings.free_format = False
def test_make_command_exe(free, std, ftype, expected_opts):
    compiler = GnuCobolCompiler()
    settings = Settings()
    settings.free_format = free
    settings.cobol_standard = std
    pgm, options = compiler.make_command(['HelloWorld.cbl'], ftype, 'bin')
    assert pgm == Settings().compiler_path
    for o, eo in zip(options, expected_opts):
        assert o == eo
    settings.free_format = free
    settings.cobol_standard = GnuCobolStandard.default
    settings.free_format = False
Exemplo n.º 5
0
 def _run(self):
     """
     Runs the current editor program.
     :return:
     """
     # compilation has finished, we can run the program that corresponds
     # to the current editor file
     editor = self.app.edit.current_editor
     file_type = editor.file_type
     self.ui.tabWidgetLogs.setCurrentIndex(LOG_PAGE_RUN)
     self.ui.dockWidgetLogs.show()
     self.ui.consoleOutput.clear()
     output_dir = Settings().output_directory
     if not os.path.isabs(output_dir):
         output_dir = os.path.join(os.path.dirname(editor.file.path),
                                   output_dir)
     if Settings().working_dir:
         wd = Settings().working_dir
     else:
         wd = output_dir
     filename = os.path.splitext(editor.file.name)[0] + \
         GnuCobolCompiler().extension_for_type(file_type)
     program = os.path.join(output_dir, filename)
     if not os.path.exists(program):
         _logger().warning('cannot run %s, file does not exists', program)
         return
     _logger().info('running program: %r (working dir=%r)', program, wd)
     if Settings().external_terminal:
         self._run_in_external_terminal(program, wd, file_type)
         self.enable_run(True)
         self.enable_compile(True)
     else:
         self.ui.consoleOutput.setFocus(True)
         for item in self.run_buttons + [self.ui.actionRun]:
             item.setEnabled(False)
         path = GnuCobolCompiler.setup_process_environment().value('PATH')
         env = Settings().run_environemnt
         if 'PATH' not in list(env.keys()):
             env['PATH'] = path
         if file_type == FileType.MODULE:
             cobcrun = system.which('cobcrun')
             self.ui.consoleOutput.start_process(
                 cobcrun, [os.path.splitext(editor.file.name)[0]],
                 working_dir=wd,
                 env=env)
         else:
             self.ui.consoleOutput.start_process(program,
                                                 working_dir=wd,
                                                 env=env,
                                                 print_command=True)
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
def lint(request_data):
    """
    Performs linting of a COBOL document.

    This method will perform on the pyqode backend.

    :param request_data: work request data (dict)
    :return: status, messages
    """
    print('running open_cobol_ide.linter.lint')
    code = request_data['code']
    path = request_data['path']
    extension = os.path.splitext(path)[1]
    print('valid compiler extensions: %r' %
          settings.Settings().cobc_extensions)
    messages = []
    if extension.lower() in settings.Settings().cobc_extensions:
        # code might not have been saved yet, run cobc on a tmp file
        # we use a time stamp to avoid overwriting the file another cobc
        # instance might be compiling.
        file_name = os.path.split(path)[1]
        file_name, ext = os.path.splitext(file_name)
        tmp_name = '%s.%s%s' % (file_name, str(int(time.time())), ext)
        tmp_pth = os.path.join(tempfile.gettempdir(), tmp_name)
        print('writing code to temporary file: %r' % tmp_pth)
        with open(tmp_pth, 'w') as f:
            f.write(code)
        compiler = GnuCobolCompiler()
        pgm, args = make_linter_command(tmp_name, path)
        print('linter command: %s %s' % (pgm, ' '.join(args)))
        process = QtCore.QProcess()
        process.setProcessEnvironment(
            GnuCobolCompiler.setup_process_environment())
        process.setWorkingDirectory(os.path.dirname(tmp_pth))
        process.setProcessChannelMode(QtCore.QProcess.MergedChannels)
        print('running compiler process')
        print('working directory: %s' % process.workingDirectory())
        process.start(pgm, args)
        print('waiting for compilation to finish...')
        process.waitForFinished()
        output = process.readAllStandardOutput().data().decode(
            locale.getpreferredencoding())
        print('linter raw output: %s' % output)
        messages = compiler.parse_output(output, process.workingDirectory())
        print('linter parsed output: %r' % messages)
        print('removing temporary file...')
        os.remove(tmp_pth)
    return messages
Exemplo n.º 8
0
    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()
Exemplo n.º 9
0
def lint(request_data):
    """
    Performs linting of a COBOL document.

    This method will perform on the pyqode backend.

    :param request_data: work request data (dict)
    :return: status, messages
    """
    print('running open_cobol_ide.linter.lint')
    code = request_data['code']
    path = request_data['path']
    extension = os.path.splitext(path)[1]
    print(('valid compiler extensions: %r' %
           settings.Settings().cobc_extensions))
    messages = []
    if extension.lower() in settings.Settings().cobc_extensions:
        # code might not have been saved yet, run cobc on a tmp file
        # we use a time stamp to avoid overwriting the file another cobc
        # instance might be compiling.
        file_name = os.path.split(path)[1]
        file_name, ext = os.path.splitext(file_name)
        tmp_name = '%s.%s%s' % (file_name, str(int(time.time())), ext)
        tmp_pth = os.path.join(tempfile.gettempdir(), tmp_name)
        print(('writing code to temporary file: %r' % tmp_pth))
        with open(tmp_pth, 'w') as f:
            f.write(code)
        compiler = GnuCobolCompiler()
        pgm, args = make_linter_command(tmp_name, path)
        print(('linter command: %s %s' % (pgm, ' '.join(args))))
        process = QtCore.QProcess()
        process.setProcessEnvironment(
            GnuCobolCompiler.setup_process_environment())
        process.setWorkingDirectory(os.path.dirname(tmp_pth))
        process.setProcessChannelMode(QtCore.QProcess.MergedChannels)
        print('running compiler process')
        print(('working directory: %s' % process.workingDirectory()))
        process.start(pgm, args)
        print('waiting for compilation to finish...')
        process.waitForFinished()
        output = process.readAllStandardOutput().data().decode(
            locale.getpreferredencoding())
        print(('linter raw output: %s' % output))
        messages = compiler.parse_output(output, process.workingDirectory())
        print(('linter parsed output: %r' % messages))
        print('removing temporary file...')
        os.remove(tmp_pth)
    return messages
Exemplo n.º 10
0
def test_compile(path, ftype, expected_results, output_file_path):
    results = GnuCobolCompiler().compile(path, ftype)
    assert results[0] == expected_results[0]
    assert len(results[1]) >= len(expected_results[1])
    if output_file_path:
        assert os.path.exists(output_file_path)
        os.remove(output_file_path)
Exemplo n.º 11
0
    def get_system_infos(self):
        try:
            import qdarkstyle
        except ImportError:
            qdarkstyle_version = 'Not installed'
        else:
            qdarkstyle_version = qdarkstyle.__version__

        system = platform.system()
        is_linux = system.lower() == 'linux'
        return '\n'.join([
            '- Operating System: %s' % system + ' (' +
            ' '.join(platform.linux_distribution()) + ')' if is_linux else '',
            '- OpenCobolIDE: %s' % __version__,
            '- GnuCOBOL: %s' % GnuCobolCompiler().get_version(),
            '- Python: %s (%dbits)' %
            (platform.python_version(), 64 if sys.maxsize > 2**32 else 32),
            '- Qt: %s' % QtCore.QT_VERSION_STR,
            '- PyQt: %s' % QtCore.PYQT_VERSION_STR,
            '- pyqode.core: %s' % pyqode.core.__version__,
            '- pyqode.cobol: %s' % pyqode.cobol.__version__,
            '- pyqode.qt: %s' % pyqode.qt.__version__,
            '- pygments: %s' % pygments.__version__,
            '- QDarkStyle: %s' % qdarkstyle_version
        ])
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.setupUi(self)
     self.checkBoxVerbose.setChecked(Settings().verbose)
     self.tabWidget.setCurrentIndex(0)
     self.tbwVersions.setColumnCount(1)
     self.tbwVersions.setRowCount(len(self.HEADERS))
     self.tbwVersions.setVerticalHeaderLabels(self.HEADERS)
     self.tbwVersions.setHorizontalHeaderLabels(['Version'])
     self.tbwVersions.verticalHeader().setStretchLastSection(False)
     self.labelMain.setText(self.labelMain.text() % __version__)
     self.setMinimumWidth(640)
     self.setMinimumHeight(480)
     self.setWindowIcon(QtGui.QIcon.fromTheme(
         'help-about', QtGui.QIcon(
             ':/ide-icons/rc/dialog-information.png')))
     try:
         import qdarkstyle
     except ImportError:
         qdarkstyle_version = 'Not installed'
     else:
         qdarkstyle_version = qdarkstyle.__version__
     versions = [GnuCobolCompiler().get_version(),
                 QtCore.QT_VERSION_STR,
                 QtCore.PYQT_VERSION_STR,
                 pyqode.core.__version__,
                 pyqode.cobol.__version__,
                 pygments.__version__,
                 qdarkstyle_version]
     for i, version in enumerate(versions):
         item = QtWidgets.QTableWidgetItem(version)
         self.tbwVersions.setItem(i, 0, item)
     with open(logger.get_path(), 'r') as f:
         self.textEditLog.setText(f.read())
     self.checkBoxVerbose.toggled.connect(self._on_verbose_toggled)
Exemplo n.º 14
0
    def __init__(self, parse_args=True):
        super().__init__()
        if system.darwin:
            Application._osx_init()
        self._reported_tracebacks = []
        self._old_except_hook = sys.excepthook
        sys.excepthook = self._except_hook
        self._report_exception_requested.connect(self._report_exception)
        if hasattr(sys, 'frozen') and sys.platform == 'win32':
            sys.stdout = open(os.path.join(system.get_cache_directory(),
                                           'ocide_stdout.log'), 'w')
            sys.stderr = open(os.path.join(system.get_cache_directory(),
                                           'ocide_stderr.log'), 'w')
        self.app = QtWidgets.QApplication(sys.argv)
        if parse_args and not system.darwin:
            args = self.parse_args()
            verbose = args.verbose
            files = args.files
        else:
            verbose = False
            files = []
        logger.setup_logging(__version__, debug=verbose or Settings().verbose)
        self.name = 'OpenCobolIDE'
        self.version = __version__
        self.title = '%s %s' % (self.name, self.version)

        self.apply_mimetypes_preferences()

        self.win = MainWindow()
        self.win.setWindowTitle(self.title)
        self.file = FileController(self)
        self.view = ViewController(self)
        self.home = HomeController(self)
        self.edit = EditController(self)
        self.cobol = CobolController(self)
        self.help = HelpController(self)

        self.view.show_perspective(Settings().perspective)
        self.view.show_home_page()

        self.update_app_style()

        try:
            check_compiler()
        except CompilerNotFound:
            msg = 'Failed to find a working GnuCOBOL compiler!\n' \
                "The IDE will continue to work but you won't be able to " \
                'compile...'
            if system.windows:
                msg += '\n\nTip: Ensure that there is no additional ' \
                    'installation of MinGW in %s:\MinGW' % sys.executable[0]
            QtWidgets.QMessageBox.warning(
                self.win, 'COBOL compiler not found or not working', msg)
        else:
            _logger().info('GnuCOBOL version: %s',
                           GnuCobolCompiler.get_version())
        # open specified files
        for f in files:
            self.file.open_file(f)
Exemplo n.º 15
0
    def __init__(self, parse_args=True):
        super().__init__()
        if system.darwin:
            Application._osx_init()
        self.app = QtWidgets.QApplication(sys.argv)

        self._reported_tracebacks = []
        qcrash.get_system_information = system.get_system_infos
        qcrash.get_application_log = logger.get_application_log
        qcrash.install_backend(
            qcrash.backends.GithubBackend(QCRASH_GH_OWNER, QCRASH_GH_REPO),
            qcrash.backends.EmailBackend(QCRASH_EMAIL, 'OpenCobolIDE'))
        qcrash.set_qsettings(Settings()._settings)
        qcrash.install_except_hook(except_hook=self._report_exception)
        # if hasattr(sys, 'frozen') and sys.platform == 'win32':
        #     sys.stdout = open(os.path.join(system.get_cache_directory(),
        #                                    'ocide_stdout.log'), 'w')
        #     sys.stderr = open(os.path.join(system.get_cache_directory(),
        #                                    'ocide_stderr.log'), 'w')
        if parse_args and not system.darwin:
            files = self.handle_command_line_args()
        else:
            files = []
        _logger().info('files to open: %r' % files)
        self.name = 'OpenCobolIDE'
        self.version = __version__
        self.title = '%s %s' % (self.name, self.version)

        self.apply_mimetypes_preferences()

        self.win = MainWindow()
        self.win.setWindowTitle(self.title)
        self.file = FileController(self)
        self.view = ViewController(self)
        self.home = HomeController(self)
        self.edit = EditController(self)
        self.cobol = CobolController(self)
        self.help = HelpController(self)
        self.win.app = self

        self.view.show_perspective(Settings().perspective)

        self.update_app_style()

        try:
            check_compiler()
        except CompilerNotFound:
            msg = 'Failed to find a working GnuCOBOL compiler!\n' \
                "The IDE will continue to work but you won't be able to " \
                'compile...'
            if system.windows:
                msg += '\n\nTip: Ensure that there is no additional ' \
                    'installation of MinGW in %s:\MinGW' % sys.executable[0]
            QtWidgets.QMessageBox.warning(
                self.win, 'COBOL compiler not found or not working', msg)
        else:
            _logger().info('GnuCOBOL version: %s',
                           GnuCobolCompiler.get_version(include_all=False))
        self._files = files
Exemplo n.º 16
0
    def __init__(self, parse_args=True):
        super().__init__()
        if system.darwin:
            Application._osx_init()
        self.app = QtWidgets.QApplication(sys.argv)

        self._reported_tracebacks = []
        qcrash.get_system_information = system.get_system_infos
        qcrash.get_application_log = logger.get_application_log
        qcrash.install_backend(
            qcrash.backends.GithubBackend(QCRASH_GH_OWNER, QCRASH_GH_REPO),
            qcrash.backends.EmailBackend(QCRASH_EMAIL, 'OpenCobolIDE'))
        qcrash.set_qsettings(Settings()._settings)
        qcrash.install_except_hook(except_hook=self._report_exception)
        # if hasattr(sys, 'frozen') and sys.platform == 'win32':
        #     sys.stdout = open(os.path.join(system.get_cache_directory(),
        #                                    'ocide_stdout.log'), 'w')
        #     sys.stderr = open(os.path.join(system.get_cache_directory(),
        #                                    'ocide_stderr.log'), 'w')
        if parse_args and not system.darwin:
            files = self.handle_command_line_args()
        else:
            files = []
        _logger().info('files to open: %r' % files)
        self.name = 'OpenCobolIDE'
        self.version = __version__
        self.title = '%s %s' % (self.name, self.version)

        self.apply_mimetypes_preferences()

        self.win = MainWindow()
        self.win.setWindowTitle(self.title)
        self.file = FileController(self)
        self.view = ViewController(self)
        self.home = HomeController(self)
        self.edit = EditController(self)
        self.cobol = CobolController(self)
        self.help = HelpController(self)
        self.win.app = self

        self.view.show_perspective(Settings().perspective)

        self.update_app_style()

        try:
            check_compiler()
        except CompilerNotFound:
            msg = 'Failed to find a working GnuCOBOL compiler!\n' \
                "The IDE will continue to work but you won't be able to " \
                'compile...'
            if system.windows:
                msg += '\n\nTip: Ensure that there is no additional ' \
                    'installation of MinGW in %s:\MinGW' % sys.executable[0]
            QtWidgets.QMessageBox.warning(
                self.win, 'COBOL compiler not found or not working', msg)
        else:
            _logger().info('GnuCOBOL version: %s',
                           GnuCobolCompiler.get_version(include_all=False))
        self._files = files
Exemplo n.º 17
0
    def get_cobc_runtime_env():
        template = '''cobc --info
============

%(cobc_infos)s

cobcrun --runtime-env
=====================

%(cobcrun_infos)s
'''

        gnucobol_infos = template % {
            'cobc_infos': GnuCobolCompiler.get_cobc_infos(),
            'cobcrun_infos': GnuCobolCompiler.get_cobcrun_infos()
        }
        return gnucobol_infos
Exemplo n.º 18
0
    def get_cobc_runtime_env():
        template = '''cobc --info
============

%(cobc_infos)s

cobcrun --runtime-env
=====================

%(cobcrun_infos)s
'''

        gnucobol_infos = template % {
            'cobc_infos': GnuCobolCompiler.get_cobc_infos(),
            'cobcrun_infos': GnuCobolCompiler.get_cobcrun_infos()
        }
        return gnucobol_infos
Exemplo n.º 19
0
def test_extensions():
    exts = GnuCobolCompiler().extensions
    if system.windows:
        assert exts[0] == '.exe'
        assert exts[1] == '.dll'
    else:
        assert exts[0] == ''
        assert exts[1] == '.so'
Exemplo n.º 20
0
    def __init__(self, parse_args=True):
        if hasattr(sys, 'frozen') and sys.platform == 'win32':
            sys.stdout = open(
                os.path.join(system.get_cache_directory(), 'ocide_stdout.log'),
                'w')
            sys.stderr = open(
                os.path.join(system.get_cache_directory(), 'ocide_stderr.log'),
                'w')
        self.init_env()
        self.app = QtWidgets.QApplication(sys.argv)
        if parse_args and not system.darwin:
            args = self.parse_args()
            verbose = args.verbose
            files = args.files
        else:
            verbose = False
            files = []
        logger.setup_logging(__version__, debug=verbose or Settings().verbose)
        self.name = 'OpenCobolIDE'
        self.version = __version__
        self.title = '%s %s' % (self.name, self.version)

        self.apply_mimetypes_preferences()

        self.win = MainWindow()
        self.win.setWindowTitle(self.title)
        self.file = FileController(self)
        self.view = ViewController(self)
        self.home = HomeController(self)
        self.edit = EditController(self)
        self.cobol = CobolController(self)
        self.help = HelpController(self)

        self.view.show_perspective(Settings().perspective)
        self.view.show_home_page()

        self.update_app_style()

        try:
            check_compiler()
        except CompilerNotFound as e:
            QtWidgets.QMessageBox.warning(
                self.win, 'COBOL compiler not found',
                'Failed to find GnuCOBOL compiler!\n\n%s\n\n'
                "The IDE will continue to work but you won't be able to "
                'compile any file...' % e)
        else:
            _logger().info('GnuCOBOL version: %s',
                           GnuCobolCompiler.get_version())
        # open specified files
        for f in files:
            self.file.open_file(f)
Exemplo n.º 21
0
 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)
Exemplo n.º 22
0
    def __init__(self, parse_args=True):
        if hasattr(sys, 'frozen') and sys.platform == 'win32':
            sys.stdout = open(os.path.join(system.get_cache_directory(),
                                           'ocide_stdout.log'), 'w')
            sys.stderr = open(os.path.join(system.get_cache_directory(),
                                           'ocide_stderr.log'), 'w')
        self.init_env()
        self.app = QtWidgets.QApplication(sys.argv)
        if parse_args and not system.darwin:
            args = self.parse_args()
            verbose = args.verbose
            files = args.files
        else:
            verbose = False
            files = []
        logger.setup_logging(__version__, debug=verbose or Settings().verbose)
        self.name = 'OpenCobolIDE'
        self.version = __version__
        self.title = '%s %s' % (self.name, self.version)

        self.apply_mimetypes_preferences()

        self.win = MainWindow()
        self.win.setWindowTitle(self.title)
        self.file = FileController(self)
        self.view = ViewController(self)
        self.home = HomeController(self)
        self.edit = EditController(self)
        self.cobol = CobolController(self)
        self.help = HelpController(self)

        self.view.show_perspective(Settings().perspective)
        self.view.show_home_page()

        self.update_app_style()

        try:
            check_compiler()
        except CompilerNotFound as e:
            QtWidgets.QMessageBox.warning(
                self.win, 'COBOL compiler not found',
                'Failed to find GnuCOBOL compiler!\n\n%s\n\n'
                "The IDE will continue to work but you won't be able to "
                'compile any file...' % e)
        else:
            _logger().info('GnuCOBOL version: %s',
                           GnuCobolCompiler.get_version())
        # open specified files
        for f in files:
            self.file.open_file(f)
Exemplo n.º 23
0
 def check_compiler(self, dotted_extension):
     compiler_works = False
     msg = 'Invalid extension'
     if dotted_extension.lower() in Settings().cobc_extensions:
         compiler_works = GnuCobolCompiler().is_working()
         msg = 'GnuCOBOL compiler not found or not working'
     elif dotted_extension.lower() in Settings().dbpre_extensions:
         compiler_works = DbpreCompiler().is_working()
         msg = 'dbpre compiler not working, please check your SQL COBOL ' \
             'configuration'
     elif dotted_extension.lower() in Settings().esqloc_extensions:
         compiler_works = EsqlOCCompiler().is_working()
         msg = 'esqlOC compiler not working, please check your SQL COBOL ' \
             'configuration'
     return compiler_works, msg
Exemplo n.º 24
0
 def __init__(self, compiler, parent):
     super().__init__(
         parent, QtCore.Qt.WindowSystemMenuHint |
         QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowCloseButtonHint)
     self._compiler = compiler
     self.ui = dlg_check_compiler_ui.Ui_Dialog()
     self.ui.setupUi(self)
     version = GnuCobolCompiler.get_version()
     self.ui.plainTextEdit.setPlainText(version)
     self.ui.buttonBox.button(self.ui.buttonBox.Apply).setText(
         'Check compilation')
     self.ui.buttonBox.button(self.ui.buttonBox.Apply).clicked.connect(
         self._check_compiler)
     self.ui.buttonBox.button(self.ui.buttonBox.Apply).setDisabled(
         not version)
Exemplo n.º 25
0
 def get_runtime_env():
     try:
         import qdarkstyle
     except ImportError:
         qdarkstyle_version = 'Not installed'
     else:
         qdarkstyle_version = qdarkstyle.__version__
     versions = {
         'GnuCOBOL': GnuCobolCompiler().get_version(include_all=False),
         'Qt': QtCore.QT_VERSION_STR,
         'PyQt': QtCore.PYQT_VERSION_STR,
         'pyqode.core': pyqode.core.__version__,
         'pyqode.cobol': pyqode.cobol.__version__,
         'pygments': pygments.__version__,
         'qdarkstyle': qdarkstyle_version}
     return versions
Exemplo n.º 26
0
    def _check_compiler(self):
        output, exit_code = GnuCobolCompiler.check_compiler(self._compiler)

        if exit_code == 0:
            output = 'Compiler works!'
        else:
            output = 'Complier check failed:\n\nExit code: %d\nOutput:%s' % (
                exit_code, output)

        self.ui.label.setText('Output:')
        self.ui.plainTextEdit.setPlainText(output)

        if exit_code != 0:
            self.ui.plainTextEdit.appendPlainText(
                '\nTip: You might need to adapt the environment variables set '
                'by the IDE to make it work.')
Exemplo n.º 27
0
def get_system_infos():
    from open_cobol_ide import __version__
    from open_cobol_ide.compilers import GnuCobolCompiler
    from pyqode.qt import QtCore
    import pyqode.core
    import pyqode.cobol
    import pygments

    try:
        import qdarkstyle
    except ImportError:
        qdarkstyle_version = 'Not installed'
    else:
        qdarkstyle_version = qdarkstyle.__version__

    def get_linux_distro():
        try:
            out = str(subprocess.check_output(['lsb_release', '-i']),
                      locale.getpreferredencoding())
        except OSError:
            distro = platform.linux_distribution()[0]
            if not distro:
                distro = 'linux distribution not found'
        else:
            distro = out.split(':')[1].strip()
        return distro

    system_info = platform.system()
    if 'linux' in sys.platform.lower():
        system_info = get_linux_distro()
    elif 'darwin' in sys.platform.lower():
        system_info = 'Mac OS X %s' % platform.mac_ver()[0]
    return '\n'.join([
        'Operating System: %s' % system_info,
        'OpenCobolIDE: %s' % __version__,
        'GnuCOBOL: %s' % GnuCobolCompiler().get_version(
            include_all=False),
        'Python: %s (%dbits)' % (platform.python_version(), 64
                                 if sys.maxsize > 2**32 else 32),
        'Qt: %s' % QtCore.QT_VERSION_STR,
        'PyQt: %s' % QtCore.PYQT_VERSION_STR,
        'pyqode.core: %s' % pyqode.core.__version__,
        'pyqode.cobol: %s' % pyqode.cobol.__version__,
        'pyqode.qt: %s' % pyqode.qt.__version__,
        'pygments: %s' % pygments.__version__,
        'QDarkStyle: %s' % qdarkstyle_version
    ])
Exemplo n.º 28
0
 def _run(self):
     """
     Runs the current editor program.
     :return:
     """
     # compilation has finished, we can run the program that corresponds
     # to the current editor file
     editor = self.app.edit.current_editor
     file_type = editor.file_type
     self.ui.tabWidgetLogs.setCurrentIndex(LOG_PAGE_RUN)
     self.ui.dockWidgetLogs.show()
     self.ui.consoleOutput.clear()
     output_dir = Settings().output_directory
     if not os.path.isabs(output_dir):
         output_dir = os.path.join(
             os.path.dirname(editor.file.path), output_dir)
     if Settings().working_dir:
         wd = Settings().working_dir
     else:
         wd = output_dir
     filename = os.path.splitext(editor.file.name)[0] + \
         GnuCobolCompiler().extension_for_type(file_type)
     program = os.path.join(output_dir, filename)
     if not os.path.exists(program):
         _logger().warning('cannot run %s, file does not exists',
                           program)
         return
     _logger().info('running program: %r (working dir=%r)', program, wd)
     if Settings().external_terminal:
         self._run_in_external_terminal(program, wd, file_type)
         self.enable_run(True)
         self.enable_compile(True)
     else:
         self.ui.consoleOutput.setFocus(True)
         for item in self.run_buttons + [self.ui.actionRun]:
             item.setEnabled(False)
         path = GnuCobolCompiler.setup_process_environment().value('PATH')
         env = Settings().run_environemnt
         if 'PATH' not in env.keys():
             env['PATH'] = path
         if file_type == FileType.MODULE:
             cobcrun = system.which('cobcrun')
             self.ui.consoleOutput.start_process(
                 cobcrun, [os.path.splitext(editor.file.name)[0]], working_dir=wd, env=env)
         else:
             self.ui.consoleOutput.start_process(program, working_dir=wd, env=env, print_command=True)
Exemplo n.º 29
0
    def _check_compiler(self):
        output, exit_code = GnuCobolCompiler.check_compiler(self._compiler)

        if exit_code == 0:
            output = 'Compiler works!'
        else:
            output = 'Complier check failed:\n\nExit code: %d\nOutput:%s' % (
                exit_code, output)

        self.ui.label.setText('Output:')
        self.ui.plainTextEdit.setPlainText(output)
        if exit_code != 0:
            self.ui.plainTextEdit.appendPlainText(
                'Tips:\n- You might need to adapt the environment variables '
                'set by the IDE to make it work.')
            if system.windows:
                self.ui.plainTextEdit.appendPlainText(
                    '- If you see MinGW related errors ensure that there is no'
                    ' additional installation of MinGW in '
                    '%s:\MinGW' % sys.executable[0])
Exemplo n.º 30
0
    def _run_in_external_terminal(self, program, wd, file_type):
        """
        Runs a program in an external terminal.

        :param program: program to run
        :param wd: working directory
        """
        self.ui.consoleOutput.append(
            "Launched in external terminal")
        pyqode_console = system.which('pyqode-console')
        env = os.environ.copy()
        for k, v in Settings().run_environemnt.items():
            env[k] = v
        env['PATH'] = GnuCobolCompiler.setup_process_environment().value(
            'PATH')
        if file_type == FileType.MODULE:
            program = QtCore.QFileInfo(program).baseName()
        if system.windows:
            cmd = [pyqode_console, program]
            if file_type == FileType.MODULE:
                cmd.insert(1, system.which('cobcrun'))
            subprocess.Popen(cmd, cwd=wd,
                             creationflags=subprocess.CREATE_NEW_CONSOLE,
                             env=env)
        elif system.darwin:
            cmd = ['open', program]
            if file_type == FileType.MODULE:
                cmd.insert(1, system.which('cobcrun'))
            subprocess.Popen(cmd, cwd=wd, env=env)
        else:
            if file_type == FileType.EXECUTABLE:
                cmd = ['"%s %s"' % (pyqode_console, program)]
            else:
                cmd = ['"%s %s %s"' % (pyqode_console, system.which('cobcrun'),
                                       program)]
            cmd = system.shell_split(
                Settings().external_terminal_command.strip()) + cmd
            subprocess.Popen(' '.join(cmd), cwd=wd, shell=True,
                             env=env)
        _logger().info('running program in external terminal: %s',
                       ' '.join(cmd))
Exemplo n.º 31
0
    def _check_compiler(self):
        output, exit_code = GnuCobolCompiler.check_compiler(self._compiler)

        if exit_code == 0:
            output = 'Compiler works!'
        else:
            output = 'Complier check failed:\n\nExit code: %d\nOutput:%s' % (
                exit_code, output)

        self.ui.label.setText('Output:')
        self.ui.plainTextEdit.setPlainText(output)

        if exit_code != 0:
            self.ui.plainTextEdit.appendPlainText(
                'Tips:\n- You might need to adapt the environment variables '
                'set by the IDE to make it work.')
            if system.windows:
                self.ui.plainTextEdit.appendPlainText(
                    '- If you see MinGW related errors ensure that there is no'
                    ' additional installation of MinGW in '
                    '%s:\MinGW' % sys.executable[0])
Exemplo n.º 32
0
 def enable_linter(self):
     self.linter_mode.enabled = GnuCobolCompiler().is_working()
     _logger().debug('linter enabled: %r', self.linter_mode.enabled)
Exemplo n.º 33
0
    def _run_in_external_terminal(self, program, wd, file_type):
        """
        Runs a program in an external terminal.

        :param program: program to run
        :param wd: working directory
        """
        pyqode_console = system.which('pyqode-console')
        cobc_run_insert_pos = 1
        if pyqode_console is None:
            from pyqode.core.tools import console
            pyqode_console = [sys.executable, console.__file__]
            cobc_run_insert_pos = 2
        else:
            pyqode_console = [pyqode_console]
        env = os.environ.copy()
        for k, v in list(Settings().run_environemnt.items()):
            env[k] = v
        if 'PATH' not in list(Settings().run_environemnt.keys()):
            env['PATH'] = GnuCobolCompiler.setup_process_environment().value(
                'PATH')
        if file_type == FileType.MODULE:
            program = QtCore.QFileInfo(program).baseName()
        if system.windows:
            cmd = pyqode_console + [program]
            if file_type == FileType.MODULE:
                cmd.insert(cobc_run_insert_pos, system.which('cobcrun'))
            try:
                _logger().debug(
                    "running program in external terminal: %r, %r, %r" %
                    (cmd, wd, env))
                subprocess.Popen(cmd,
                                 cwd=wd,
                                 creationflags=subprocess.CREATE_NEW_CONSOLE,
                                 env=env)
            except (OSError, subprocess.CalledProcessError):
                msg = "Failed to launch program in external terminal (cmd=%s) " % ' '.join(
                    cmd)
                _logger().exception(msg)
                self.ui.consoleOutput.appendPlainText(msg)
                return
        elif system.darwin:
            if file_type == FileType.MODULE:
                create_script(PATH_RUN_MODULE_SCRIPT, RUN_MODULE_SCRIPT,
                              (wd, system.which('cobcrun'), program))
                cmd = [
                    'open', '-n', '-a', 'Terminal', '--args',
                    PATH_RUN_MODULE_SCRIPT
                ]
            else:
                create_script(PATH_RUN_PROGRAM_SCRIPT, RUN_PROGRAM_SCRIPT,
                              (wd, program))
                cmd = [
                    'open', '-n', '-a', 'Terminal', '--args',
                    PATH_RUN_PROGRAM_SCRIPT
                ]
            try:
                subprocess.Popen(cmd, cwd=wd, env=env)
            except (OSError, subprocess.CalledProcessError):
                msg = "Failed to launch program in external terminal (cmd=%s) " % ' '.join(
                    cmd)
                _logger().exception(msg)
                self.ui.consoleOutput.appendPlainText(msg)
                return
        else:
            if file_type == FileType.EXECUTABLE:
                cmd = ['"%s %s"' % (' '.join(pyqode_console), program)]
            else:
                cmd = [
                    '"%s %s %s"' % (' '.join(pyqode_console),
                                    system.which('cobcrun'), program)
                ]
            cmd = system.shell_split(
                Settings().external_terminal_command.strip()) + cmd
            try:
                subprocess.Popen(' '.join(cmd), cwd=wd, shell=True, env=env)
            except (OSError, subprocess.CalledProcessError):
                msg = "Failed to launch program in external terminal (cmd=%s) " % ' '.join(
                    cmd)
                _logger().exception(msg)
                self.ui.consoleOutput.appendPlainText(msg)
                return
        _logger().info('running program in external terminal: %s',
                       ' '.join(cmd))
        self.ui.consoleOutput.appendPlainText(
            "Launched in external terminal: %s" % ' '.join(cmd))
Exemplo n.º 34
0
def test_parse_output():
    code = "HelloWorld.cbl: 5: Error: Invalid indicator ';' at column 7 \n" \
        "HelloWorld.cbl: 3: Error: TCOP: No such file or directory"
    msgs = GnuCobolCompiler.parse_output(code, 'test/testfiles')
    assert len(msgs) == 2
Exemplo n.º 35
0
    def __init__(self, parse_args=True):
        super().__init__()
        if system.darwin:
            Application._osx_init()
        self._reported_tracebacks = []
        self._old_except_hook = sys.excepthook
        sys.excepthook = self._except_hook
        self._report_exception_requested.connect(self._report_exception)
        if hasattr(sys, 'frozen') and sys.platform == 'win32':
            sys.stdout = open(
                os.path.join(system.get_cache_directory(), 'ocide_stdout.log'),
                'w')
            sys.stderr = open(
                os.path.join(system.get_cache_directory(), 'ocide_stderr.log'),
                'w')
        self.app = QtWidgets.QApplication(sys.argv)
        if parse_args and not system.darwin:
            args = self.parse_args()
            verbose = args.verbose
            files = args.files
        else:
            verbose = False
            files = []
        logger.setup_logging(__version__, debug=verbose or Settings().verbose)
        self.name = 'OpenCobolIDE'
        self.version = __version__
        self.title = '%s %s' % (self.name, self.version)

        self.apply_mimetypes_preferences()

        self.win = MainWindow()
        self.win.setWindowTitle(self.title)
        self.file = FileController(self)
        self.view = ViewController(self)
        self.home = HomeController(self)
        self.edit = EditController(self)
        self.cobol = CobolController(self)
        self.help = HelpController(self)

        self.view.show_perspective(Settings().perspective)
        self.view.show_home_page()

        self.update_app_style()

        try:
            check_compiler()
        except CompilerNotFound:
            msg = 'Failed to find a working GnuCOBOL compiler!\n' \
                "The IDE will continue to work but you won't be able to " \
                'compile...'
            if system.windows:
                msg += '\n\nTip: Ensure that there is no additional ' \
                    'installation of MinGW in %s:\MinGW' % sys.executable[0]
            QtWidgets.QMessageBox.warning(
                self.win, 'COBOL compiler not found or not working', msg)
        else:
            _logger().info('GnuCOBOL version: %s',
                           GnuCobolCompiler.get_version())
        # open specified files
        for f in files:
            self.file.open_file(f)
Exemplo n.º 36
0
def test_type_extension(file_type, expected):
    assert GnuCobolCompiler().extension_for_type(file_type) == expected
Exemplo n.º 37
0
def test_get_version():
    prog = re.compile(r'^.*\d.\d.\d$')
    assert prog.match(GnuCobolCompiler().get_version(include_all=False)) \
        is not None
Exemplo n.º 38
0
def test_is_working():
    assert GnuCobolCompiler().is_working()
Exemplo n.º 39
0
    ('test/testfiles/VIRTUAL-PRINTER.cbl', FileType.MODULE),
    ('test/testfiles/VIRTUAL-PRINTER2.cbl', FileType.MODULE),
])
def test_get_file_type(path, ftype):
    assert get_file_type(path) == ftype


@pytest.mark.parametrize('file_type, expected', [
    (FileType.EXECUTABLE, '.exe' if system.windows else ''),
    (FileType.MODULE, '.dll' if system.windows else '.so'),
])
def test_type_extension(file_type, expected):
    assert GnuCobolCompiler().extension_for_type(file_type) == expected


exe_ext = GnuCobolCompiler().extension_for_type(FileType.EXECUTABLE)
dll_ext = GnuCobolCompiler().extension_for_type(FileType.MODULE)


@pytest.mark.parametrize(
    'free, std, ftype, expected_opts',
    [(False, GnuCobolStandard.default, FileType.EXECUTABLE, [
        '-x', '-o',
        '%s' % os.path.join('bin', 'HelloWorld' + exe_ext), '-std=default',
        '-Wall', '-debug'
    ]),
     (True, GnuCobolStandard.default, FileType.EXECUTABLE, [
         '-x', '-o',
         '%s' % os.path.join('bin', 'HelloWorld' + exe_ext), '-std=default',
         '-Wall', '-debug', '-free'
     ]),
Exemplo n.º 40
0
def test_get_dependencies(filename, expected_results):
    results = GnuCobolCompiler().get_dependencies(filename)
    assert sorted(results) == sorted(expected_results)
Exemplo n.º 41
0
def test_parse_output():
    code = "HelloWorld.cbl: 5: Error: Invalid indicator ';' at column 7 \n" \
        "HelloWorld.cbl: 3: Error: TCOP: No such file or directory"
    msgs = GnuCobolCompiler.parse_output(code, 'test/testfiles')
    assert len(msgs) == 2
Exemplo n.º 42
0
    def _run_in_external_terminal(self, program, wd, file_type):
        """
        Runs a program in an external terminal.

        :param program: program to run
        :param wd: working directory
        """
        pyqode_console = system.which('pyqode-console')
        cobc_run_insert_pos = 1
        if pyqode_console is None:
            from pyqode.core.tools import console
            pyqode_console = [sys.executable, console.__file__]
            cobc_run_insert_pos = 2
        else:
            pyqode_console = [pyqode_console]
        env = os.environ.copy()
        for k, v in Settings().run_environemnt.items():
            env[k] = v
        if 'PATH' not in Settings().run_environemnt.keys():
            env['PATH'] = GnuCobolCompiler.setup_process_environment().value(
                'PATH')
        if file_type == FileType.MODULE:
            program = QtCore.QFileInfo(program).baseName()
        if system.windows:
            cmd = pyqode_console + [program]
            if file_type == FileType.MODULE:
                cmd.insert(cobc_run_insert_pos, system.which('cobcrun'))
            try:
                _logger().debug("running program in external terminal: %r, %r, %r" % (cmd, wd, env))
                subprocess.Popen(cmd, cwd=wd, creationflags=subprocess.CREATE_NEW_CONSOLE, env=env)
            except (OSError, subprocess.CalledProcessError):
                msg = "Failed to launch program in external terminal (cmd=%s) " % ' '.join(cmd)
                _logger().exception(msg)
                self.ui.consoleOutput.appendPlainText(msg)
                return
        elif system.darwin:
            if file_type == FileType.MODULE:
                create_script(PATH_RUN_MODULE_SCRIPT, RUN_MODULE_SCRIPT, (wd, system.which('cobcrun'), program))
                cmd = ['open', '-n', '-a', 'Terminal', '--args', PATH_RUN_MODULE_SCRIPT]
            else:
                create_script(PATH_RUN_PROGRAM_SCRIPT, RUN_PROGRAM_SCRIPT, (wd, program))
                cmd = ['open', '-n', '-a', 'Terminal', '--args', PATH_RUN_PROGRAM_SCRIPT]
            try:
                subprocess.Popen(cmd, cwd=wd, env=env)
            except (OSError, subprocess.CalledProcessError):
                msg = "Failed to launch program in external terminal (cmd=%s) " % ' '.join(cmd)
                _logger().exception(msg)
                self.ui.consoleOutput.appendPlainText(msg)
                return
        else:
            if file_type == FileType.EXECUTABLE:
                cmd = ['"%s %s"' % (' '.join(pyqode_console), program)]
            else:
                cmd = ['"%s %s %s"' % (' '.join(pyqode_console), system.which('cobcrun'), program)]
            cmd = system.shell_split(Settings().external_terminal_command.strip()) + cmd
            try:
                subprocess.Popen(' '.join(cmd), cwd=wd, shell=True, env=env)
            except (OSError, subprocess.CalledProcessError):
                msg = "Failed to launch program in external terminal (cmd=%s) " % ' '.join(cmd)
                _logger().exception(msg)
                self.ui.consoleOutput.appendPlainText(msg)
                return
        _logger().info('running program in external terminal: %s', ' '.join(cmd))
        self.ui.consoleOutput.appendPlainText("Launched in external terminal: %s" % ' '.join(cmd))
Exemplo n.º 43
0
def test_get_version():
    prog = re.compile(r'^.*\d.\d.\d$')
    assert prog.match(GnuCobolCompiler().get_version()) is not None