def acceptableNames(self, tokens, index): acceptableNames = self.preferredNames(tokens, index) if self.allowAny and tokens[index]: if tokens[index] not in acceptableNames: acceptableNames.insert(0, tokens[index]) return acceptableNames def match(self, tokens, index): possibleMatches = self.acceptableNames(tokens, index) if not possibleMatches: return NO_MATCH, 1 if len(possibleMatches) > 1: return PARTIAL, 1 return COMPLETE, 1 if __name__ == "__main__": # A server must be enabled for the tests to work properly. from libTest import startTest, runTest, endTest hostField = BomHostField() status = OK startTest() status = runTest(hostField.match, [["bigdb"], 0], (COMPLETE, 1), status) status = runTest(hostField.match, [["bigsam"], 0], (COMPLETE, 1), status) status = runTest(hostField.match, [["foo"], 0], (NO_MATCH, 1), status) status = runTest(hostField.match, [[""], 0], (PARTIAL, 1), status) status = runTest(hostField.preferredNames, [["big"], 0], ['bigap', 'bigdb', 'bigsam'], status) hostField.allowAny = True status = runTest(hostField.acceptableNames, [["12.22.13.0"], 0], ['12.22.13.0'], status) endTest(status)
possibleLocalNames = glob.glob(dest+"*") if dest == '.': possibleLocalNames.append('.') if os.path.isdir(dest): possibleLocalNames.append(dest) return possibleLocalNames return [] def match(self, tokens, index): possibleMatches = self.preferredNames(tokens, index) if not possibleMatches: return NO_MATCH, 1 if len(possibleMatches) > 1: return PARTIAL, 1 return COMPLETE, 1 if __name__ == "__main__": # A server must be enabled for the tests to work properly. from libTest import startTest, runTest, endTest hostField = ScpHostField() status = OK startTest() status = runTest(hostField.preferredNames, [["bigap:/usr/l"], 0], ['bigap:/usr/lib/', 'bigap:/usr/libexec/', 'bigap:/usr/local/'], status) status = runTest(hostField.preferredNames, [["biga"], 0], ['bigap'], status) status = runTest(hostField.preferredNames, [["/usr/l"], 0], ['/usr/lib', '/usr/lib64', '/usr/local'], status) status = runTest(hostField.preferredNames, [["/tmp/2.ovpn"], 0], ['/tmp/2.ovpn'], status) status = runTest(hostField.preferredNames, [["bigap:/tmp/"], 0], ['bigap:/tmp/sudoers', 'bigap:/tmp/'], status) #status = runTest(hostField.preferredNames, [["/tmp/"], 0], ['/tmp/'], status) endTest(status)
return PARTIAL, lengthOfMatch return COMPLETE, lengthOfMatch return PARTIAL, lengthOfMatch if __name__ == "__main__": from libTest import startTest, runTest, endTest import Integer import BomHostField import PackageField import glob output = ['casDB-patch-R3O-9', 'uhrDB-patch-R3AB_7-4', 'mcsDB-patch-R2S-1', 'casDB-patch-R3Q-5', 'rmsDB-install-12', 'uhrDB-patch-R3AB_9-5', 'casDB-patch-R3X-11', 'rmsDB-patch-R3I-8', 'LogReport-193-3', 'uhrDB-patch-R3AB_6-7', 'uhrDB-patch-R3K-8', 'CgAuthorization-1', 'rmsDB-patch-R3K-8', 'HostAuthorization-24', 'uhrDB-patch-R3S-8', 'uhrDB-patch-R3X-6', 'rmsDB-patch-R3V-10', 'uhrDB-install-11', 'mcsDB-patch-R2AD-6', 'mcsDB-patch-R2U-1', 'uhrDB-patch-R3N-7', 'mcsDB-patch-R2Z-2', 'mcsDB-patch-R2X-3', 'mcsDB-patch-R2Q2-1', 'mcsDB-patch-R2AA-4', 'rmsDB-patch-R3S-5', 'casDB-patch-R3L-8', 'uhrDB-patch-R3AB-7', 'TestPackage-2', 'casDB-patch-R3U-2', 'casDB-patch-R3M-9', 'casDB-install-14', 'uhrDB-patch-R3Z-5', 'rmsDB-patch-R3T-8', 'rmsDB-patch-R3U-3', 'uhrDB-patch-R3AB_5-6', 'DbAuthorization-1', 'rmsDB-patch-R3Y_1-8', 'uhrDB-patch-R3Q-7', 'uhrDB-patch-R3H-8', 'uhrDB-patch-R3J-7', 'mcsDB-patch-R2Q-2', 'CgDbSettings-1', 'casDB-patch-R3Y_1-9', 'rmsDB-patch-R3L-8', 'rmsDB-patch-R3N-9', 'mcsDB-patch-R2T-4', 'uhrDB-patch-R3U-10', 'SqlBackup-8', 'rmsDB-patch-R3Y_5-6', 'casDB-patch-R3J-9', 'mcsDB-install-1', 'uhrDB-patch-R3AB_13-4'] i = Integer.Integer(1, 100) ll = LongList(i) status = OK startTest() status = runTest(ll.preferredNames, [["1"], 0], ["1"], status) status = runTest(ll.preferredNames, [["1", "1", "1"], 0], ["1 1 1"], status) status = runTest(ll.preferredNames, [["1", "2", "3"], 0], ["1 2 3"], status) status = runTest(ll.preferredNames, [["1", "2", "a"], 0], ["1 2"], status) status = runTest(ll.preferredNames, [["1", "a", "2"], 0], ["1"], status) status = runTest(ll.preferredNames, [[""], 0], [], status) status = runTest(ll.match, [[""], 0], (NO_MATCH, 1), status) status = runTest(ll.match, [["1", "2", "3"], 0], (COMPLETE, 3), status) bhf = BomHostField.BomHostField() ll3 = LongList(bhf, unique=True) status = runTest(ll3.preferredNames, [["lilap", "biga"], 0], ["lilap bigap"], status) mode.enabledSystems = [ "lilap", "bigap" ] status = runTest(ll3.preferredNames, [["lilap", ""], 0], [ "lilap bigap" ], status) pf = PackageField.PurgablePackageField() ll2 = LongList(pf, unique=True)
if len(packageNames) != 1: return '' packageName = packageNames[0] if len(tokens) <= index: return '' partialScriptName = tokens[index] possibleMatches = self.possibleScriptNames(packageName, partialScriptName) if possibleMatches: return possibleMatches return '' def match(self, tokens, index): possibleMatches = self.preferredNames(tokens, index) if not possibleMatches: return NO_MATCH, 1 if len(possibleMatches) > 1: return PARTIAL, 1 return COMPLETE, 1 if __name__ == "__main__": from libTest import startTest, runTest, endTest scriptField = ScriptField() status = OK startTest() status = runTest(scriptField.preferredNames, [["bigap", "Conn", "conn"], 2], ["connectTest"], status) status = runTest(scriptField.preferredNames, [["bigs", "con", "co"], 2], ["connectTest"], status) status = runTest(scriptField.preferredNames, [["virtap", "a", "a"], 2], "", status) status = runTest(scriptField.preferredNames, [["foo", "Conn", 'conn'], 2], '', status) endTest(status)
class Variable(PinshCmd.PinshCmd): def __init__(self, name = "variable"): PinshCmd.PinshCmd.__init__(self, name) self.helpText = name+"\ta variable, to be used later with $<variableName>" self.level = 99 self.cmdOwner = 0 def match(self, tokens, index): if tokens[index] == '': return NO_MATCH, 1 okCharacters = set("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_") if set(tokens[index]) - okCharacters: return NO_MATCH, 1 return PARTIAL, 1 def preferredNames(self, tokens, index): if self.match(tokens, index) == (PARTIAL, 1): return [tokens[index]] return [] if __name__ == "__main__": from libTest import startTest, runTest, endTest variable = Variable() status = OK startTest() runTest(variable.match, [[""], 0], (NO_MATCH, 1), status) runTest(variable.match, [["abc123"], 0], (PARTIAL, 1), status) runTest(variable.match, [["~!%^&*"], 0], (NO_MATCH, 1), status) runTest(variable.match, [["kjd;lkadsjf"], 0], (NO_MATCH, 1), status) endTest(status)
def __init__(self, name="["): PinshCmd.PinshCmd.__init__(self, name) self.helpText = "[\tstart a list, end with a ']'" self.level = 99 self.cmdOwner = 0 def match(self, tokens, index): if tokens[index] != "[": return NO_MATCH, 1 if tokens[-1] == "]": return COMPLETE, len(tokens) - index return PARTIAL, len(tokens) - index def preferredNames(self, tokens, index): pyChucker(index) return [tokens[-1], tokens[-1]] if __name__ == "__main__": from libTest import startTest, runTest, endTest listy = List() status = OK startTest() runTest(listy.match, [["[", "foo"], 0], (PARTIAL, 2), status) runTest(listy.match, [["cheeze"], 0], (NO_MATCH, 1), status) runTest(listy.match, [["[", "a", "b", "c"], 0], (PARTIAL, 4), status) runTest(listy.match, [["[", "a", "b", "c", "]"], 0], (COMPLETE, 5), status) runTest(listy.match, [["[", "]"], 0], (COMPLETE, 2), status) endTest(status)
self.level = 99 self.cmdOwner = 0 def match(self, tokens, index): possibleMatches = self.acceptableNames(tokens, index) if not possibleMatches: return NO_MATCH, 1 if len(possibleMatches) > 1: return PARTIAL, 1 return COMPLETE, 1 def preferredNames(self, tokens, index): if tokens[index] == '': return [] cleanedUp = tokens[index] for badCharacter in BAD_CHARACTERS: cleanedUp = cleanedUp.replace(badCharacter, '') return [cleanedUp] if __name__ == "__main__": from libTest import startTest, runTest, endTest hostField = HostField() status = OK startTest() status = runTest(hostField.preferredNames, [["foo"], 0], ["foo"], status) status = runTest(hostField.preferredNames, [["www.foo.com"], 0], ["www.foo.com"], status) status = runTest(hostField.preferredNames, [["a;sdjf#!"], 0], ["asdjf"], status) status = runTest(hostField.preferredNames, [["www.^DH.com"], 0], ["www.DH.com"], status) status = runTest(hostField.match, [[""], 0], (NO_MATCH, 1), status) endTest(status)