def __init__(self, server=None, palette='default', keymap='default', debug=False, disable_sync=False, fetch_missing_refs=False, path=config.DEFAULT_CONFIG_PATH): self.server = server self.config = config.Config(server, palette, keymap, path) if debug: level = logging.DEBUG else: level = logging.WARNING logging.basicConfig(filename=self.config.log_file, filemode='w', format='%(asctime)s %(message)s', level=level) self.log = logging.getLogger('gertty.App') self.log.debug("Starting") self.fetch_missing_refs = fetch_missing_refs self.config.keymap.updateCommandMap() self.search = search.SearchCompiler(self) self.db = db.Database(self) self.sync = sync.Sync(self) self.screens = [] self.status = StatusHeader(self) self.header = urwid.AttrMap(self.status, 'header') screen = view_project_list.ProjectListView(self) self.status.update(title=screen.title) self.loop = urwid.MainLoop(screen, palette=self.config.palette.getPalette(), unhandled_input=self.unhandledInput) has_subscribed_projects = False with self.db.getSession() as session: if session.getProjects(subscribed=True): has_subscribed_projects = True if not has_subscribed_projects: self.welcome() self.sync_pipe = self.loop.watch_pipe(self.refresh) self.loop.screen.tty_signal_keys(start='undefined', stop='undefined') #self.loop.screen.set_terminal_properties(colors=88) if not disable_sync: self.sync_thread = threading.Thread(target=self.sync.run, args=(self.sync_pipe, )) self.sync_thread.daemon = True self.sync_thread.start() else: self.sync_thread = None self.sync.offline = True self.status.update(offline=True)
def __call__(self, parser, namespace, values, option_string=None): cf = config.Config(namespace.server, namespace.palette, namespace.keymap, namespace.path) url = values[0] result = urlparse.urlparse(values[0]) if not url.startswith(cf.url): print('Supplied URL must start with %s' % (cf.url,)) sys.exit(1) s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(cf.socket_path) s.sendall('open %s\n' % url) sys.exit(0)
def __init__(self, server=None, palette='default', keymap='default', debug=False, verbose=False, disable_sync=False, disable_background_sync=False, fetch_missing_refs=False, path=config.DEFAULT_CONFIG_PATH): self.server = server self.config = config.Config(server, palette, keymap, path) if debug: level = logging.DEBUG elif verbose: level = logging.INFO else: level = logging.WARNING logging.basicConfig(filename=self.config.log_file, filemode='w', format='%(asctime)s %(message)s', level=level) # Python2.6 Logger.setLevel doesn't convert string name # to integer code. Here, we set the requests logger level to # be less verbose, since our logging output duplicates some # requests logging content in places. req_level_name = 'WARN' req_logger = logging.getLogger('requests') if sys.version_info < (2, 7): level = logging.getLevelName(req_level_name) req_logger.setLevel(level) else: req_logger.setLevel(req_level_name) self.log = logging.getLogger('gertty.App') self.log.debug("Starting") self.project_cache = ProjectCache() self.ring = mywid.KillRing() self.input_buffer = [] webbrowser.register('xdg-open', None, BackgroundBrowser("xdg-open")) self.fetch_missing_refs = fetch_missing_refs self.config.keymap.updateCommandMap() self.search = search.SearchCompiler(self.config.username) self.db = db.Database(self, self.config.dburi, self.search) self.sync = sync.Sync(self, disable_background_sync) self.screens = [] self.status = StatusHeader(self) self.header = urwid.AttrMap(self.status, 'header') screen = view_project_list.ProjectListView(self) self.status.update(title=screen.title) self.updateStatusQueries() self.loop = urwid.MainLoop(screen, palette=self.config.palette.getPalette(), handle_mouse=self.config.handle_mouse, unhandled_input=self.unhandledInput) self.sync_pipe = self.loop.watch_pipe(self.refresh) self.error_queue = queue.Queue() self.error_pipe = self.loop.watch_pipe(self._errorPipeInput) self.logged_warnings = set() self.command_pipe = self.loop.watch_pipe(self._commandPipeInput) self.command_queue = queue.Queue() warnings.showwarning = self._showWarning has_subscribed_projects = False with self.db.getSession() as session: if session.getProjects(subscribed=True): has_subscribed_projects = True if not has_subscribed_projects: self.welcome() self.loop.screen.tty_signal_keys(start='undefined', stop='undefined') #self.loop.screen.set_terminal_properties(colors=88) self.startSocketListener() if not disable_sync: self.sync_thread = threading.Thread(target=self.sync.run, args=(self.sync_pipe,)) self.sync_thread.daemon = True self.sync_thread.start() else: self.sync_thread = None self.sync.offline = True self.status.update(offline=True)