Exemple #1
0
def upgradePrePostScript(scannersConfigFile, scannerPlatformConfig, Framework):
    logger.debug('Installing pre/post script')

    BASEDIR = Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR)
    platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM)
    unixConfig = scannersConfigFile.getPlatformConfiguration('unix', "")
    #whether run or not pre-scan and post-scan scripts
    isPrePostScriptAllowed = Boolean.parseBoolean(Framework.getParameter('IsPrePostScriptAllowed'))
    logger.debug("isPrePostScriptAllowed:", isPrePostScriptAllowed)
    if not isPrePostScriptAllowed:
        return

    isAllUnix = False
    preScanScriptLocalPath = getPrePostScriptLocalPath(scannerPlatformConfig.getScannerPreScanScriptLocalFile())
    logger.debug('preScanScriptLocalPath:', preScanScriptLocalPath)
    if  InventoryUtils.isUnix(platform) and not os.path.exists(preScanScriptLocalPath):
        logger.debug("No specific platform for the device, use all-unix.")
        isAllUnix = True
        preScanScriptLocalPath = getPrePostScriptLocalPath(unixConfig.getScannerPreScanScriptLocalFile())
        logger.debug("preScanScriptLocalPath:", preScanScriptLocalPath)

    postScanScriptLocalPath = getPrePostScriptLocalPath(scannerPlatformConfig.getScannerPostScanScriptLocalFile())
    logger.debug('postScanScriptLocalPath:', postScanScriptLocalPath)
    if  InventoryUtils.isUnix(platform) and not os.path.exists(postScanScriptLocalPath):
        logger.debug("No specific platform for the device, use all-unix.")
        isAllUnix = True
        postScanScriptLocalPath = getPrePostScriptLocalPath(unixConfig.getScannerPostScanScriptLocalFile())
        logger.debug('postScanScriptLocalPath:', postScanScriptLocalPath)

    preScanScriptRemotePath = BASEDIR + scannerPlatformConfig.getScannerPreScanScriptRemoteFile()
    logger.debug('preScanScriptRemotePath:', preScanScriptRemotePath)
    postScanScriptRemotePath = BASEDIR + scannerPlatformConfig.getScannerPostScanScriptRemoteFile()
    logger.debug('postScanScriptRemotePath:', postScanScriptRemotePath)

    if  os.path.exists(preScanScriptLocalPath):
        InventoryUtils.copyLocalFileToRemote(Framework, preScanScriptLocalPath, preScanScriptRemotePath)

    if  os.path.exists(postScanScriptLocalPath):
        InventoryUtils.copyLocalFileToRemote(Framework, postScanScriptLocalPath, postScanScriptRemotePath)

    # upgrade resource files for PrePostScript
    upgradePrePostScriptResource(isAllUnix, Framework)

    Framework.setProperty(InventoryUtils.SCANNER_PRE_SCAN_SCRIPT_REMOTE_PATH, preScanScriptRemotePath)
    Framework.setProperty(InventoryUtils.SCANNER_POST_SCAN_SCRIPT_REMOTE_PATH, postScanScriptRemotePath)
Exemple #2
0
def terminateScanner(Framework, shell, scannerRemoteExecutable):
    platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM)
    if InventoryUtils.isUnix(platform):
        psArgs = ' -e ' 
        if platform == 'macosx':
            psArgs = ' -A '
        cmdOutput = shell.execCmd('ps' + psArgs + '| grep ' + scannerRemoteExecutable)
        if cmdOutput and len(cmdOutput) > 0:
            pid = cmdOutput.split()[0]
            if pid.isdigit():
                shell.execCmd('kill ' + pid)
    else:
        cmdOutput = shell.execCmd('tasklist /FO csv | findstr ' + scannerRemoteExecutable)
        if cmdOutput and len(cmdOutput) > 0:
            pid = cmdOutput.split('","')[1]
            if pid.isdigit():
                shell.execCmd('taskkill /PID ' + pid)