Esempio n. 1
0
    def start(self):
        reactor.listenTCP(52045, ServerFactory(self), interface='localhost')
        try:
            os.makedirs(self.config.config_dir)
        except OSError:
            pass
        if self.args.debug:
            logging.basicConfig(format='%(asctime)s %(funcName)s %(message)s',
                                level=logging.DEBUG,
                                stream=sys.stdout)
        else:
            logfile = os.path.join(self.config.config_dir, 'gridsync.log')
            logging.basicConfig(format='%(asctime)s %(funcName)s %(message)s',
                                level=logging.INFO,
                                filename=logfile)
        logging.info("Server started with args: {}".format((self.args)))
        logging.debug("$PATH is: {}".format(os.getenv('PATH')))
        try:
            output = Tahoe().command(["--version-and-path"])
            logging.info(output.split('\n')[0])
        except Exception as e:
            logging.error('Error checking Tahoe-LAFS version: {}'.format(e))
            # TODO: Notify user?
        try:
            self.settings = self.config.load()
        except IOError:
            self.settings = {}

        if not self.settings:
            reactor.callLater(0, self.first_run)
        else:
            self.initialize_gateways()
            reactor.callLater(0, self.start_gateways)
        if not self.args.no_gui:
            self.tray = SystemTrayIcon(self)
            self.tray.show()
        state_checker = LoopingCall(self.check_state)
        state_checker.start(1.0)
        connection_status_updater = LoopingCall(reactor.callInThread,
                                                self.update_connection_status)
        reactor.callLater(5, connection_status_updater.start, 60)
        reactor.callLater(1, self.start_sync_folders)
        reactor.addSystemEventTrigger("before", "shutdown", self.stop)
        reactor.suggestThreadPoolSize(20)  # XXX Adjust?
        reactor.run()
Esempio n. 2
0
 def start(self):
     reactor.listenTCP(52045, CoreFactory(self), interface='localhost')
     try:
         os.makedirs(self.config.config_dir)
     except OSError:
         pass
     if self.args.debug:
         logging.basicConfig(
             format='%(asctime)s %(funcName)s %(message)s',
             level=logging.DEBUG,
             stream=sys.stdout)
     else:
         logfile = os.path.join(self.config.config_dir, 'gridsync.log')
         logging.basicConfig(
             format='%(asctime)s %(funcName)s %(message)s',
             level=logging.INFO,
             filename=logfile)
     logging.info("Core started with args: %s", self.args)
     logging.debug("$PATH is: %s", os.getenv('PATH'))
     try:
         self.settings = self.config.load()
     except IOError:
         self.settings = {}
     if not self.settings:
         reactor.callLater(0, self.first_run)
     else:
         self.initialize_gateways()
         reactor.callLater(0, self.start_gateways)
     if not self.args.no_gui:
         self.tray = SystemTrayIcon(self)
         self.tray.show()
     state_checker = LoopingCall(self.check_state)
     state_checker.start(1.0)
     connection_status_updater = LoopingCall(
         reactor.callInThread, self.update_connection_status)
     reactor.callLater(5, connection_status_updater.start, 60)
     reactor.callLater(1, self.start_sync_folders)
     reactor.addSystemEventTrigger("before", "shutdown", self.stop)
     reactor.suggestThreadPoolSize(20)  # XXX Adjust?
     reactor.run()