def start_server_and_listen(launchui, use_auth, analytics_manager, max_tries=5): """The primary entry point for launching the daemon. Args: launchui: set to true to open a browser window use_auth: set to true to enable http authentication analytics_manager: to send analytics """ analytics_manager.send_server_startup() log_support.configure_analytics_handler(analytics_manager) tries = 1 while tries < max_tries: log.info('Making attempt %s / %s to startup', tries, max_tries) try: daemon_server = DaemonServer(analytics_manager) yield daemon_server.start(use_auth, launchui) analytics_manager.send_server_startup_success() break except Exception as e: log.exception('Failed to startup') yield daemon_server.stop() analytics_manager.send_server_startup_error(str(e)) tries += 1 else: log.warn("Exceeded max tries to start up, stopping") reactor.callFromThread(reactor.stop)
def finishLaunching(self): self.connection = False statusbar = AppKit.NSStatusBar.systemStatusBar() self.statusitem = statusbar.statusItemWithLength_(AppKit.NSVariableStatusItemLength) self.icon = AppKit.NSImage.alloc().initByReferencingFile_(ICON_PATH) self.icon.setScalesWhenResized_(True) self.icon.setSize_((20, 20)) self.statusitem.setImage_(self.icon) self.menubarMenu = AppKit.NSMenu.alloc().init() self.open = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Open", "openui:", "") self.menubarMenu.addItem_(self.open) self.quit = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( "Quit", "replyToApplicationShouldTerminate:", "" ) self.menubarMenu.addItem_(self.quit) self.statusitem.setMenu_(self.menubarMenu) self.statusitem.setToolTip_(APP_NAME) if test_internet_connection(): if platform.mac_ver()[0] >= "10.10": LBRYNotify("Starting LBRY") else: if platform.mac_ver()[0] >= "10.10": LBRYNotify("LBRY needs an internet connection to start, try again when one is available") sys.exit(0) lbry = DaemonServer() d = lbry.start() d.addCallback(lambda _: webbrowser.open(UI_ADDRESS)) lbrynet_server = server.Site(lbry.root) lbrynet_server.requestFactory = DaemonRequest reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE)
def start_server_and_listen(launchui, use_auth, analytics_manager): """The primary entry point for launching the daemon. Args: launchui: set to true to open a browser window use_auth: set to true to enable http authentication analytics_manager: to send analytics """ daemon_server = DaemonServer(analytics_manager) d = daemon_server.start(use_auth) if launchui: d.addCallback(lambda _: webbrowser.open(settings.UI_ADDRESS)) d.addCallback(lambda _: analytics_manager.send_server_startup_success()) d.addErrback(log.fail(kill, analytics_manager), 'Failed to startup')
def start_server_and_listen(launchui, use_auth, analytics_manager): """The primary entry point for launching the daemon. Args: launchui: set to true to open a browser window use_auth: set to true to enable http authentication analytics_manager: to send analytics kwargs: passed along to `DaemonServer().start()` """ daemon_server = DaemonServer(analytics_manager) d = daemon_server.start() d.addCallback(lambda _: listen(daemon_server, use_auth)) if launchui: d.addCallback(lambda _: webbrowser.open(settings.UI_ADDRESS)) d.addCallback(lambda _: analytics_manager.send_server_startup_success()) d.addErrback(log_and_kill, analytics_manager)
def start_server_and_listen(launchui, use_auth, analytics_manager): """The primary entry point for launching the daemon. Args: launchui: set to true to open a browser window use_auth: set to true to enable http authentication analytics_manager: to send analytics """ analytics_manager.send_server_startup() log_support.configure_analytics_handler(analytics_manager) try: daemon_server = DaemonServer(analytics_manager) yield daemon_server.start(use_auth, launchui) analytics_manager.send_server_startup_success() except Exception as e: log.exception('Failed to startup') analytics_manager.send_server_startup_error(str(e)) reactor.callFromThread(reactor.stop)
def main(lbry_name=None): def LBRYApp(): return SysTrayIcon(icon, hover_text, menu_options, on_quit=stop) def openui_(sender): webbrowser.open(UI_ADDRESS) def replyToApplicationShouldTerminate_(): try: reactor.stop() except error.ReactorNotRunning: log.debug('Reactor already stopped') def stop(sysTrayIcon): replyToApplicationShouldTerminate_() if getattr(sys, 'frozen', False) and os.name == "nt": icon = os.path.join(os.path.dirname(sys.executable), ICON_PATH, 'lbry16.ico') else: icon = os.path.join(ICON_PATH, 'lbry16.ico') hover_text = APP_NAME menu_options = (('Open', icon, openui_), ) if not test_internet_connection(): log.warn('No Internet Connection') sys.exit(1) systray_thread = threading.Thread(target=LBRYApp) systray_thread.daemon = True systray_thread.start() lbry = DaemonServer() d = lbry.start() d.addCallback(lambda _: LBRYURIHandler.open_address(lbry_name)) lbrynet_server = server.Site(lbry.root) lbrynet_server.requestFactory = DaemonRequest try: reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE) except error.CannotListenError: log.info('Daemon already running, exiting app') sys.exit(1) reactor.run()
def main(lbry_name=None): def LBRYApp(): return SysTrayIcon(icon, hover_text, menu_options, on_quit=stop) def openui_(sender): webbrowser.open(UI_ADDRESS) def replyToApplicationShouldTerminate_(): try: reactor.stop() except error.ReactorNotRunning: log.debug('Reactor already stopped') def stop(sysTrayIcon): replyToApplicationShouldTerminate_() if getattr(sys, 'frozen', False) and os.name == "nt": icon = os.path.join(os.path.dirname(sys.executable), ICON_PATH, 'lbry16.ico') else: icon = os.path.join(ICON_PATH, 'lbry16.ico') hover_text = APP_NAME menu_options = (('Open', icon, openui_),) if not test_internet_connection(): log.warn('No Internet Connection') sys.exit(1) systray_thread = threading.Thread(target=LBRYApp) systray_thread.daemon = True systray_thread.start() lbry = DaemonServer() d = lbry.start() d.addCallback(lambda _: LBRYURIHandler.open_address(lbry_name)) lbrynet_server = server.Site(lbry.root) lbrynet_server.requestFactory = DaemonRequest try: reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE) except error.CannotListenError: log.info('Daemon already running, exiting app') sys.exit(1) reactor.run()
def start_server_and_listen(launchui, use_auth, analytics_manager, max_tries=5): """The primary entry point for launching the daemon. Args: launchui: set to true to open a browser window use_auth: set to true to enable http authentication analytics_manager: to send analytics """ analytics_manager.send_server_startup() daemon_server = DaemonServer(analytics_manager) try: yield daemon_server.start(use_auth, launchui) analytics_manager.send_server_startup_success() except Exception as e: log.exception('Failed to startup') yield daemon_server.stop() analytics_manager.send_server_startup_error(str(e)) reactor.fireSystemEvent("shutdown")
def finishLaunching(self): self.connection = False statusbar = AppKit.NSStatusBar.systemStatusBar() self.statusitem = statusbar.statusItemWithLength_( AppKit.NSVariableStatusItemLength) self.icon = AppKit.NSImage.alloc().initByReferencingFile_(ICON_PATH) self.icon.setScalesWhenResized_(True) self.icon.setSize_((20, 20)) self.statusitem.setImage_(self.icon) self.menubarMenu = AppKit.NSMenu.alloc().init() self.open = AppKit.NSMenuItem.alloc( ).initWithTitle_action_keyEquivalent_("Open", "openui:", "") self.menubarMenu.addItem_(self.open) self.quit = AppKit.NSMenuItem.alloc( ).initWithTitle_action_keyEquivalent_( "Quit", "replyToApplicationShouldTerminate:", "") self.menubarMenu.addItem_(self.quit) self.statusitem.setMenu_(self.menubarMenu) self.statusitem.setToolTip_(APP_NAME) if test_internet_connection(): if platform.mac_ver()[0] >= "10.10": LBRYNotify("Starting LBRY") else: if platform.mac_ver()[0] >= "10.10": LBRYNotify( "LBRY needs an internet connection to start, try again when one is available" ) sys.exit(0) lbry = DaemonServer() d = lbry.start() d.addCallback(lambda _: webbrowser.open(UI_ADDRESS)) lbrynet_server = server.Site(lbry.root) lbrynet_server.requestFactory = DaemonRequest reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE)
def start(): parser = argparse.ArgumentParser(description="Launch lbrynet-daemon") parser.add_argument("--wallet", help="lbrycrd or lbryum, default lbryum", type=str, default='') parser.add_argument("--ui", help="path to custom UI folder", default=None) parser.add_argument("--branch", help="Branch of lbry-web-ui repo to use, defaults on master") parser.add_argument('--no-launch', dest='launchui', action="store_false") parser.add_argument('--log-to-console', dest='logtoconsole', action="store_true") parser.add_argument('--quiet', dest='quiet', action="store_true") parser.add_argument('--verbose', action='store_true', help='enable more debug output for the console') parser.set_defaults(branch=False, launchui=True, logtoconsole=False, quiet=False) args = parser.parse_args() log_support.configure_file_handler(lbrynet_log) log_support.configure_loggly_handler() if args.logtoconsole: log_support.configure_console(level='DEBUG') log_support.disable_third_party_loggers() if not args.verbose: log_support.disable_noisy_loggers() try: JSONRPCProxy.from_url(API_CONNECTION_STRING).is_running() log.info("lbrynet-daemon is already running") if not args.logtoconsole: print "lbrynet-daemon is already running" if args.launchui: webbrowser.open(UI_ADDRESS) return except: pass log.info("Starting lbrynet-daemon from command line") if not args.logtoconsole and not args.quiet: print "Starting lbrynet-daemon from command line" print "To view activity, view the log file here: " + lbrynet_log print "Web UI is available at http://%s:%i" % (API_INTERFACE, API_PORT) print "JSONRPC API is available at " + API_CONNECTION_STRING print "To quit press ctrl-c or call 'stop' via the API" if test_internet_connection(): lbry = DaemonServer() d = lbry.start(branch=args.branch if args.branch else DEFAULT_UI_BRANCH, user_specified=args.ui, wallet=args.wallet, branch_specified=True if args.branch else False) if args.launchui: d.addCallback(lambda _: webbrowser.open(UI_ADDRESS)) lbrynet_server = server.Site(lbry.root) lbrynet_server.requestFactory = DaemonRequest reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE) reactor.run() if not args.logtoconsole and not args.quiet: print "\nClosing lbrynet-daemon" else: log.info("Not connected to internet, unable to start") if not args.logtoconsole: print "Not connected to internet, unable to start" return
def start(): parser = argparse.ArgumentParser(description="Launch lbrynet-daemon") parser.add_argument("--wallet", help="lbrycrd or lbryum, default lbryum", type=str, default='') parser.add_argument("--ui", help="path to custom UI folder", default=None) parser.add_argument( "--branch", help="Branch of lbry-web-ui repo to use, defaults on master") parser.add_argument('--no-launch', dest='launchui', action="store_false") parser.add_argument('--log-to-console', dest='logtoconsole', action="store_true") parser.add_argument('--quiet', dest='quiet', action="store_true") parser.add_argument('--verbose', action='store_true', help='enable more debug output for the console') parser.set_defaults(branch=False, launchui=True, logtoconsole=False, quiet=False) args = parser.parse_args() log_support.configure_file_handler(lbrynet_log) log_support.configure_loggly_handler() if args.logtoconsole: log_support.configure_console(level='DEBUG') log_support.disable_third_party_loggers() if not args.verbose: log_support.disable_noisy_loggers() try: JSONRPCProxy.from_url(API_CONNECTION_STRING).is_running() log.info("lbrynet-daemon is already running") if not args.logtoconsole: print "lbrynet-daemon is already running" if args.launchui: webbrowser.open(UI_ADDRESS) return except: pass log.info("Starting lbrynet-daemon from command line") if not args.logtoconsole and not args.quiet: print "Starting lbrynet-daemon from command line" print "To view activity, view the log file here: " + lbrynet_log print "Web UI is available at http://%s:%i" % (API_INTERFACE, API_PORT) print "JSONRPC API is available at " + API_CONNECTION_STRING print "To quit press ctrl-c or call 'stop' via the API" if test_internet_connection(): lbry = DaemonServer() d = lbry.start( branch=args.branch if args.branch else DEFAULT_UI_BRANCH, user_specified=args.ui, wallet=args.wallet, branch_specified=True if args.branch else False) if args.launchui: d.addCallback(lambda _: webbrowser.open(UI_ADDRESS)) lbrynet_server = server.Site(lbry.root) lbrynet_server.requestFactory = DaemonRequest reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE) reactor.run() if not args.logtoconsole and not args.quiet: print "\nClosing lbrynet-daemon" else: log.info("Not connected to internet, unable to start") if not args.logtoconsole: print "Not connected to internet, unable to start" return