Exemplo n.º 1
0
 def _onStderr(self):
     text = Meta.decodePlatformString(self._process.readAllStandardError())
     self.logger.info('E: %s', text.strip())
Exemplo n.º 2
0
 def _onStdout(self):
     text = Meta.decodePlatformString(self._process.readAllStandardOutput())
     self.logger.info('O: %s', text.strip())
Exemplo n.º 3
0
    def check(self):  # pylint: disable=R0912,R0914,R0915
        if platform.system() == 'Linux':
            # 1. plugdev group

            groupOk = False
            retcode = 0
            try:
                proc = subprocess.Popen(['groups'],
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
                outData, unused = proc.communicate()
            except Exception as exc:  # pylint: disable=W0703
                msg = str(exc)
                retcode = 1
            else:
                retcode = proc.returncode
                msg = _('<i>groups</i> exited with code {code}').format(
                    code=proc.returncode)

            if retcode:
                QtWidgets.QMessageBox.warning(
                    self, _('Cannot find groups'),
                    _('Unable to find out which groups you belong to:<p />{error}<p />For this program to work correctly, you must belong to the <i>plugdev</i> group.'
                      ).format(error=msg))
                groupOk = True
            else:
                groups = Meta.decodePlatformString(outData).split()
                groupOk = 'plugdev' in groups

            # 2. udev rules
            udevOk = os.path.exists('/etc/udev/rules.d/80-dsremap.rules')

            if not (udevOk and groupOk):
                msg = _(
                    'The following operations must be done before this program can work correctly:'
                ) + '<p /><ul>'
                if not udevOk:
                    msg += '<li>' + _(
                        'Install udev rules to allow HID communication'
                    ) + '</li>'
                if not groupOk:
                    msg += '<li>' + _(
                        'Add you to the <i>plugdev</i> group') + '</li>'
                msg += '</ul>'
                if not groupOk:
                    msg += '<p />' + _(
                        'You may have to logout and login again, or even reboot, and unplug/replug the Arduino for those changes to apply.'
                    )

                msg += '<p />' + _('You may be prompted for your password.')

                QtWidgets.QMessageBox.information(self, _('System setup'), msg)

                try:
                    if not groupOk:
                        sudoLaunch('usermod', '-a', '-G', 'plugdev',
                                   os.environ['USER'])
                    if not udevOk:
                        # Cannot copy a file from the res directory because root hasn't the permissions on the mount dir...
                        sudoLaunch(
                            'sh', '-c',
                            'echo \'SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="09cc", GROUP="plugdev", MODE="0660"\' > /etc/udev/rules.d/80-dsremap.rules'
                        )
                        sudoLaunch(
                            'sh', '-c',
                            'echo \'SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0ce6", GROUP="plugdev", MODE="0660"\' > /etc/udev/rules.d/80-dsremap.rules'
                        )
                        sudoLaunch(
                            'sh', '-c',
                            'echo \'SUBSYSTEM=="tty", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="8036", GROUP="plugdev", MODE="0660"\' >> /etc/udev/rules.d/80-dsremap.rules'
                        )
                except SudoNotFound:
                    QtWidgets.QMessageBox.critical(
                        self, _('Error'),
                        _('Unable to find <i>sudo</i> on the path.'))
                except SudoError as exc:
                    QtWidgets.QMessageBox.critical(
                        self, _('Error'),
                        _('Command failed with exit code {code}.<p />{stderr}'
                          ).format(code=exc.code, stderr=exc.stderr))

        with Settings().grouped('DefaultConfigurations') as settings:
            imported = settings.value('Imported').split(
                ',') if settings.contains('Imported') else []
            importer = JSONImporter()
            for name in glob.glob(
                    os.path.join(Meta.defaultConfigurations(), '*.zip')):
                with zipfile.ZipFile(name, mode='r') as zipobj:
                    configuration = importer.read(zipobj)
                if configuration.uuid() not in imported:
                    imported.append(configuration.uuid())
                    self._workspace.configurations().addItem(configuration)
            settings.setValue('Imported', ','.join(imported))

        if not Settings().firmwareUploaded():
            wizard = FirstLaunchWizard(self, mainWindow=self)
            wizard.exec_()