Beispiel #1
0
    def pin(self, gui, hash, timeLimit):
        if timeLimit is None: timer = self.MaxWaitTime
        else: timer = timeLimit
        max = timer
        #self.Server.pin(hash)
        try:  ### Added shell == False...
            p = sp.Popen(["ipfs", "pin", "add", f"{hash}"],
                         shell=False,
                         stdout=sp.PIPE,
                         stderr=sp.STDOUT)
        except Exception as e:
            sg.popup("Aw shucks, something went wrong...",
                     inspect.stack()[1][3] + ' error: ' + str(e))
            return False

        output = ""
        result = None
        progress = 0
        pop = gui.progressWindow("open", 400, 200, 0, timer,
                                 max)  # Show progress popup
        while True:
            pinOut = nonblock_read(p.stdout)  # Get output if any available
            if pinOut is None:  # Subprocess closed stream
                p.wait()
                if f"pinned {hash}" in output:  # Pinned successfully?
                    result = True
                else:
                    result = False
                break  # We're done here
            elif len(pinOut) > 0:
                output += str(pinOut)
                progress += 1
#               resWin['-PROG-'].update(current_count=progress, max=max)
            else:
                time.sleep(1)
                timer -= 1
                #                minutes, s = divmod(timer, 60)
                #                h, m = divmod(minutes, 60)
                if timer < 1: break
#                else: resWin['-TIMR-'].update("%02d:%02d:%02d" % (h, m, s))
            gui.progressWindow(pop, 0, 0, progress, timer, max)  # Decr timer

        gui.progressWindow(pop, 0, 0, -1, 0, max)  # Close the progress popup
        return result
Beispiel #2
0
    def get(self, hash, gui, x, y, ipns=None, save=None):
        if save: out = save
        else: out = hash + ".file"
        if ipns: hash = '/ipns/' + hash  # Add ipNs prefix
        #self.Server.get(hash, target=self.DLfolder)
        args = ["ipfs", "get", f"-o={out}", f"{hash}"]

        # Use command line for now to run the IPFS command
        try:
            p = sp.Popen(args, shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
        except Exception as e:
            sg.popup("Aw shucks, something went wrong...",
                     inspect.stack()[1][3] + ' error: ' + str(e),
                     location=(locX + 300, locY - 100))
            return False

        output = ""
        result = False
        progress = 0
        max = self.MaxWaitTime
        timer = max
        pop = gui.progressWindow("open", x, y, 0, timer,
                                 max)  # Show progress popup
        while True:
            getOut = nonblock_read(p.stdout)  # Get output if any
            if getOut is None:  # Subprocess closed stream
                p.wait()
                if "100.00%" in output:  # Success?
                    result = True
                break  # Yep! We're done here
            elif len(getOut) > 0:
                output += str(getOut)  # Accumulate output
                progress += 1
            else:
                time.sleep(1)  # Wait a bit
                timer -= 1
                if timer < 1: break
            gui.progressWindow(pop, x, y, progress, timer, max)  # Decr timer

        gui.progressWindow(pop, 0, 0, -1, 0, max)  # Close the progress popup
        return result
            if moveY is True:
                if random.randint(0, 1) == 0:
                    # Go left
                    monsterPos[1] = max(monsterPos[1] - 1, 0)
                else:
                    monsterPos[1] = min(monsterPos[1] + 1, WALL_NORTH)

        # See if we got eaten
        if monsterPos == [x, y]:
            tries = 0
            output('YOU WERE EATEN BY THE MONSTER!\n')
            keepGoing = False
            break

        # Check for any input, and process a single command.
        data = nonblock_read(sys.stdin, 1, 't')

        # We have a loop here so we can break, it will only ever have 1 element per the limit above
        for character in data:
            if character == 'q':
                tries = 0
                keepGoing = False
                break
            elif character == 'w':
                y += 1
                output('You take a step north.\n')
                if y > WALL_NORTH:
                    output('You hit the north wall!\n\n')
                    y = WALL_NORTH
            elif character == 's':
                y -= 1
Beispiel #4
0
            if moveY is True:
                if random.randint(0, 1) == 0:
                    # Go left
                    monsterPos[1] = max(monsterPos[1] - 1, 0)
                else:
                    monsterPos[1] = min(monsterPos[1] + 1, WALL_NORTH)

        # See if we got eaten
        if monsterPos == [x, y]:
            tries = 0
            output('YOU WERE EATEN BY THE MONSTER!\n')
            keepGoing = False
            break

        # Check for any input, and process a single command.
        data = nonblock_read(sys.stdin, 1, 't')

        # We have a loop here so we can break, it will only ever have 1 element per the limit above
        for character in data:
            if character == 'q':
                tries = 0
                keepGoing = False
                break
            elif character == 'w':
                y += 1
                output('You take a step north.\n')
                if y > WALL_NORTH:
                    output('You hit the north wall!\n\n')
                    y = WALL_NORTH
            elif character == 's':
                y -= 1
Beispiel #5
0
from nonblock import nonblock_read

# pipe = subprocess.Popen(['someProgram'], stdout=subprocess.PIPE)

# ...

while True:
    data = nonblock_read(pipe.stdout)
    if data is None:
        print 'None'
    elif data:
        # Some data has been read, process it
        # processData(data)
        print data
# else:
# 	# No data is on buffer, but subprocess has not closed stream
# 	idleTask()

# All data has been processed, focus on the idle task
# idleTask()