async def init_mega_client(holder=[], return_pr=False): if len(holder) == 0: MEGA_API = get_val("MEGA_API") MEGA_UNAME = get_val("MEGA_UNAME") MEGA_PASS = get_val("MEGA_PASS") if MEGA_API is None: return None pr = Popen(["megasdkrest", "--apikey", MEGA_API, "--port", "8200"]) await asyncio.sleep(5) mega_client = MegaSdkRestClient("http://localhost:8200") anon = False if MEGA_UNAME is None: anon = True torlog.warn("Mega Username not specified") if MEGA_PASS is None: anon = True torlog.warn("Mega Password not specified") if anon: torlog.info("Mega running in Anon mode.") else: torlog.info("Mega running in Logged in mode.") try: mega_client.login(MEGA_UNAME, MEGA_PASS) except: torlog.error("Mega login failed.") torlog.info("Started in anon mode.") holder.append(mega_client) holder.append(pr) if return_pr: return holder[1] else: return holder[0]
MEGA_KEY = getConfig('MEGA_KEY') except KeyError: MEGA_KEY = None LOGGER.info('MEGA API KEY NOT AVAILABLE') if MEGA_KEY is not None: # Start megasdkrest binary subprocess.Popen(["megasdkrest", "--apikey", MEGA_KEY]) time.sleep(3) # Wait for the mega server to start listening mega_client = MegaSdkRestClient('http://localhost:6090') try: MEGA_USERNAME = getConfig('MEGA_USERNAME') MEGA_PASSWORD = getConfig('MEGA_PASSWORD') if len(MEGA_USERNAME) > 0 and len(MEGA_PASSWORD) > 0: try: mega_client.login(MEGA_USERNAME, MEGA_PASSWORD) except mega_err.MegaSdkRestClientException as e: logging.error(e.message['message']) exit(0) else: LOGGER.info( "Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!" ) MEGA_USERNAME = None MEGA_PASSWORD = None except KeyError: LOGGER.info( "Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!" ) MEGA_USERNAME = None MEGA_PASSWORD = None