コード例 #1
0
    def parseArgs(self, args):
        # Parse the arguments looking for required parameters.
        # Return false if any tests fail.

        subtestResults = []
        subtestMessages = []
        rval = True

        # Instantiate the ArgParser
        ap = ArgParser(args)

        # check for optional debug flag
        self.bInDebug = ap.isInArgs("-debug", False)

        # check for action
        self.action = "NOT_SET"
        rv = False
        if (ap.isInArgs("-action", True)):
            # action value must appear after target
            self.action = ap.getArgValue("-action")
            rv = True
        else:
            subtestMessages.append("-action with arg is required.")
        subtestResults.append(rv)

        # check for input filename
        if (ap.isInArgs("-infile", True)):
            # filename value must appear after target
            self.inputFile = ap.getArgValue("-infile")
            rv = True
        else:
            rv = False
            subtestMessages.append("-infile with arg is required.")
        subtestResults.append(rv)

        # check for target path
        if (ap.isInArgs("-targetpath", True)):
            # filename value must appear after target
            self.targetPath = ap.getArgValue("-targetpath")
            rv = True
        else:
            if (self.action == "genscript"):
                rv = False
                subtestMessages.append(
                    "-targetpath required when -action is genscript.")
        subtestResults.append(rv)

        # Determine if all subtests passed
        for idx in range(len(subtestResults)):
            if (self.bInDebug):
                print("Arg subtest " + str(subtestResults[idx]))
            rval = rval and subtestResults[idx]

        if (rval == False):
            for idx in range(len(subtestMessages)):
                if (self.bInDebug):
                    print("ArgParse message: " + str(subtestMessages[idx]))

        return (rval)
コード例 #2
0
def parseArgs():

    # Parse the arguments looking for required parameters.
    # Return false if any tests fail.

    global bDictionaryMatchRequired, osType, inputFilename, targetLength

    subtestResults = []
    rval = True

    # Instantiate the ArgParser
    ap = ArgParser(sys.argv)

    # check the OS type
    rv = False
    if (ap.isArgWithValue("-os", "mac") or ap.isArgWithValue("-os", "win")):
        osType = ap.getArgValue("-os")
        rv = True
    subtestResults.append(rv)

    # check for input filename
    inputFilename = "NOT_SET"
    rv = False
    if (ap.isInArgs("-infile", True)):
        # input filename value must appear after target
        inputFilename = ap.getArgValue("-infile")
        rv = True
    subtestResults.append(rv)

    # check for target length
    targetLength = -1
    rv = False
    if (ap.isInArgs("-targetlen", True)):
        # input filename value must appear after target
        targetLength = int(ap.getArgValue("-targetlen"))
        rv = True
    subtestResults.append(rv)

    # check for the optional dictionary match flag
    bDictionaryMatchRequired = ap.isInArgs("-dictionarymatch", False)

    # Determine if all subtests passed
    for idx in range(len(subtestResults)):
        rval = rval and subtestResults[idx]

    return (rval)
コード例 #3
0
    def parseArgs(self, args):
        # Parse the arguments looking for required parameters.
        # Return false if any tests fail.

        # global osType, action, searchType, targetPhrase

        subtestResults = []
        subtestResultMessages = []
        rval = True

        # Instantiate the ArgParser
        ap = ArgParser(args)

        # check for optional debug flag
        self.bInDebug = ap.isInArgs("-debug", False)

        # check the OS type
        subtestResultMessages.append("-os %s" % self.doOSCheck(ap))
        subtestResults.append(self.doOSCheck(ap))

        # check for action
        self.action = "NOT_SET"
        rv = False
        if (ap.isInArgs("-action", True)):
            # action value must appear after target
            self.action = ap.getArgValue("-action")
            rv = True
        subtestResultMessages.append("-action %s" % rv)
        subtestResults.append(rv)

        # check for searchtype
        # using a different arg parse approach than the OS check.
        self.doSearchTypeCheck(ap, subtestResults, subtestResultMessages)

        # check for JumblePt2
        self.doJumblePt2Check(ap, subtestResults, subtestResultMessages)

        # check for Wordle
        self.doWorldleCheck(ap, subtestResults, subtestResultMessages)

        # check for genmask
        if (self.action == "genmask"):
            # GenMask requires a target
            rv = False
            if (ap.isInArgs("-target", True)):
                self.targetPhrase = ap.getArgValue("-target")
                rv = True
            subtestResultMessages.append("-genmask %s" % rv)
            subtestResults.append(rv)

        # check for maintenance
        if (self.action == "maint"):
            rv = False
            if (ap.isInArgs("-mainttype", True)):
                self.maintType = ap.getArgValue("-mainttype")
                if (self.maintType == "addword"):
                    if (ap.isInArgs("-target", True)):
                        self.targetPhrase = ap.getArgValue("-target")
                        rv = True

                # no additional checks for adding sort column
                if (self.maintType == "gensortcolumn"):
                    rv = True
            subtestResultMessages.append("-mainttype %s" % rv)
            subtestResults.append(rv)

        if (self.action == "addword"):
            rv = False
            if (ap.isInArgs("-target", True)):
                self.targetPhrase = ap.getArgValue("-target")
                rv = True
            else:
                rv = False

            subtestResultMessages.append("-addword %s" % rv)
            subtestResults.append(rv)

        # Determine if all subtests passed
        for aMsg in subtestResultMessages:
            if (self.bInDebug):
                msg = "Arg subtest {0}".format(aMsg)
                print(msg)

        for aSubResult in subtestResults:
            rval = rval and aSubResult

        return (rval)
