def run(self): """Start up the application.""" args = [sys.argv[0]] qt_options = self.options.qt_options args += map(lambda o: '-{0}'.format(o.strip()), qt_options.split(',')) app = singleton(Bluepass, args) addr = gruvi.paddr(self.options.connect) ctrlapi = singleton(ControlApiClient) ctrlapi.connect(addr) ctrlapi.login(self.options.auth_token) return app.exec_()
def test_fortune(self): proc = Process(encoding='ascii') proc.spawn([sys.executable, '-u', 'fortune.py'], stdout=PIPE) line = proc.stdout.readline() self.assertTrue(line.startswith('Listen on ')) addr = gruvi.paddr(line[10:]) client = HttpClient() client.connect(addr) client.request('GET', '/') response = client.getresponse() fortune = response.read().decode('ascii') client.close() self.assertTrue('Albert Einstein' in fortune) proc.send_signal(signal.SIGINT) proc.wait(timeout=1) self.assertEqual(proc.returncode, 0) proc.close()
def test_echoserver2(self): proc = Process(encoding='ascii') proc.spawn([sys.executable, '-u', 'echoserver2.py'], stdout=PIPE) line = proc.stdout.readline() self.assertTrue(line.startswith('Listen on ')) addr = gruvi.paddr(line[10:]) client = StreamClient() client.connect(addr) client.write(b'foo') self.assertEqual(client.read(3), b'foo') client.write(b'foo bar baz\n') self.assertEqual(client.readline(), b'foo bar baz\n') client.close() proc.send_signal(signal.SIGINT) proc.wait(timeout=1) self.assertEqual(proc.returncode, 0) proc.close()
def run(self): """Initialize the backend and run its main loop.""" self._log.debug('initializing backend components') self._log.debug('initializing password generator') pwgen = singleton(PasswordGenerator) self._log.debug('initializing document store') fname = os.path.join(self.options.data_dir, 'bluepass.db') store = singleton(Store, fname) self._log.debug('initializing model') model = singleton(Model, store) token = {'id': self.options.auth_token, 'expires': 0, 'allow': {'control_api': True}} model.create_token(token) self._log.debug('initializing locator') locator = singleton(Locator) for ls in platform.get_location_sources(): self._log.debug('adding location source: {}', ls.name) locator.add_source(ls()) self._log.debug('initializing sync API') syncapi = singleton(SyncApiServer) syncapi.listen(('0.0.0.0', 0)) self._log.debug('initializing sync API publisher') publisher = singleton(SyncApiPublisher, syncapi) publisher.start() if locator.sources: self._log.debug('initializing background sync worker') syncer = singleton(Syncer) syncer.start() else: self._log.warning('no location sources available') self._log.warning('network synchronization is disabled') self._log.debug('initializing control API') ctrlapi = singleton(ControlApiServer) if self.options.trace: tracename = os.path.join(self.options.data_dir, 'backend.trace') tracefile = open(tracename, 'w') ctrlapi._set_tracefile(tracefile) addr = gruvi.paddr(self.options.listen) ctrlapi.listen(addr) fname = os.path.join(self.options.data_dir, 'backend.run') addr = ctrlapi.addresses[0] runinfo = { 'listen': gruvi.saddr(addr), 'pid': os.getpid() } util.write_atomic(fname, json.dumps(runinfo)) #self._log.debug('initializing client API') #clientapi = singleton(ClientApiServer) #clientapi.listen() # This is where the backend runs (until stop_event is raised or CTRL-C # is pressed). self._stop_event.wait() self._log.debug('backend event loop terminated') self._log.debug('shutting down control API') ctrlapi.close() self._log.debug('shutting down document store') store.close() self._log.debug('stopped all backend components') return 0