Exemplo n.º 1
0
def disconnect_device():
    global connected, processes
    data = 'CONNECTED'
    errors = ''
    try:
        if not connected:
            raise Exception('You are not connected.')
        client_socket = sockets[0]
        client_socket.send("X")
        time.sleep(5)
        client_socket.shutdown(socket.SHUT_RDWR)
        while 1:
            try:
                byte = client_socket.recv(1)
                if "" == byte:
                    break
            except:
                break
        for subprocess in processes:
            if subprocess.poll() is None:
                subprocess.kill()
        del processes[:]
        client_socket.close()
        del sockets[:]
        connected = False
        data = "DISCONNECTED"
    except Exception as f:
        errors = str(f)
    output = OrderedDict([('command', 'disconnect'), ('data', data),
                          ('errors', errors)])
    return json.dumps(output)
Exemplo n.º 2
0
    def tearDown(self):
        for proxy_admin_port in self.proxy_admin_ports:
            try:
                r = redis.Redis(port=proxy_admin_port)
                r.shutdown()
            except:
                pass

        for subprocess in self.subprocesses:
            try:
                subprocess.kill()
            except OSError:
                pass
Exemplo n.º 3
0
 def end_process(self, subprocess, signal=signal.SIGINT):
     print('ending process pid', subprocess.pid)
     ppid = subprocess.pid
     try:
         process = psutil.Process(ppid)
     except psutil.NoSuchProcess:
         return
     pids = process.children(recursive=True)
     for pid in pids:
         os.kill(pid.pid, signal)
     subprocess.terminate()
     try:
         subprocess.wait()
     except:
         subprocess.kill()
Exemplo n.º 4
0
def main():
    config = HarnessConfiguration.instance().read()

    if len(config.testables) != 1:
        config.errors.append(
            "Fatal Error: Exactly one testable may be passed.")
        return 1

    def id_generator(zsize, zchars):
        return "".join(random.choice(chars) for x in xrange(zsize))

    # Generate the words we will send to the testable
    words = [
        id_generator(8, string.ascii_lowercase) + "%0.2d" % i
        for i in range(0, 100)
    ]

    # Execute the testable
    subprocess.Popen([config.testables[0]],
                     stdin=subprocess.PIPE,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)

    subprocess.stdin.write(words.join(" "))
    subprocess.stdin.close()

    # Grab all the output
    output = subprocess.stdout.readlines().join("\n")

    # Kill the process if it's still running
    if subprocess.poll() == None:
        subprocess.kill()

    testResults = []
    if "WordsExist" in config.tests:
        testResults.append(testWordsExist(output, words))
    if "LineLengths" in config.tests:
        testResults.append(testLineLengths(output))
    if "Paragraphs" in config.tests:
        testResults.append(testLineLengths(output))

    json.dump(testResults, sys.stdout)
    sys.stderr.write("\n")

    return 0
Exemplo n.º 5
0
def main():
    config = HarnessConfiguration.instance().read()

    if len(config.testables) != 1:
        config.errors.append("Fatal Error: Exactly one testable may be passed.")
        return 1

    def id_generator(zsize, zchars):
        return "".join(random.choice(chars) for x in xrange(zsize))

    # Generate the words we will send to the testable
    words = [id_generator(8, string.ascii_lowercase) + "%0.2d" % i for i in range(0, 100)]

    # Execute the testable
    subprocess.Popen([config.testables[0]], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

    subprocess.stdin.write(words.join(" "))
    subprocess.stdin.close()

    # Grab all the output
    output = subprocess.stdout.readlines().join("\n")

    # Kill the process if it's still running
    if subprocess.poll() == None:
        subprocess.kill()

    testResults = []
    if "WordsExist" in config.tests:
        testResults.append(testWordsExist(output, words))
    if "LineLengths" in config.tests:
        testResults.append(testLineLengths(output))
    if "Paragraphs" in config.tests:
        testResults.append(testLineLengths(output))

    json.dump(testResults, sys.stdout)
    sys.stderr.write("\n")

    return 0
Exemplo n.º 6
0
    while (True):
        print 'Input choice'
        inp = raw_input(u"enter choice or \'Stop\' to exit: ")
        if inp.lower() == 'stop':
            exit()
        elif inp == '9' or inp == '16':
            fistYay(inp)
        elif inp == '0':
            gesture.faceForward()
        elif inp == '1':
            hello(inp)
        elif inp == '2' or inp == '8' or inp == '5' or inp == '17' or inp == '20' or inp == '21':
            oneHandUp(inp)
        elif inp == '3' or inp == '4' or inp == '6' or inp == '18' or inp == '19':
            nod(inp)
        elif inp == '12' or inp == '14':
            shrug(inp)
        elif inp == '11' or inp == '15':
            shrugAndShakeHead(inp)
        elif inp == '7' or inp == '13':
            shakeHead(inp)
        elif inp == '10':
            peace(inp)
        else:
            other(inp)
        '''if inp is not None:
            speak(inp)'''
        #comment this back out when done (below)
        Thread(target=func2).start()
    subprocess.kill()
Exemplo n.º 7
0
 def finish(self):
     for subprocess in self.subprocesses:
         subprocess.kill();
Exemplo n.º 8
0
	def tearDownClass(cls):
		for subprocess in cls.subprocesses:
			subprocess.kill()
		cls.subprocesses = []