def build_notebook(self, ensure_uptodate=False): # Bit more complicated here due to options to use default and # allow using notebookdialog to prompt # Explicit page argument has priority over implicit from uri # mounting is attempted by zim.notebook.build_notebook() from zim.notebook import FileNotFoundError def prompt_notebook_list(): import zim.gui.notebookdialog return zim.gui.notebookdialog.prompt_notebook() # Can return None if dialog is cancelled used_default = False page = None if self.opts.get('list'): notebookinfo = prompt_notebook_list() else: notebookinfo, page = self.get_notebook_argument() if notebookinfo is None: notebookinfo = self.get_default_or_only_notebook() used_default = notebookinfo is not None if notebookinfo is None: notebookinfo = prompt_notebook_list() if notebookinfo is None: return None, None # Cancelled prompt try: notebook, uripage = build_notebook( notebookinfo) # can raise FileNotFound except FileNotFoundError: if used_default: # Default notebook went missing? Fallback to dialog to allow changing it notebookinfo = prompt_notebook_list() if notebookinfo is None: return None, None # Cancelled prompt notebook, uripage = build_notebook( notebookinfo) # can raise FileNotFound else: raise if ensure_uptodate and not notebook.index.is_uptodate: for info in notebook.index.update_iter(): #logger.info('Indexing %s', info) pass # TODO meaningful info for above message return notebook, page or uripage
def run(self): if self.opts.get('help'): print usagehelp return if len(self.args) == 0: # TODO: find and open the default notebook notebook, ns = build_notebook(nb) print(notebook) else: nbi = resolve_notebook(self.args[0]) notebook, ns = build_notebook(nbi) self.process_subpages(notebook, None)
def build_notebook(self, ensure_uptodate=True): '''Get the L{Notebook} object for this command Tries to automount the file location if needed. @param ensure_uptodate: if C{True} index is updated when needed. Only set to C{False} when index update is handled explicitly (e.g. in the main gui). @returns: a L{Notebook} object and a L{Path} object or C{None} @raises NotebookLookupError: if the notebook could not be resolved or is not given @raises FileNotFoundError: if the notebook location does not exist and could not be mounted. ''' # Explicit page argument has priority over implicit from uri # mounting is attempted by zim.notebook.build_notebook() notebookinfo, page = self.get_notebook_argument( ) # can raise NotebookLookupError if not notebookinfo: raise NotebookLookupError(_('Please specify a notebook')) notebook, uripage = build_notebook( notebookinfo) # can raise FileNotFound if ensure_uptodate and not notebook.index.is_uptodate: for info in notebook.index.update_iter(): #logger.info('Indexing %s', info) pass # TODO meaningful info for above message return notebook, page or uripage
def start(self): # Start server try: uri = self.notebookcombobox.get_notebook() if uri: notebook, x = build_notebook(NotebookInfo(uri)) if not notebook: return else: return port = int(self.portentry.get_value()) public = self.public_checkbox.get_active() self.httpd = make_server(notebook, port, public, **self.interface_opts) if sys.platform == 'win32': # glib io watch conflicts with socket use on windows.. # idle handler uses a bit to much CPU for my taste, # timeout every 0.5 sec is better self.httpd.timeout = 0.1 # 100 ms self._source_id = glib.timeout_add(500, self.do_serve_on_poll) else: self.httpd.timeout = 3 # if no response after 3 sec, drop it self._source_id = glib.io_add_watch( self.httpd.fileno(), glib.IO_IN | glib.IO_OUT | glib.IO_ERR | glib.IO_HUP | glib.IO_PRI, # any event.. self.do_serve_on_io) logger.info("Serving HTTP on %s port %i...", self.httpd.server_name, self.httpd.server_port) except Exception, error: ErrorDialog(self, error).run() return
def start(self): # Start server try: uri = self.notebookcombobox.get_notebook() if uri: notebook, x = build_notebook(NotebookInfo(uri)) if not notebook: return else: return port = int(self.portentry.get_value()) public = self.public_checkbox.get_active() self.httpd = make_server(notebook, port, public, **self.interface_opts) if sys.platform == 'win32': # glib io watch conflicts with socket use on windows.. # idle handler uses a bit to much CPU for my taste, # timeout every 0.5 sec is better self.httpd.timeout = 0.1 # 100 ms self._source_id = glib.timeout_add(500, self.do_serve_on_poll) else: self.httpd.timeout = 3 # if no response after 3 sec, drop it self._source_id = glib.io_add_watch( self.httpd.fileno(), glib.IO_IN | glib.IO_OUT | glib.IO_ERR | glib.IO_HUP | glib.IO_PRI, # any event.. self.do_serve_on_io ) logger.info("Serving HTTP on %s port %i...", self.httpd.server_name, self.httpd.server_port) except Exception, error: ErrorDialog(self, error).run() return
def run(self): ntb_name = self.get_notebook_argument( )[0] or self.get_default_or_only_notebook() ntb, _ = build_notebook(ntb_name) GoogletasksController(notebook=ntb, preferences=GoogletasksCommand.preferences ).fetch() # add new lines
def start(self): # Start server try: uri = self.notebookcombobox.get_notebook() if uri: notebook, x = build_notebook(NotebookInfo(uri)) if not notebook: return else: return if not notebook.index.is_uptodate: for info in notebook.index.update_iter(): #logger.info('Indexing %s', info) pass # TODO meaningful info for above message port = int(self.portentry.get_value()) public = self.public_checkbox.get_active() self.httpd = make_server(notebook, port, public, **self.interface_opts) if sys.platform == 'win32': # GObject io watch conflicts with socket use on windows.. # idle handler uses a bit to much CPU for my taste, # timeout every 0.5 sec is better self.httpd.timeout = 0.1 # 100 ms self._source_id = GObject.timeout_add(500, self.do_serve_on_poll) else: self.httpd.timeout = 3 # if no response after 3 sec, drop it self._source_id = GObject.io_add_watch( self.httpd.fileno(), GObject.IO_IN | GObject.IO_OUT | GObject.IO_ERR | GObject.IO_HUP | GObject.IO_PRI, # any event.. self.do_serve_on_io) logger.info("Serving HTTP on %s port %i...", self.httpd.server_name, self.httpd.server_port) except Exception as error: ErrorDialog(self, error).run() return # Update UI self.notebookcombobox.set_sensitive(False) self.portentry.set_sensitive(False) self.public_checkbox.set_sensitive(False) self.open_button.set_sensitive(False) self.start_button.set_sensitive(False) self.stop_button.set_sensitive(True) self.status_label.set_markup('<i>' + _('Server started') + '</i>') # T: Status in web server gui #if self.public_checkbox.get_active(): # url = 'http://%s:%i' % (self.httpd.server_name, self.httpd.server_port) #else: # url = 'http://localhost:%i' % self.httpd.server_port url = 'http://localhost:%i' % self.httpd.server_port if self.link_button: self.link_button.set_uri(url) self.link_button.set_label(url) self.link_button.set_sensitive(True)
def _set_autocomplete(self, notebook): if notebook: if isinstance(notebook, basestring): notebook = NotebookInfo(notebook) obj, x = build_notebook(notebook) self.form.widgets['namespace'].notebook = obj self.form.widgets['page'].notebook = obj logger.debug('Notebook for autocomplete: %s (%s)', obj, notebook) else: self.form.widgets['namespace'].notebook = None self.form.widgets['page'].notebook = None logger.debug('Notebook for autocomplete unset')
def _set_autocomplete(self, notebook): if notebook: try: if isinstance(notebook, str): notebook = NotebookInfo(notebook) obj, x = build_notebook(notebook) self.form.widgets['namespace'].notebook = obj self.form.widgets['page'].notebook = obj logger.debug('Notebook for autocomplete: %s (%s)', obj, notebook) except: logger.exception('Could not set notebook: %s', notebook) else: self.form.widgets['namespace'].notebook = None self.form.widgets['page'].notebook = None logger.debug('Notebook for autocomplete unset')
def build_notebook(self): '''Get the L{Notebook} object for this command Tries to automount the file location if needed. @returns: a L{Notebook} object and a L{Path} object or C{None} @raises NotebookLookupError: if the notebook could not be resolved or is not given @raises FileNotFoundError: if the notebook location does not exist and could not be mounted. ''' # Explicit page argument has priority over implicit from uri # mounting is attempted by zim.notebook.build_notebook() notebookinfo, page = self.get_notebook_argument() # can raise NotebookLookupError if not notebookinfo: raise NotebookLookupError, _('Please specify a notebook') notebook, uripage = build_notebook(notebookinfo) # can raise FileNotFound return notebook, uripage or page
def build_notebook(self): '''Get the L{Notebook} object for this command Tries to automount the file location if needed. @returns: a L{Notebook} object and a L{Path} object or C{None} @raises NotebookLookupError: if the notebook could not be resolved or is not given @raises FileNotFoundError: if the notebook location does not exist and could not be mounted. ''' # Explicit page argument has priority over implicit from uri # mounting is attempted by zim.notebook.build_notebook() notebookinfo, page = self.get_notebook_argument( ) # can raise NotebookLookupError if not notebookinfo: raise NotebookLookupError, _('Please specify a notebook') notebook, uripage = build_notebook( notebookinfo) # can raise FileNotFound return notebook, page or uripage
def run(self): if self.opts.get('help'): print usagehelp return nbi = None if len(self.args) > 0: nbi = resolve_notebook(self.args[0]) if nbi is None: print("Notebook must be specified!") return self.nb, ns = build_notebook(nbi) listing = None if self.opts.get('missing-only'): listing = 'M' if self.opts.get('existing-only'): if listing == 'M': print """\ --missing-only and --existing-only are mutually exclusive!""" return listing = 'E' for page in self._all_links(): exists = page.exists() if listing is None or \ (listing == 'M' and exists == 0) or \ (listing == 'E' and exists == 1): print "%c %s" % ('E' if exists == 1 else 'M', page.name)
def _get_notebook(self): uri = self.notebookcombobox.get_notebook() notebook, p = build_notebook(Dir(uri)) return notebook