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)
try: pid = os.fork() if pid > 0: # exit first parent return pid except OSError, e: print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror) return 0 os.chdir("/") os.setsid() os.umask(0) os.execvp(cmd, cmdVector) def getAllFromProgram(regex, cmd): "will open a file and parse through the whole thing, looking for matches to the provided regex" c = re.compile(regex, re.M) status, output = runcmd(cmd,0) if output == "error": return '' matches = c.findall(output) if matches != None: if len(matches) > 0: return matches[0] return '' if __name__ == "__main__": from libTest import startTest, runTest, endTest status = startTest() endTest(status)