コード例 #4
0
    def parseArgs(self, args):
        # Parse the arguments looking for required parameters.
        # Return false if any tests fail.
        subtestResults = []
        rval = True

        # Instantiate the ArgParser
        ap = ArgParser(args)

        # check for optional debug flag
        self.bInDebug = ap.isInArgs("-debug", False)

        # check the OS type
        rv = False
        if (ap.isArgWithValue("-os", "mac")
                or ap.isArgWithValue("-os", "win")):
            self.osType = ap.getArgValue("-os")
            rv = True
        subtestResults.append(rv)

        # check for action
        self.action = "NOT_SET"
        rv = False
        if (ap.isInArgs("-action", True)):
            # action value must appear after target
            self.action = ap.getArgValue("-action")
            rv = True
        subtestResults.append(rv)

        # check for searchtype, using a different arg parse approach than the OS check.
        if (self.action == "search"):
            rv = False
            if (ap.isInArgs("-searchtype", True)):
                # value must be either word or pattern
                st = ap.getArgValue("-searchtype")
                validSearchTypes = ["word", "pattern", "encword", "jumble"]
                for vst in validSearchTypes:
                    if (st == vst):
                        self.searchType = st
                        rv = True
            subtestResults.append(rv)

            # search also requires a target
            rv = False
            if (ap.isInArgs("-target", True)):
                self.targetPhrase = ap.getArgValue("-target")
                rv = True
            subtestResults.append(rv)

        # check for JumblePt2
        if (self.action == "jumblept2"):
            rv = False
            if (ap.isInArgs("-windowsize", True)):
                self.windowSize = int(ap.getArgValue("-windowsize"))
                rv = True
            subtestResults.append(rv)

            # JumblePt2 also requires a target
            rv = False
            if (ap.isInArgs("-target", True)):
                self.targetPhrase = ap.getArgValue("-target")
                rv = True
            subtestResults.append(rv)

        # check for 7lw (Seven Little Words)
        if (self.action == "7lw"):
            rv = False
            if (ap.isInArgs("-windowsize", True)):
                self.windowSize = int(ap.getArgValue("-windowsize"))
                rv = True
            subtestResults.append(rv)

            # 7lw also requires an input file
            rv = False
            if (ap.isInArgs("-infile", True)):
                self.inputFile = ap.getArgValue("-infile")
                rv = True
            subtestResults.append(rv)

        # check for genmask
        if (self.action == "genmask"):
            # GenMask requires a target
            rv = False
            if (ap.isInArgs("-target", True)):
                self.targetPhrase = ap.getArgValue("-target")
                rv = True
            subtestResults.append(rv)

        # check for maintenance
        if (self.action == "maint"):
            rv = False
            if (ap.isInArgs("-mainttype", True)):
                self.maintType = ap.getArgValue("-mainttype")
                if (self.maintType == "addword"):
                    if (ap.isInArgs("-target", True)):
                        self.targetPhrase = ap.getArgValue("-target")
                        rv = True

                # no additional checks for adding sort column
                if (self.maintType == "gensortcolumn"):
                    rv = True
            subtestResults.append(rv)

        # Determine if all subtests passed
        for idx in range(len(subtestResults)):
            self.debugMsg("Arg subtest " + str(subtestResults[idx]))
            rval = rval and subtestResults[idx]

        return (rval)