def _parse_args(self, prepared_args): """ Handles the special command-line arguments available for this screen. Although this is a base screen, having these options prepared here can save coding for screens that will not change the default options. See `_usage_options_example` method for documentation on each of the options being parsed here. Additionally, this is dependent on the values exposed in `cli_opts`, passed to this class during its instantiation. Only values properly configured there will be accepted here. """ for o, a in prepared_args[0]: # optlist, args if o in ("-h", "--help"): self.usage() self.screen_exit() elif o in ("-r", "--raw"): self.clean_html = False elif o in ("-f", "--format"): #remove escaping self.print_format = common.unescape_string(a) elif o in ("-u", "--url"): try: # try to fix the url formatting self.url = self.fix_uri(a) except Exception, e: raise exception.InvalidOptionException("url", e.message) else: # this should never happen! raise Exception(_("Unhandled option. See --help for details."))
def _parse_args(self, prepared_args): """ Handles the special command-line arguments available for this screen. Although this is a base screen, having these options prepared here can save coding for screens that will not change the default options. See `_usage_options_example` method for documentation on each of the options being parsed here. Additionally, this is dependent on the values exposed in `cli_opts`, passed to this class during its instantiation. Only values properly configured there will be accepted here. """ for o, a in prepared_args[0]: # optlist, args if o in ("-h", "--help"): self.usage() self.screen_exit() elif o in ("-r", "--raw"): self.clean_html = False elif o in ("-f", "--format"): # remove escaping self.print_format = common.unescape_string(a) elif o in ("-u", "--url"): try: # try to fix the url formatting self.url = self.fix_uri(a) except Exception, e: raise exception.InvalidOptionException("url", e.message) else: # this should never happen! raise Exception(_("Unhandled option. See --help for details."))
def _run_cycle(self): """ Executes a cycle of this screen. The actions taken here, for each cycle, are as follows: * retrieve data from `url` * parses the data into a XML dom document object * parses the document object into a list of dictionaries * print using `typing_print` """ self.doc_xml_string(self.fetch(self.url)) self.parse_data() self.clear_screen() for item in self.data: new_text = item try: new_text = common.unescape_string(self.print_format % new_text) # remove HTML tags is applicable if self.clean_html: new_text = common.strip_html(new_text) except: raise exception.InvalidOptionException( "format", _("There was an error while using your format.")) if self.center_vertically or self.center_horizontally: self.get_terminal_size() if self.center_vertically: new_text = self.center_text_vertically(new_text) if self.center_horizontally: new_text = self.center_text_horizontally(new_text) self.typing_print(new_text) time.sleep(self.sleep_between_items) if self.cleanup_per_item: self.clear_screen()
def _run_cycle(self): """ Executes a cycle of this screen. The actions taken here, for each cycle, are as follows: * retrieve data from `url` * parses the data into a XML dom document object * parses the document object into a list of dictionaries * print using `typing_print` """ self.doc_xml_string(self.fetch(self.url)) self.parse_data() self.clear_screen() for item in self.data: new_text = item try: new_text = common.unescape_string(self.print_format % new_text) # remove HTML tags is applicable if self.clean_html: new_text = common.strip_html(new_text) except: raise exception.InvalidOptionException("format", _("There was an error while using your format.")) if self.center_vertically or self.center_horizontally: self.get_terminal_size() if self.center_vertically: new_text = self.center_text_vertically(new_text) if self.center_horizontally: new_text = self.center_text_horizontally(new_text) self.typing_print(new_text) time.sleep(self.sleep_between_items) if self.cleanup_per_item: self.clear_screen()