def crowreconnect(): global crow try: crow = crowlib.connect() myprint(" <online!>\n") except ValueError as err: myprint(" <lost connection>\n")
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()
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()
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
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()
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()
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()