Esempio n. 1
0
    def run_command(self, command, seconds=None):
        """
            Run a command on the system and keep the user updated on the completeness.
        """
        proc = Process(command.strip().split(" "))

        self.display_progress(0)
        start_time = time.time()
        while True:
            time.sleep(.1)
            sys.stdout.flush()
            poll = proc.wait(os.WNOHANG)
            if poll != None:
                break
            line = proc.read()
            if "PERCENT COMPLETE:" in line:
                self.display_progress(
                    float(
                        line.split("PERCENT COMPLETE:")[-1].replace("\n", "")))
            if seconds:
                current_time = time.time()
                if current_time - start_time > seconds:
                    break
                self.display_progress(
                    float(current_time - start_time) * 100. / seconds)
        try:
            proc.kill(signal.SIGTERM)
        except OSError:
            pass
        self.display_progress(100)
        print
Esempio n. 2
0
def call_cmd(cmd, timeout=-1, output_filter=None, cwd=None, check_ret=None):
    '''
    Utility to call a command.
    timeout is in seconds.
    '''
    print("call_cmd: calling " + " ".join(cmd))
    p = Process(cmd, cwd=cwd, stderr=subprocess.STDOUT)
    launch_time = time.clock()
    output = ""

    while True:
        # check to see if process has ended
        ret = p.wait(os.WNOHANG)
        # print any new output
        o = p.read()
        if len(o) > 0:
            print("output = %s" % o)

        if output_filter:
            output_filter(p, o, output)
        output += o
        time.sleep(1)

        if ret is not None:
            if check_ret is not None:
                assert check_ret == ret
            return ret, output

        if timeout > 0 and time.clock() - launch_time > timeout:
            p.kill(signal.SIGKILL)
            if check_ret is not None:
                assert check_ret == -1
            return -1, output
Esempio n. 3
0
def call_cmd(cmd, timeout=-1, output_filter=None, cwd=None, check_ret=None):
    '''
    Utility to call a command.
    timeout is in seconds.
    '''
    print("call_cmd: calling " + " ".join(cmd))
    p = Process(cmd, cwd=cwd, stderr=subprocess.STDOUT)
    launch_time = time.clock()
    output = ""

    while True:
        # check to see if process has ended
        ret = p.wait(os.WNOHANG)
        # print any new output
        o = p.read()
        if len(o) > 0:
            print("output = %s" % o)

        if output_filter:
            output_filter(p, o, output)
        output += o
        time.sleep(1)

        if ret is not None:
            if check_ret is not None:
                assert check_ret == ret
            return ret, output

        if timeout > 0 and time.clock() - launch_time > timeout:
            p.kill(signal.SIGKILL)
            if check_ret is not None:
                assert check_ret == -1
            return -1, output
Esempio n. 4
0
    def run_command(self,command,seconds=None):
        """
            Run a command on the system and keep the user updated on the completeness.
        """
        proc = Process(command.strip().split(" "))

        self.display_progress(0)
        start_time = time.time()
        while True:
            time.sleep(.1)
            sys.stdout.flush()
            poll = proc.wait(os.WNOHANG)
            if poll != None:
                break
            line = proc.read()
            if "PERCENT COMPLETE:" in line:
                try:
                    self.display_progress(float(line.split("PERCENT COMPLETE:")[-1].replace("\n","")))
                except ValueError:
                    pass
            if seconds:
                current_time = time.time()
                if current_time-start_time>seconds:
                    break
                self.display_progress(float(current_time-start_time)*100./seconds)
        try:
            proc.kill(signal.SIGTERM)
        except OSError:
            pass
        self.display_progress(100)
        print
Esempio n. 5
0
                    channels, sample_rate, sample_width)).split(),\
                    env={"AUDIO_PATH":"./audio"})
            print("Started decoder")
            decode_pipe = decode_process
            print("Opened decode pipe")
            playback.set_source(decode_process)
            play_thread = Thread(target=playback.start)
            play_thread.start()
            print("Started playback thread")
            while True:
                bts = client.recv(1024)
                print(len(bts))
                if len(bts) < 1024:
                    decode_pipe.write(bts)
                    break
                while len(bts):
                    bts = bts[decode_pipe.write(bts):]
            decode_pipe.close()
            play_thread.join()
        except SocketException as e:
            print(e.strerror)
        client.close()
        decode_process.kill(signal.SIGTERM)
except KeyboardInterrupt:
    print("Stopping")
except Exception as e:
    print(e.strerror)
server_socket.close()
print("Closed server socket")