def _setDebugLevel(libHandle): """ If the library makes use of ToolBOS's ANY_LOG framework, set the debug level appropriately according to the debugLevel used in Python. """ Any.requireIsInstance(libHandle, ctypes.CDLL) try: debugLevel = Any.getDebugLevel() # Any.py logs at maximum level 5 while the Any.c logs up to infinity. # therefore we generally suppress setting the loglevel if above 5. if debugLevel < 5: libHandle.Any_setDebugLevel(Any.getDebugLevel()) libHandle.Any_setShortLogFormat() except AttributeError: # likely does not link against ToolBOSCore library pass
def writeText(self, toWrite): if not self._frozen: text = UnicodeSupport.convert(toWrite) self._cursorToEnd() cursor = self.textCursor() begin = cursor.position() self.insertPlainText(text) end = cursor.position() if text.find( 'error:' ) >= 0 or \ text.find( '[ERROR]' ) >= 0 or \ text.find( 'make: *** [all] Error' ) >= 0: highlightChar = self._highlightCharError highlightBlock = self._highlightBlockError self._autoScroll = False elif text.find( 'warning:' ) >= 0 or \ text.find( '[WARNING]' ) >= 0: highlightChar = self._highlightCharWarn highlightBlock = self._highlightBlockWarn else: highlightChar = self._highlightCharNone highlightBlock = self._highlightBlockNone cursor.setPosition(begin, QTextCursor.MoveAnchor) cursor.setPosition(end, QTextCursor.KeepAnchor) Any.requireIsInstance(highlightChar, QTextCharFormat) cursor.setCharFormat(highlightChar) Any.requireIsInstance(highlightBlock, QTextBlockFormat) cursor.setBlockFormat(highlightBlock) self._cursorToEnd()
def _setCellColorCode(self, child, column, status): Any.requireIsInstance(child, QTreeWidgetItem) Any.requireIsInt(column) if status is None: color = self._grey text = '' elif status is True: color = self._green text = 'yes' elif status is False: color = self._red text = 'no' else: raise ValueError('unexpected status: %s', status) child.setBackground(column, color) child.setText(column, text) child.setTextAlignment(column, Qt.AlignCenter)
def convertQByteArray(qba): """ Converts a string of PyQt's 'QByteArray' type to: Py2: unicode Py3: str """ Any.requireIsInstance(qba, QByteArray) data = qba.data() if six.PY2: Any.requireIsInstance(data, str) return convertStr(data) else: Any.requireIsInstance(data, bytes) return convertBytes(data)
def setMetaInfoCache( self, metaInfoCache ): Any.requireIsInstance( metaInfoCache, MetaInfoCache ) BSTInstalledPackage._metaInfoCache = metaInfoCache
def __init__(self, model): super(DependenciesDialog, self).__init__() Any.requireIsInstance(model, QtPackageModel.BSTPackageModel) numColumns = 4 self._model = model self._treeMode = True self._reverseMode = False self._tree = None self._treeWidget = QTreeWidget() self._red = QColor(255, 120, 120) self._green = QColor(220, 255, 220) self._grey = QColor(240, 240, 240) self._canonicalPath = self._model.getCanonicalPath() self._sitProxyPath = SIT.getPath() self._sitRootPath = SIT.getRootPath() self._hasProxy = ProxyDir.isProxyDir(self._sitProxyPath) # obtain data and create one QTreeWidgetItem for each self._data1 = self._model.getDependencySet() self._data2 = self._model.getDependencyTree() self._data3 = self._model.getReverseDependencySet() self._data4 = self._model.getReverseDependencyTree() self._aptCmd = self._model.getDepInstallCmd_APT() logging.debug('data1: %s', self._data1) logging.debug('data2: %s', self._data2) logging.debug('data3: %s', self._data3) logging.debug('data4: %s', self._data4) depsEnabled = self._data1 is not None and self._data2 is not None revDepsEnabled = self._data3 is not None and self._data4 is not None if depsEnabled: self._tree1 = self._createTreeWidgetFromSet(self._data1, False) self._tree2 = self._createTreeWidgetFromList(self._data2, False) if revDepsEnabled: self._tree3 = self._createTreeWidgetFromSet(self._data3, True) self._tree4 = self._createTreeWidgetFromList(self._data4, True) if not depsEnabled and not revDepsEnabled: logging.error('unable to show dependency-dialog') return depsTooltip = 'low-level packages needed by the current one' if revDepsEnabled: revDepsTooltip = 'high-level packages which use the current one' else: revDepsTooltip = 'not globally installed --> no reverse dependencies' self._depRadio_direct = QRadioButton('&dependencies') self._depRadio_direct.setChecked(True) self._depRadio_direct.setToolTip(depsTooltip) self._depRadio_direct.clicked.connect(self._showDependencies) self._depRadio_reverse = QRadioButton('&reverse dependencies') self._depRadio_reverse.setToolTip(revDepsTooltip) self._depRadio_reverse.setEnabled(revDepsEnabled) self._depRadio_reverse.clicked.connect(self._showReverseDependencies) depSelectLayout = QVBoxLayout() depSelectLayout.addWidget(self._depRadio_direct) depSelectLayout.addWidget(self._depRadio_reverse) depSelectWidget = QGroupBox('direction') depSelectWidget.setLayout(depSelectLayout) # initial / default view: show own dependencies as tree self._tree = self._tree2 self._updateView() self._treeWidget.setColumnCount(numColumns) self._treeWidget.setRootIsDecorated( False) # top-left has no parent line self._treeWidget.setSortingEnabled(False) header = self._treeWidget.header() header.setStretchLastSection(False) header.setSectionResizeMode( 0, QHeaderView.Stretch) # stretch first column headerWidget = QTreeWidgetItem([ 'dependency', 'installed in proxy SIT', 'installed in global SIT', 'installed locally' ]) for i in range(1, numColumns): header.setSectionResizeMode(i, QHeaderView.ResizeToContents) headerWidget.setTextAlignment(i, Qt.AlignCenter) self._treeWidget.setHeaderItem(headerWidget) self._aptLabel = QLabel('Debian/Ubuntu packages needed:') self._aptWidget = QTextEdit(self._aptCmd) self._aptWidget.setFixedHeight(100) self._aptWidget.setFontFamily("Courier New") self._aptWidget.setReadOnly(True) toggleView = QPushButton('&toggle tree/flat view') toggleView.pressed.connect(self._toggleTree) self._expandButton = QPushButton('&expand all') self._expandButton.pressed.connect(self._treeWidget.expandAll) self._collapseButton = QPushButton('&collapse all') self._collapseButton.pressed.connect(self._treeWidget.collapseAll) self._collapseButton.pressed.connect( lambda: self._tree.setExpanded(True)) closeButton = QPushButton('&OK') closeButton.pressed.connect(self.close) buttonLayout = QHBoxLayout() buttonLayout.setAlignment(Qt.AlignRight) buttonLayout.addWidget(toggleView) buttonLayout.addSpacing(1) buttonLayout.addWidget(self._expandButton) buttonLayout.addWidget(self._collapseButton) buttonLayout.addWidget(closeButton) buttonWidget = QWidget() buttonWidget.setLayout(buttonLayout) mainLayout = QVBoxLayout() mainLayout.addWidget(depSelectWidget) mainLayout.addWidget(self._treeWidget) mainLayout.addWidget(self._aptLabel) mainLayout.addWidget(self._aptWidget) mainLayout.addWidget(buttonWidget) # noinspection PyArgumentList screen = QApplication.desktop().screenGeometry() dialogWidth = screen.width() * 0.5 dialogHeight = screen.height() * 0.75 self.setLayout(mainLayout) self.setWindowTitle('Dependencies of %s' % self._canonicalPath) self.resize(dialogWidth, dialogHeight) self.move(screen.center() - self.rect().center()) # center self.show()
def __init__(self, readonly, inactiveColor=lightGrey, runColor=lightYellow, exitSuccessColor=lightGreen, exitFailureColor=lightRed, warningHighlightColor=lightOrange, errorHighlightColor=solidRed, parent=None): Any.requireIsBool(readonly) Any.requireIsInstance(inactiveColor, QColor) Any.requireIsInstance(runColor, QColor) Any.requireIsInstance(exitSuccessColor, QColor) Any.requireIsInstance(exitFailureColor, QColor) Any.requireIsInstance(warningHighlightColor, QColor) Any.requireIsInstance(errorHighlightColor, QColor) super(QWidget, self).__init__() self.command = '' self.hostname = 'localhost' self.homeDir = os.path.expanduser('~') self.path = os.getcwd() self.pipe = None self.standalone = False self.taskProcess = None self.withX11Tunnel = False self._loggingEnabled = False self._logFilename = '' self._logFile = None self.depChecker = None self._missingDeps = [] self._closeAction = None self._enabled = False self._execCommand = None self._showCommand = None self._oldPath = self.path self._oldColor = None self._oldWinFlags = None self._outputFilter = None self._terminating = False self._inactiveColor = inactiveColor self._runColor = runColor self._exitSuccessColor = exitSuccessColor self._exitFailureColor = exitFailureColor self._warningHighlightColor = warningHighlightColor self._errorHighlightColor = errorHighlightColor self.hostnameField = QLineEdit(parent) self.hostnameField.setFont(QFont('Arial', 8)) self.hostnameField.setToolTip('hostname') self.hostnameField.setText(self.hostname) self.hostnameField.setReadOnly(readonly) # noinspection PyUnresolvedReferences self.hostnameField.editingFinished.connect(self._onHostnameFieldInput) self.sepLabel = QLabel(':', parent) self.pathField = QLineEdit(parent) self.pathField.setFont(QFont('Arial', 8)) self.pathField.setToolTip( 'working directory (to change it type "cd ..." in operator shell below)' ) self.pathField.setText(self.path) # noinspection PyUnresolvedReferences self.pathField.editingFinished.connect(self._onPathFieldInput) self.problemIndicator = QPushButton() self.problemIndicator.hide() self.xtermButton = QPushButton() self.xtermButton.setIcon(IconProvider.getIcon('utilities-terminal')) self.xtermButton.setToolTip('open xterm') # noinspection PyUnresolvedReferences self.xtermButton.pressed.connect(self._onXtermButton) self.hLayout = QHBoxLayout() self.hLayout.setContentsMargins(0, 0, 0, 0) self.hLayout.addWidget(self.hostnameField) self.hLayout.addWidget(self.sepLabel) self.hLayout.addWidget(self.pathField) self.hLayout.addWidget(self.problemIndicator) self.hLayout.addWidget(self.xtermButton) self.hLayout.setStretchFactor(self.pathField, 2) self.locationWidget = QWidget(parent) self.locationWidget.setLayout(self.hLayout) self.textField = self._TerminalTextEdit( warningColor=warningHighlightColor, errorColor=errorHighlightColor, parent=parent) self.textField.setColor(self._inactiveColor) self.textField.closeRequest.connect(self.closeRequest.emit) self.textField.reRunProcess.connect(self._reRun) self.textField.terminateProcess.connect(self.terminate) self.textField.standaloneRequest.connect(self.toggleStandalone) self.vLayout = QVBoxLayout() self.vLayout.addWidget(self.locationWidget) self.vLayout.addWidget(self.textField) self.setLayout(self.vLayout)
def setColor(self, color): Any.requireIsInstance(color, QColor) self.textField.setColor(color)
def _saveSettings(self): defaultHostnames_nat = ToolBOSConf.getConfigOption('BST_compileHosts') defaultHostnames_xcmp = ToolBOSConf.getConfigOption( 'BST_crossCompileHosts') userCompileHosts = {} userCrossCompileHosts = {} enabledPlatforms_nat = [] enabledPlatforms_xcmp = [] logging.debug('checkbox status:') for platform, checkbox in self._platformCBs_nat.items(): checked = checkbox.isChecked() logging.debug('%s (native): %s', platform, checked) if checked: enabledPlatforms_nat.append(platform) hostnameField = self._hostnameFields_nat[platform] Any.requireIsInstance(hostnameField, QLineEdit) enteredHostname = str(hostnameField.text()) Any.requireIsText(enteredHostname) # might be empty try: defaultHostname = defaultHostnames_nat[platform] except KeyError: defaultHostname = None if defaultHostname is None: defaultHostname = '' if enteredHostname != '' and enteredHostname != defaultHostname: logging.info('user-modified hostname: %s=%s', platform, enteredHostname) userCompileHosts[platform] = enteredHostname for platform, checkbox in self._platformCBs_xcmp.items(): checked = checkbox.isChecked() logging.debug('%s (cross): %s', platform, checked) if checked: enabledPlatforms_xcmp.append(platform) hostnameField = self._hostnameFields_xcmp[platform] Any.requireIsInstance(hostnameField, QLineEdit) enteredHostname = str(hostnameField.text()) Any.requireIsText(enteredHostname) # might be empty try: defaultHostname = defaultHostnames_xcmp[platform] except KeyError: defaultHostname = None if defaultHostname is None: defaultHostname = '' if enteredHostname != '' and enteredHostname != defaultHostname: logging.info('user-modified hostname: %s=%s', platform, enteredHostname) userCrossCompileHosts[platform] = enteredHostname enabledPlatforms_nat.sort() enabledPlatforms_xcmp.sort() self._toolBOSConf.setUserConfigOption('BST_defaultPlatforms_native', enabledPlatforms_nat) self._toolBOSConf.setUserConfigOption('BST_defaultPlatforms_xcmp', enabledPlatforms_xcmp) self._toolBOSConf.setUserConfigOption('BST_userCompileHosts', userCompileHosts) self._toolBOSConf.setUserConfigOption('BST_userCrossCompileHosts', userCrossCompileHosts) self._toolBOSConf.save()
def _parseSqArgs(cr, argv): import re from ToolBOSCore.SoftwareQuality import CheckRoutine, Rules Any.requireIsInstance(cr, CheckRoutine.CheckRoutine) Any.requireIsList(argv) try: # ensure that script-name does not appear in this list argv.remove(sys.argv[0]) except ValueError: pass ruleIDs = Rules.getRuleIDs() forceDirs = set() forceFiles = set() forceLevel = None forceRules = [] for arg in argv: if arg in ruleIDs: logging.debug('requested checking rule ID: %s', arg) forceRules.append(arg) elif os.path.isdir(arg): logging.debug('requested checking directory: %s', arg) forceDirs.add(os.path.abspath(arg)) elif os.path.exists(arg): logging.debug('requested checking file: %s', arg) forceFiles.add(os.path.abspath(arg)) elif arg.startswith('sqLevel='): tmp = re.search('sqLevel=(\S+)', ' '.join(argv)) if tmp: forceLevel = tmp.group(1) else: msg = '%s: No such file or directory, or rule ID' % arg raise ValueError(msg) if forceDirs: logging.debug('check directories: %s', forceDirs) cr.setDirs(forceDirs) if forceFiles: logging.debug('check files: %s', forceFiles) cr.setFiles(forceRules) if forceLevel: logging.debug('check level: %s', forceLevel) cr.setLevel(forceLevel) if forceRules: logging.debug('check rules: %s', forceRules) cr.setRules(forceRules) cr.showSummary(False) else: cr.showSummary(True)
def __init__(self, model, parent=None): super(QWidget, self).__init__() Any.requireIsInstance(model, QtPackageModel.BSTPackageModel) self.parent = parent self.model = model self._pkgCreator = None self._settingsDialog = None self._sqDialog = None self._busyDialog = None iconSize = QSize(32, 32) self.updateButton = QToolButton() self.updateButton.setEnabled(False) self.updateButton.setIcon( IconProvider.getIcon('software-update-available')) self.updateButton.setIconSize(iconSize) self.updateButton.setToolTip( 'No patches available, package is up-to-date') self.updateButton.clicked.connect(self._onUpdateButtonPressed) settingsButton = QToolButton() settingsButton.setIconSize(iconSize) settingsButton.setToolTip('set preferences') settingsButton.setIcon(IconProvider.getIcon('preferences-system')) settingsButton.clicked.connect(self._onSettingsButtonPressed) logo = QLabel() logo.setPixmap(PixmapProvider.getPixmap('ToolBOS-Logo-small')) logo.setAlignment(Qt.AlignCenter) icemonButton = QToolButton() icemonButton.setIconSize(iconSize) icemonButton.setToolTip('compile farm status (Icecream Monitor)') icemonButton.setIcon(IconProvider.getIcon('IcecreamMonitor')) icemonButton.clicked.connect(self._onIceMonButtonPressed) sqButton = QToolButton() sqButton.setIconSize(iconSize) sqButton.setToolTip('Software Quality') sqButton.setIcon(IconProvider.getIcon('QualityGuideline')) sqButton.clicked.connect(self._onSoftwareQualityDialogPressed) iconGrid = QGridLayout() iconGrid.setContentsMargins(0, 0, 0, 0) iconGrid.addWidget(icemonButton, 0, 0) iconGrid.addWidget(sqButton, 0, 1) iconGrid.addWidget(self.updateButton, 1, 0) iconGrid.addWidget(settingsButton, 1, 1) iconWidget = QGroupBox('utilities', self) iconWidget.setLayout(iconGrid) mainLayout = QVBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.addStretch(1) mainLayout.addWidget(logo) mainLayout.addStretch(1) mainLayout.addWidget(iconWidget) self.setLayout(mainLayout)
def _onDepDetectorError(self, data): Any.requireIsInstance(data, QByteArray) text = UnicodeSupport.convertQByteArray(data) logging.error(text)
def _onDepDetectorFinished(self): logging.debug( 'dependency detection in progress (helper-process finished)') self._depDetectorData.flush() base64payload = self._depDetectorData.getvalue() base64payloadSize = len(base64payload) base64payloadType = type(base64payload) logging.debug('base64payload type: %s', base64payloadType) logging.debug('base64payload size: %d', base64payloadSize) if base64payloadSize == 0: logging.debug('no dependency data received') return if six.PY2: if not Any.isInstance(base64payload, unicode): logging.debug('received dependency data of unexpected type') logging.debug( '(this could come from a ~/.bashrc which prints text)') return else: if not Any.isInstance(base64payload, bytes): logging.debug('received dependency data of unexpected type') logging.debug( '(this could come from a ~/.bashrc which prints text)') return dillPayload = base64.b64decode(base64payload) dillPayloadSize = len(dillPayload) dillPayloadType = type(dillPayload) logging.debug('dillPayload type: %s', dillPayloadType) logging.debug('dillPayload size: %d', dillPayloadSize) data = dill.loads(dillPayload) Any.requireIsDictNonEmpty(data) Any.requireIsInstance(data['bstpkg_src'], BSTPackage.BSTSourcePackage) Any.requireIsInstance(data['bstpkg_global'], BSTPackage.BSTGloballyInstalledPackage) Any.requireIsDict(data['installStatus']) Any.requireIsDict(data['installStatusLocal']) Any.requireIsDict(data['installStatusProxy']) Any.requireIsDict(data['installStatusGlobal']) self._bstpkg_src.depSet = data['bstpkg_src'].depSet self._bstpkg_src.depTree = data['bstpkg_src'].depTree self._bstpkg_global = data['bstpkg_global'] try: self._bstpkg_global.open(self.getCanonicalPath()) except AssertionError as details: logging.debug(details) self._installStatus = data['installStatus'] self._installStatusLocal = data['installStatusLocal'] self._installStatusProxy = data['installStatusProxy'] self._installStatusGlobal = data['installStatusGlobal'] logging.debug('depSet: %s', self._bstpkg_src.depSet) logging.debug('depTree: %s', self._bstpkg_src.depTree) logging.debug('revDepSet: %s', self._bstpkg_global.revDepSet) logging.debug('revDepTree: %s', self._bstpkg_global.revDepTree) self.depsDetected.emit(True) # retrieving direct dependencies should work, consider an error if not try: Any.requireIsSet(self._bstpkg_src.depSet) Any.requireIsList(self._bstpkg_src.depTree) except AssertionError: self.depsDetected.emit(False) logging.error('unable to retrieve dependencies') # while for reverse dependencies it is significant if the package is # installed, yet if self._bstpkg_global.isInstalled(): try: Any.requireIsSet(self._bstpkg_global.revDepSet) Any.requireIsList(self._bstpkg_global.revDepTree) except AssertionError: logging.error('unable to retrieve reverse dependencies') else: logging.debug('not globally installed --> no reverse dependencies') logging.debug('dependency detection finished')
def unsetEnv(self, name): Any.requireIsTextNonEmpty(name) Any.requireIsInstance(self._env, QProcessEnvironment) self._env.remove(name)
status = ProjectProperties.isInstalled(packageURL, sitRootPath) installStatusGlobal[packageURL] = status logging.debug('installed globally: %s = %s', packageURL, status) data = { 'bstpkg_src': bstpkg_src, 'bstpkg_global': bstpkg_global, 'installStatus': installStatus, 'installStatusLocal': installStatusLocal, 'installStatusProxy': installStatusProxy, 'installStatusGlobal': installStatusGlobal } dillPayload = dill.dumps(data) Any.requireIsInstance(dillPayload, bytes) base64payload = base64.b64encode(dillPayload) Any.requireIsInstance(base64payload, bytes) if six.PY2: strPayload = str(base64payload) else: strPayload = str(base64payload, 'utf-8') Any.requireIsInstance(strPayload, str) print(strPayload, end='') # EOF