当前位置: 首页>>代码示例>>Python>>正文


Python CommandHelper.getErrorString方法代码示例

本文整理汇总了Python中src.stonix_resources.CommandHelper.CommandHelper.getErrorString方法的典型用法代码示例。如果您正苦于以下问题:Python CommandHelper.getErrorString方法的具体用法?Python CommandHelper.getErrorString怎么用?Python CommandHelper.getErrorString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在src.stonix_resources.CommandHelper.CommandHelper的用法示例。


在下文中一共展示了CommandHelper.getErrorString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: zzzTestRuleDisableCamera

# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getErrorString [as 别名]
class zzzTestRuleDisableCamera(RuleTest):

    def setUp(self):
        '''
        @change: Breen Malmberg - 06102015 - updated self.cmd and paths to work
        with updated unit test functionality
        '''

        RuleTest.setUp(self)
        self.rule = DisableCamera(self.config,
                                  self.environ,
                                  self.logdispatch,
                                  self.statechglogger)
        self.rulename = self.rule.rulename
        self.rulenumber = self.rule.rulenumber
        self.ch = CommandHelper(self.logdispatch)
        self.cmd = 'chmod a+r '
        self.paths = ['/System/Library/QuickTime/QuickTimeUSBVDCDigitizer.component/Contents/MacOS/QuickTimeUSBVDCDigitizer',
                     '/System/Library/PrivateFrameworks/CoreMediaIOServicesPrivate.framework/Versions/A/Resources/VDC.plugin/Contents/MacOS/VDC',
                     '/System/Library/PrivateFrameworks/CoreMediaIOServices.framework/Versions/A/Resources/VDC.plugin/Contents/MacOS/VDC',
                     '/System/Library/Frameworks/CoreMediaIO.framework/Versions/A/Resources/VDC.plugin/Contents/MacOS/VDC',
                     '/Library/CoreMediaIO/Plug-Ins/DAL/AppleCamera.plugin/Contents/MacOS/AppleCamera']

    def tearDown(self):
        pass

    def runTest(self):
        self.simpleRuleTest()

    def setConditionsForRule(self):
        '''
        Configure system for the unit test
        @param self: essential if you override this definition
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        @change: Breen Malmberg - 06102015 - changed this method to reflect
        the new functionality of DisableCamera.py
        '''
        success = True

        for path in self.paths:
            if os.path.exists(path):
                self.ch.executeCommand(self.cmd + path)
                error = self.ch.getErrorString()
                if error:
                    success = False
        return success

    def checkReportForRule(self, pCompliance, pRuleSuccess):
        '''
        check on whether report was correct
        @param self: essential if you override this definition
        @param pCompliance: the self.iscompliant value of rule
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
                             str(pCompliance) + ".")
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
                             str(pRuleSuccess) + ".")
        success = True
        return success

    def checkFixForRule(self, pRuleSuccess):
        '''
        check on whether fix was correct
        @param self: essential if you override this definition
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
                             str(pRuleSuccess) + ".")
        success = True
        return success

    def checkUndoForRule(self, pRuleSuccess):
        '''
        check on whether undo was correct
        @param self: essential if you override this definition
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
                             str(pRuleSuccess) + ".")
        success = True
        return success
开发者ID:inscriptionweb,项目名称:stonix,代码行数:91,代码来源:zzzTestRuleDisableCamera.py

示例2: MacOSUser

# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getErrorString [as 别名]
class MacOSUser(ManageUser):
    """
    Class to manage users on Mac OS.

    @method findUniqueUid
    @method setUserShell
    @method setUserComment
    @method setUserUid
    @method setUserPriGid
    @method setUserHomeDir
    @method addUserToGroup
    @method rmUserFromGroup
    @method setUserPassword
    @method setUserLoginKeychainPassword
    @method createHomeDirectory
    @method rmUser
    @method rmUserHome

    @author: Roy Nielsen
    """
    def __init__(self, userName="", userShell="/bin/bash",
                 userComment="", userUid=1000, userPriGid=20,
                 userHomeDir="/tmp", logger=False):
        super(MacOSUser, self).__init__(userName, userShell,
                                         userComment, userUid, userPriGid,
                                         userHomeDir, logger)
        self.module_version = '20160225.125554.540679'
        self.dscl = "/usr/bin/dscl"
        self.cmdh = CommandHelper(self.logger)

    #----------------------------------------------------------------------

    def createStandardUser(self, userName, password):
        """
        Creates a user that has the "next" uid in line to be used, then puts
        in in a group of the same id.  Uses /bin/bash as the standard shell.
        The userComment is left empty.  Primary use is managing a user
        during test automation, when requiring a "user" context.

        It does not set a login keychain password as that is created on first
        login to the GUI.

        @author: Roy Nielsen
        """
        self.createBasicUser(userName)
        newUserID = self.findUniqueUid()
        newUserGID = newUserID
        self.setUserUid(userName, newUserID)
        self.setUserPriGid(userName, newUserID)
        self.setUserHomeDir(userName)
        self.setUserShell(userName, "/bin/bash")
        self.setUserPassword(userName, password)
        #####
        # Don't need to set the user login keychain password as it should be
        # created on first login.

    #----------------------------------------------------------------------

    def setDscl(self, directory=".", action="", object="", property="", value=""):
        """
        Using dscl to set a value in a directory...

        @author: Roy Nielsen
        """
        success = False
        reterr = ""
        if directory and action and object and property and value:
            cmd = [self.dscl, directory, action, object, property, value]

            self.cmdh.executeCommand(cmd)
            output = self.cmdh.getOutput()
            reterr = self.cmdh.getErrorString()

            if not reterr:
                success = True
            else:
                raise DsclError("Error trying to set a value with dscl (" + \
                                str(reterr).strip() + ")")
        return success

    def getDscl(self, directory="", action="", dirobj="", property=""):
        """
        Using dscl to retrieve a value from the directory

        @author: Roy Nielsen
        """
        success = False
        reterr = ""
        retval = ""

        #####
        # FIRST VALIDATE INPUT!!
        if isinstance(directory, basestring) and re.match("^[/\.][A-Za-z0-9/]*", directory):
            success = True
        else:
            success = False
        if isinstance(action, basestring) and re.match("^[-]*[a-z]+", action) and success:
            success = True
        else:
            success = False
#.........这里部分代码省略.........
开发者ID:CSD-Public,项目名称:stonix,代码行数:103,代码来源:macos_users.py

示例3: zzzTestDisableAFPFileSharing

# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getErrorString [as 别名]
class zzzTestDisableAFPFileSharing(RuleTest):

    def setUp(self):

        RuleTest.setUp(self)
        self.rule = DisableAFPFileSharing(self.config,
                                self.environ,
                                self.logdispatch,
                                self.statechglogger)
        self.cmdhelper = CommandHelper(self.logdispatch)
        self.rulename = self.rule.rulename
        self.rulenumber = self.rule.rulenumber

    def tearDown(self):
        pass

    def runTest(self):
        self.simpleRuleTest()

    def setConditionsForRule(self):
        '''
        Configure system for the unit test
        @param self: essential if you override this definition
        @return: boolean - If successful True; If failure False
        @author: Breen Malmberg
        '''

        success = True

        try:

            cmd = '/bin/launchctl enable system/com.apple.AppleFileServer'

            self.cmdhelper.executeCommand(cmd)
            retcode = self.cmdhelper.getReturnCode()
            if retcode != 0:
                errstr = self.cmdhelper.getErrorString()
                self.logdispatch.log(LogPriority.DEBUG, errstr)
                success = False

        except Exception:
            raise
        return success

    def checkReportForRule(self, pCompliance, pRuleSuccess):
        '''
        check on whether report was correct
        @param self: essential if you override this definition
        @param pCompliance: the self.iscompliant value of rule
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
                             str(pCompliance) + ".")
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
                             str(pRuleSuccess) + ".")
        success = True
        return success

    def checkFixForRule(self, pRuleSuccess):
        '''
        check on whether fix was correct
        @param self: essential if you override this definition
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
                             str(pRuleSuccess) + ".")
        success = True
        return success

    def checkUndoForRule(self, pRuleSuccess):
        '''
        check on whether undo was correct
        @param self: essential if you override this definition
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
                             str(pRuleSuccess) + ".")
        success = True
        return success
