Пример #1
0
def test_xmodem(filepath, protocol='xmodem1k'):
    import os
    from x84.bbs import echo, send_modem, recv_modem, getterminal
    term = getterminal()

    echo(u"\r\n\r\n")

    # test bbs sending to client
    stream = open(filepath, 'rb')
    echo(u"Sending {0} using protocol {1}. \r\n"
         u"Start your receiving program now. \r\n"
         u"Press ^X twice to cancel: "
         .format(filepath, protocol))
    status = send_modem(stream, protocol)
    if not status:
        echo(u"\r\nThat didn't go so well.. "
             u"status={0}; sorry!\r\n".format(status))
        term.inkey()
        return

    # test client sending to bbs
    echo(u"Now its your turn cowboy -- send me anything\r\n"
         u"using the {0} protocol. really, I don't care.\r\n"
         .format(protocol))
    stream = open(os.devnull, 'wb')
    if not recv_modem(stream, protocol):
        echo(u"That didn't go so well.. sorry!\r\n")
        term.inkey()
        return

    echo(u"fine shooting, soldier!\r\n")
    term.inkey()
Пример #2
0
def upload_files(term, protocol='xmodem1k'):
    """ Upload files. """
    echo(term.clear)
    while True:
        echo(u'Filename (empty to quit):\r\n')
        led = LineEditor(width=term.width - 1)
        led.refresh()
        inp = led.read()
        led = None
        if inp:
            for illegal in (os.path.sep, u'..', u'~',):
                if illegal in inp:
                    echo(term.bold_red(u'\r\nIllegal filename.\r\n'))
                    term.inkey()
                    return

            echo(term.bold(
                u'\r\nBegin your {0} sending program now.\r\n'
                .format(protocol)))

            upload_filename = os.path.join(UPLOADS_DIR, inp)
            try:
                upload = open(upload_filename, 'wb')
            except IOError as err:
                echo(term.bold_red('u\r\nIOError: {err}\r\n'.format(err=err)))
            else:
                if not recv_modem(upload, protocol):
                    echo(term.bold_red(u'Upload failed!\r\n'))
                    os.unlink(upload_filename)
                else:
                    echo(term.bold_green(u'Transfer succeeded.\r\n'))
            term.inkey()
        else:
            return
Пример #3
0
def upload_files(term, protocol='xmodem1k'):
    """ Upload files. """
    echo(term.clear)
    while True:
        echo(u'Filename (empty to quit):\r\n')
        led = LineEditor(width=term.width - 1)
        led.refresh()
        inp = led.read()
        led = None
        if inp:
            for illegal in (os.path.sep, u'..', u'~',):
                if illegal in inp:
                    echo(term.bold_red(u'\r\nIllegal filename.\r\n'))
                    term.inkey()
                    return

            echo(term.bold(
                u'\r\nBegin your {0} sending program now.\r\n'
                .format(protocol)))

            upload_filename = os.path.join(UPLOADS_DIR, inp)
            try:
                upload = open(upload_filename, 'wb')
            except IOError as err:
                echo(term.bold_red('u\r\nIOError: {err}\r\n'.format(err=err)))
            else:
                if not recv_modem(upload, protocol):
                    echo(term.bold_red(u'Upload failed!\r\n'))
                    os.unlink(upload_filename)
                else:
                    echo(term.bold_green(u'Transfer succeeded.\r\n'))
            term.inkey()
        else:
            return
Пример #4
0
def test_xmodem(filepath, protocol='xmodem1k'):
    import os
    from x84.bbs import echo, send_modem, recv_modem, getterminal
    term = getterminal()

    echo(u"\r\n\r\n")

    # test bbs sending to client
    stream = open(filepath, 'rb')
    echo(u"Sending {0} using protocol {1}. \r\n"
         u"Start your receiving program now. \r\n"
         u"Press ^X twice to cancel: ".format(filepath, protocol))
    status = send_modem(stream, protocol)
    if not status:
        echo(u"\r\nThat didn't go so well.. "
             u"status={0}; sorry!\r\n".format(status))
        term.inkey()
        return

    # test client sending to bbs
    echo(u"Now its your turn cowboy -- send me anything\r\n"
         u"using the {0} protocol. really, I don't care.\r\n".format(protocol))
    stream = open(os.devnull, 'wb')
    if not recv_modem(stream, protocol):
        echo(u"That didn't go so well.. sorry!\r\n")
        term.inkey()
        return

    echo(u"fine shooting, soldier!\r\n")
    term.inkey()