コード例 #1
0
ファイル: main.py プロジェクト: jlmitch5/druid
def crowreconnect():
    global crow
    try:
        crow = crowlib.connect()
        myprint(" <online!>\n")
    except ValueError as err:
        myprint(" <lost connection>\n")
コード例 #2
0
ファイル: main.py プロジェクト: jlmitch5/druid
def main():
    logging.config.dictConfig({
        'version': 1,
        'formatters': {
            'detailed': {
                'class':
                'logging.Formatter',
                'format':
                '%(asctime)s %(name)-15s %(levelname)-8s'
                '%(processName)-10s %(message)s'
            },
        },
        'handlers': {
            'file': {
                'class': 'logging.FileHandler',
                'filename': 'druid.log',
                'mode': 'w',
                'formatter': 'detailed',
            },
        },
        'loggers': {
            'crowlib': {
                'handlers': ['file'],
            },
        },
        'root': {
            'level': 'DEBUG',
            'handlers': [],
        },
    })

    global crow
    loop = asyncio.get_event_loop()

    try:
        crow = crowlib.connect()
    except ValueError as err:
        print(err)
        exit()

    # run script passed from command line
    if len(sys.argv) == 2:
        crowlib.execute(crow.write, myprint, sys.argv[1])

    use_asyncio_event_loop()

    with patch_stdout():
        background_task = asyncio.gather(printer(), return_exceptions=True)
        loop.run_until_complete(shell())
        background_task.cancel()
        loop.run_until_complete(background_task)

    crow.close()
    exit()
コード例 #3
0
ファイル: download.py プロジェクト: jlmitch5/druid
def main():
    try:
        crow = crowlib.connect()
    except ValueError as err:
        print(err)
        exit()

    crow.write(bytes('^^p', 'utf-8'))
    print(crow.read(1000000).decode())

    crow.close()
    exit()
コード例 #4
0
ファイル: repl.py プロジェクト: Jwhiles/druid
def crowreconnect(errmsg=None):
    global crow
    global is_connected
    try:
        crow = crowlib.connect()
        myprint(" <crow connected>\n")
        is_connected = True
    except ValueError:
        if errmsg is not None:
            myprint(" <{}>\n".format(errmsg))
        elif is_connected == True:
            myprint(" <crow disconnected>\n")
            is_connected = False
コード例 #5
0
def download():
    """
    Download a file from crow and print it to stdout
    """
    try:
        crow = crowlib.connect()
    except ValueError as err:
        click.echo(err)
        sys.exit(1)

    crow.write(bytes("^^p", "utf-8"))
    click.echo(crow.read(1000000).decode())
    crow.close()
コード例 #6
0
def upload(filename):
    """
    Upload a file to crow.
    FILENAME is the path to the Lua file to upload
    """
    try:
        crow = crowlib.connect()
    except ValueError as err:
        click.echo(err)
        sys.exit(1)

    crowlib.upload(crow.write, myprint, filename)
    click.echo(crow.read(1000000).decode())
    click.echo("File uploaded")
    time.sleep(0.5)  # wait for new script to be ready
    crow.write(bytes("^^p", "utf-8"))
    click.echo(crow.read(1000000).decode())
    crow.close()
コード例 #7
0
ファイル: upload.py プロジェクト: jlmitch5/druid
def main():
    try:
        crow = crowlib.connect()
    except ValueError as err:
        print(err)
        exit()

    # run script passed from command line
    if len(sys.argv) == 2:
        crowlib.upload(crow.write, myprint, sys.argv[1])
        print(crow.read(1000000).decode())
        print(' file uploaded:')
        time.sleep(0.5)  # wait for new script to be ready
        crow.write(bytes('^^p', 'utf-8'))
        print(crow.read(1000000).decode())
    else:
        print('usage: python3 upload.py file-to-upload.lua')

    crow.close()
    exit()