From f9220c47fb1344d24cec4d3d6a728d396f80eecc Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sun, 7 Jul 2013 17:09:36 +0000 Subject: [PATCH] Add a -s/--show option, to replace -t/-T etc. I've left -t/-T in place because they were in the last release, but removed the (rather awkward) extra options for the feedlist/feeditem templates. We can now have as many templates as we like! --- NEWS | 17 ++++++++++------- config | 18 +++++++++--------- rawdog.1 | 18 ++++++------------ rawdoglib/rawdog.py | 17 ++++++----------- test-rawdog | 25 ++++++++++--------------- todolist | 1 - 6 files changed, 41 insertions(+), 55 deletions(-) diff --git a/NEWS b/NEWS index 4d7fc53..18b0972 100644 --- a/NEWS +++ b/NEWS @@ -120,8 +120,6 @@ Fix Debian bug 657206: make feedscanner understand relative links Fix Debian bug 650776: make feedscanner not crash if it can't parse the URL it was given as HTML (reported by Jonathan Polley). -Don't append an extra newline to the templates when doing -t/-T. - Make rawdog use feedscanner's preferred order of feeds in addition to its own. @@ -136,13 +134,18 @@ before scanning it for links. Move rawdog's feed quality heuristic into feedscanner. -Provide templates for the feed list and each item in the feed list -(based on patch from Arnout Engelen). +Simplify the options for dealing with templates: there is now a +-s/--show command-line option that takes a template name as an argument +(i.e. you do "rawdog -s item" rather than "rawdog -T"), and the +"template" config file option is now called "pagetemplate". This +simplifies the code, and makes it possible to add more templates without +adding more command-line options. (All the old command-line and +config-file options are still accepted for backwards compatibility.) -Refactor the template-loading/showing code to reduce duplication. +Add templates for the feed list and each item in the feed list +(based on patch from Arnout Engelen). -Rename the "template" option to "pagetemplate", for consistency. -("template" is still accepted for backwards compatibility.) +Don't append an extra newline when showing a template. Rework the locking logic in persister so that it uses a separate lock file. This fixes a (mostly) harmless bug: previously if rawdog A was diff --git a/config b/config index cdf4c72..ec71033 100644 --- a/config +++ b/config @@ -75,8 +75,8 @@ timeformat %H:%M datetimeformat %H:%M, %A, %d %B # The page template file to use, or "default" to use the built-in template -# (which is probably sufficient for most users). Use "rawdog -t" to show the -# template currently in use as a starting-point for customisation. +# (which is probably sufficient for most users). Use "rawdog -s page" to show +# the template currently in use as a starting-point for customisation. # The following strings will be replaced in the output: # __version__ The rawdog version in use # __refresh__ The HTML 4 header @@ -89,9 +89,9 @@ datetimeformat %H:%M, %A, %d %B # replaced by "Adam Sampson" in the output. pagetemplate default -# Similarly, the template used for each item shown. Use "rawdog -T" to -# show the template currently in use as a starting-point for -# customisation. The following strings will be replaced in the output: +# Similarly, the template used for each item shown. Use "rawdog -s item" to +# show the template currently in use as a starting-point for customisation. +# The following strings will be replaced in the output: # __title__ The item title (as an HTML link, if possible) # __title_no_link__ The item title (as text) # __url__ The item's URL, or the empty string if it doesn't @@ -119,14 +119,14 @@ pagetemplate default itemtemplate default # The template used to generate the feed list (__feeds__ above). Use "rawdog -# --show-feedlisttemplate" to show the current template. The following strings -# will be replaced in the output: +# -s feedlist" to show the current template. +# The following strings will be replaced in the output: # __feeditems__ The feed items feedlisttemplate default # The template used to generate each item in the feed list. Use "rawdog -# --show-feeditemtemplate" to show the current template. The following strings -# will be replaced in the output: +# -s feeditem" to show the current template. +# The following strings will be replaced in the output: # __feed_id__ The feed's title with non-alphanumeric characters # (and HTML markup) removed (useful for per-feed # styles); you can use the "id" feed option below to diff --git a/rawdog.1 b/rawdog.1 index 48c46c5..ea87b94 100644 --- a/rawdog.1 +++ b/rawdog.1 @@ -89,13 +89,13 @@ the time of the last update. \fB\-r\fP \fIURL\fP, \fB\-\-remove\fP \fIURL\fP Remove feed \fIURL\fP from the config file. .TP -\fB\-t\fP, \fB\-\-show\-template\fP -Print the page template currently in use to stdout. +\fB\-s\fP \fITEMPLATE\fP, \fB\-\-show\fP \fITEMPLATE\fP +Print one of the templates currently in use to stdout. +\fBTEMPLATE\fP may be \fBpage\fP, \fBitem\fP, \fBfeedlist\fP or +\fBfeeditem\fP. This can be used as a starting point if you want to design your own -template for use with the \fBtemplate\fP option in the config file. -.TP -\fB\-T\fP, \fB\-\-show\-itemtemplate\fP -Print the item template currently in use to stdout. +template for use with the corresponding \fBtemplate\fP option in the +config file. .TP \fB\-u\fP, \fB\-\-update\fP Fetch data from the feeds and store it. @@ -103,12 +103,6 @@ This could take some time if you've got lots of feeds. .TP \fB\-w\fP, \fB\-\-write\fP Write out the HTML output file. -.TP -\fB\-\-show\-feeditemtemplate\fP -Print the feed list item template currently in use to stdout. -.TP -\fB\-\-show\-feedlisttemplate\fP -Print the feed list template currently in use to stdout. .SS Special Actions If one of these options is specified, \fBrawdog\fP will perform only that action, then exit. diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 53d4495..5dc2fd1 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -1744,10 +1744,8 @@ Actions (performed in order given): -f|--update-feed URL Force an update on the single feed URL -l, --list List feeds known at time of last update -r|--remove URL Remove feed URL from the config file --t, --show-template Print the page template currently in use --T, --show-itemtemplate Print the item template currently in use ---show-feeditemtemplate Print the feed list item template currently in use ---show-feedlisttemplate Print the feed list template currently in use +-s|--show TEMPLATE Show the contents of a template + (TEMPLATE may be: page item feedlist feeditem) -u, --update Fetch data from feeds and store it -w, --write Write out HTML output @@ -1768,7 +1766,7 @@ def main(argv): system_encoding = locale.getpreferredencoding() try: - SHORTOPTS = "a:c:d:f:lNr:tTuvV:wW" + SHORTOPTS = "a:c:d:f:lNr:s:tTuvV:wW" LONGOPTS = [ "add=", "config=", @@ -1780,10 +1778,9 @@ def main(argv): "no-lock-wait", "no-locking", "remove=", + "show=", "show-itemtemplate", "show-template", - "show-feeditemtemplate", - "show-feedlisttemplate", "update", "update-feed=", "verbose", @@ -1882,6 +1879,8 @@ def main(argv): remove_feed("config", a, config) config.reload() rawdog.sync_from_config(config) + elif o in ("-s", "--show"): + rawdog.show_template(a, config) elif o in ("-t", "--show-template"): rawdog.show_template("page", config) elif o in ("-T", "--show-itemtemplate"): @@ -1890,10 +1889,6 @@ def main(argv): rawdog.update(config) elif o in ("-w", "--write"): rawdog.write(config) - elif o == "--show-feeditemtemplate": - rawdog.show_template("feeditem", config) - elif o == "--show-feedlisttemplate": - rawdog.show_template("feedlist", config) plugins.call_hook("shutdown", rawdog, config) diff --git a/test-rawdog b/test-rawdog index ed9561d..8791035 100644 --- a/test-rawdog +++ b/test-rawdog @@ -651,18 +651,13 @@ make_rss20 $httpdir/simple.rss add "feed 0 $httpurl/simple.rss" runs -uw cp $statedir/output.html $statedir/output.html.orig -run -t -cp $outfile $statedir/page -run -T -cp $outfile $statedir/item -run --show-feedlisttemplate -cp $outfile $statedir/feedlist -run --show-feeditemtemplate -cp $outfile $statedir/feeditem -add "pagetemplate page" -add "itemtemplate item" -add "feedlisttemplate feedlist" -add "feeditemtemplate feeditem" +for template in page item feedlist feeditem; do + run -s $template + cp $outfile $statedir/$template + run --show $template + same $outfile $statedir/$template + add "${template}template ${template}" +done run -w same $statedir/output.html.orig $statedir/output.html @@ -690,7 +685,7 @@ contains $statedir/output.html MAGIC1 MAGIC2 begin "item dates" # Debian bug 651080. -run -T +run -s item cp $outfile $statedir/item echo "__date__" >>$statedir/item make_atom10 $httpdir/feed.atom @@ -709,10 +704,10 @@ make_rss20 $httpdir/2.rss add "feed 0 $httpurl/0.rss" add "feed 0 $httpurl/1.rss" add "feed 0 $httpurl/2.rss" -run --show-feedlisttemplate +run -s feedlist cp $outfile $statedir/feedlist echo "FEEDLIST" >>$statedir/feedlist -run --show-feeditemtemplate +run -s feeditem cp $outfile $statedir/feeditem echo "FEEDITEM-__feed_url__" >>$statedir/feeditem add "feedlisttemplate feedlist" diff --git a/todolist b/todolist index 37d4694..8e6c4c3 100644 --- a/todolist +++ b/todolist @@ -104,7 +104,6 @@ Add a needs_update() method to Feed; make Rawdog call that on all the feeds (when not being forced) and then call update() on each of them that needs it. For rawdog 3: -- generalise templating (so the show template option takes a name, etc.) - newer Python features - use unicode.encode('ascii','xmlcharrefreplace') if possible? - "for line in file" -- 2.35.1