def get_page_tree(name): def attr_picker(c): return { "title": c["title"], } log.info("Load page tree of space '%s'" % name) url = f"rest/api/space/{name}/content?depth=root" page_tree = get_nested_content(url, attr_picker) return page_tree
def open_gui_browser(url): if not url.startswith(BASE_URL): if url.startswith('/'): url = f"{BASE_URL}{url}" else: url = f"{BASE_URL}/{url}" cmd = config["GuiBrowser"] if '%s' not in cmd: cmd = cmd + " '%s'" cmd = cmd % url log.info("Executing: `%s`" % cmd) process = Popen(split(cmd), stdin=PIPE, stderr=PIPE) process.communicate()
def alert(self, message, msgtype='info'): """Show a message in the status line :message: the alert message as a string :msgtype: one of 'info', 'warning', 'error' """ log.info("Alert (%s): %s" % (msgtype, message)) self.footer.status_line.set_text((msgtype, message)) try: self.loop.draw_screen() except AssertionError: # If we are outside the loop (which happens after catching an # exception) then this would cause another exception and lead to # an exit of the program pass
def open_cli_browser(url, app): """Opens an URL in a CLI browser""" if not url.startswith(BASE_URL): if url.startswith('/'): url = f"{BASE_URL}{url}" else: url = f"{BASE_URL}/{url}" cmd = config["CliBrowser"] if '%s' not in cmd: cmd = cmd + " '%s'" cmd = cmd % url log.info("Executing: `%s`" % cmd) app.loop.screen.stop() process = Popen(split(cmd), stdin=PIPE, stderr=PIPE) process.communicate() app.loop.screen.start()
def get_editor_input(prompt): """Open a tempfile with an external editor :prompt: Text to be written to the file beforehand """ tfile = tempfile.NamedTemporaryFile('w', delete=False) tfile.write(prompt) tfile.flush() cmd = config["Editor"] if '%s' not in cmd: cmd += " '%s'" cmd = cmd % tfile.name log.info("Executing: `%s`" % cmd) process = Popen(split(cmd)) process.communicate() with open(tfile.name, 'r') as f: content = f.read() return content
def get_microblog(self): """Load Microblog entries via HTTP""" log.info("Fetch microblog...") response = make_request( "rest/microblog/1.0/microposts/search", params={ "offset": self.offset, "limit": self.limit, "replyLimit": self.replyLimit, }, method='POST', data=self.post_data, headers={ "Content-Type": "application/json", }, ) entries = response.json() result = [] for e in entries['microposts']: result.append(MicroblogEntry(MicroblogObject(e), is_reply=False)) self.offset += len(result) return result
def update(self, size=None): log.info("Update ...") self.params["start"] = 0 self.entries = self.get_entries() self.redraw()
def load_much_more(self, size=None): log.info("Load much more ...") self.params["limit"] *= 5 self.entries += self.get_entries() self.params["limit"] //= 5 self.redraw()
def load_more(self, size=None): log.info("Load more ...") self.entries += self.get_entries() self.redraw()