开发者ID:CSD-Public,项目名称:stonix,代码行数:87,代码来源:zzzTestRuleDisableAFPFileSharing.py

示例4: zzzTestRuleNoCoreDumps

# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getErrorString [as 别名]
class zzzTestRuleNoCoreDumps(RuleTest):

    def setUp(self):
        RuleTest.setUp(self)
        self.rule = NoCoreDumps(self.config,
                                self.environ,
                                self.logdispatch,
                                self.statechglogger)
        self.logger = self.logdispatch
        self.rulename = self.rule.rulename
        self.rulenumber = self.rule.rulenumber
        self.checkUndo = True
        self.ch = CommandHelper(self.logger)
    def tearDown(self):
        pass

    def runTest(self):
        self.simpleRuleTest()

    def setConditionsForRule(self):
        """
        Configure system for the unit test
        @param self: essential if you override this definition
        @return: boolean - If successful True; If failure False
        @author: Ekkehard J. Koch
        """
        success = True
        if self.environ.getosfamily() == "linux":
            if not self.setLinuxConditions():
                success = False
        elif self.environ.getostype() == "mac":
            if not self.setMacConditions():
                success = False
        return success

    def setMacConditions(self):
        success = True
        self.ch.executeCommand("/usr/bin/launchctl limit core")
        retcode = self.ch.getReturnCode()
        if retcode != 0:
            self.detailedresults += "\nFailed to run launchctl command to get current value of core dumps configuration"
            errmsg = self.ch.getErrorString()
            self.logger.log(LogPriority.DEBUG, errmsg)
        else:
            output = self.ch.getOutputString()
            if output:
                if not re.search("1", output):
                    self.ch.executeCommand("/usr/bin/launchctl limit core 1 1")

    def setLinuxConditions(self):
        success = True
        path1 = "/etc/security/limits.conf"
        if os.path.exists(path1):
            lookfor1 = "(^\*)\s+hard\s+core\s+0?"
            contents = readFile(path1, self.logger)
            if contents:
                tempstring = ""
                for line in contents:
                    if not re.search(lookfor1, line.strip()):
                        tempstring += line
                if not writeFile(path1, tempstring, self.logger):
                    debug = "unable to write incorrect contents to " + path1 + "\n"
                    self.logger.log(LogPriority.DEBUG, debug)
                    success = False
            if checkPerms(path1, [0, 0, 0o644], self.logger):
                if not setPerms(path1, [0, 0, 0o777], self.logger):
                    debug = "Unable to set incorrect permissions on " + path1 + "\n"
                    self.logger.log(LogPriority.DEBUG, debug)
                    success = False
                else:
                    debug = "successfully set incorrect permissions on " + path1 + "\n"
                    self.logger.log(LogPriority.DEBUG, debug)

        self.ch.executeCommand("/sbin/sysctl fs.suid_dumpable")
        retcode = self.ch.getReturnCode()

        if retcode != 0:
            self.detailedresults += "Failed to get value of core dumps configuration with sysctl command\n"
            errmsg = self.ch.getErrorString()
            self.logger.log(LogPriority.DEBUG, errmsg)
            success = False
        else:
            output = self.ch.getOutputString()
            if output.strip() != "fs.suid_dumpable = 1":
                if not self.ch.executeCommand("/sbin/sysctl -w fs.suid_dumpable=1"):
                    debug = "Unable to set incorrect value for fs.suid_dumpable"
                    self.logger.log(LogPriority.DEBUG, debug)
                    success = False
                elif not self.ch.executeCommand("/sbin/sysctl -p"):
                    debug = "Unable to set incorrect value for fs.suid_dumpable"
                    self.logger.log(LogPriority.DEBUG, debug)
                    success = False
        
        return success

    def checkReportForRule(self, pCompliance, pRuleSuccess):
        """
        check on whether report was correct
        @param self: essential if you override this definition
        @param pCompliance: the self.iscompliant value of rule
#.........这里部分代码省略.........
开发者ID:CSD-Public,项目名称:stonix,代码行数:103,代码来源:zzzTestRuleNoCoreDumps.py

示例5: zzzTestReqPassSysPref

# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getErrorString [as 别名]
class zzzTestReqPassSysPref(RuleTest):

    def setUp(self):

        RuleTest.setUp(self)
        self.rule = ReqPassSysPref(self.config,
                                self.environ,
                                self.logdispatch,
                                self.statechglogger)
        self.cmdhelper = CommandHelper(self.logdispatch)
        self.rulename = self.rule.rulename
        self.rulenumber = self.rule.rulenumber

    def tearDown(self):
        pass

    def runTest(self):
        self.simpleRuleTest()

    def setConditionsForRule(self):
        '''
        Configure system for the unit test
        @param self: essential if you override this definition
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        success = True
        setuplist = ["system.preferences", "system.preferences.accessibility",
                     "system.preferences.accounts", "system.preferences.datetime",
                     "system.preferences.energysaver", "system.preferences.location",
                     "system.preferences.network", "system.preferences.nvram",
                     "system.preferences.parental-controls", "system.preferences.printing",
                     "system.preferences.security", "system.preferences.security.remotepair",
                     "system.preferences.sharing", "system.preferences.softwareupdate",
                     "system.preferences.startupdisk", "system.preferences.timemachine",
                     "system.preferences.version-cue"]
        plistfile = "/System/Library/Security/authorization.plist"
        plistbuddy = "/usr/libexec/PlistBuddy"

        for option in setuplist:
            self.cmdhelper.executeCommand(plistbuddy + " -c 'Set rights:" + option + ":shared 1 " + plistfile)
            errorout = self.cmdhelper.getErrorString()
            if errorout:
                if re.search("Does Not Exist", errorout):
                    self.cmdhelper.executeCommand(plistbuddy + " -c 'Add rights:" + option + ":shared bool true " + plistfile)
                    erradd = self.cmdhelper.getErrorString()
                    if erradd:
                        success = False
        return success

    def checkReportForRule(self, pCompliance, pRuleSuccess):
        '''
        check on whether report was correct
        @param self: essential if you override this definition
        @param pCompliance: the self.iscompliant value of rule
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
                             str(pCompliance) + ".")
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
                             str(pRuleSuccess) + ".")
        success = True
        return success

    def checkFixForRule(self, pRuleSuccess):
        '''
        check on whether fix was correct
        @param self: essential if you override this definition
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
                             str(pRuleSuccess) + ".")
        success = True
        return success

    def checkUndoForRule(self, pRuleSuccess):
        '''
        check on whether undo was correct
        @param self: essential if you override this definition
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: ekkehard j. koch
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
                             str(pRuleSuccess) + ".")
        success = True
        return success
开发者ID:CSD-Public,项目名称:stonix,代码行数:93,代码来源:zzzTestRuleReqPassSysPref.py

示例6: zzzTestRuleSetSSCorners

# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getErrorString [as 别名]
class zzzTestRuleSetSSCorners(RuleTest):
    def setUp(self):
        RuleTest.setUp(self)
        self.rule = SetSSCorners(self.config, self.environ, self.logdispatch, self.statechglogger)
        self.rulename = self.rule.rulename
        self.rulenumber = self.rule.rulenumber
        self.ch = CommandHelper(self.logdispatch)

    def tearDown(self):
        pass

    def runTest(self):
        self.simpleRuleTest()

    def setConditionsForRule(self):
        """
        Configure system for the unit test
        @param self: essential if you override this definition
        @return: boolean - If successful True; If failure False
        @author: Breen Malmberg
        """
        success = True
        self.cmdhelper = CommandHelper(self.logdispatch)
        optdict = {"wvous-tr-corner": 6}
        cmd = "defaults write " + '"' + self.environ.geteuidhome() + '/Library/Preferences/com.apple.dock.plist" '
        for item in optdict:
            self.cmdhelper.executeCommand(cmd + item + " -int " + str(optdict[item]))
            errout = self.cmdhelper.getErrorString()
            if errout:
                success = False
        return success

    def checkReportForRule(self, pCompliance, pRuleSuccess):
        """
        check on whether report was correct
        @param self: essential if you override this definition
        @param pCompliance: the self.iscompliant value of rule
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: Breen Malmberg
        """
        self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + str(pCompliance) + ".")
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + str(pRuleSuccess) + ".")
        success = True
        return success

    def checkFixForRule(self, pRuleSuccess):
        """
        check on whether fix was correct
        @param self: essential if you override this definition
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: Breen Malmberg
        """
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + str(pRuleSuccess) + ".")
        success = True
        return success

    def checkUndoForRule(self, pRuleSuccess):
        """
        check on whether undo was correct
        @param self: essential if you override this definition
        @param pRuleSuccess: did report run successfully
        @return: boolean - If successful True; If failure False
        @author: Breen Malmberg
        """
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + str(pRuleSuccess) + ".")
        success = True
        return success
开发者ID:inscriptionweb,项目名称:stonix,代码行数:71,代码来源:zzzTestRuleSetSSCorners.py


注:本文中的src.stonix_resources.CommandHelper.CommandHelper.getErrorString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。