Skip to content

Commit f59cbc3

Browse files
committed
Upgrade the score file on initial load.
This commit causes elfeed-score to immediately re-write the score file in the current format version when it is asked to load a score file in an archaic version.
1 parent 71f4a92 commit f59cbc3

File tree

10 files changed

+117
-43
lines changed

10 files changed

+117
-43
lines changed

ChangeLog

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
2021-02-28 Michael Herstine <[email protected]>
1+
2021-03-02 Michael Herstine <[email protected]>
22

3-
Fix issue #12.
4-
Announce the fact when making a backup copy of the score file.
5-
If there is an error on copy, say so & continue (i.e. don't
6-
error out).
3+
Upgrade the score file on initial load.
4+
This commit causes elfeed-score to immediately re-write the
5+
score file in the current format version when it is asked to
6+
load a score file in an archaic version.
77

88
2021-03-01 Michael Herstine <[email protected]>
99

1010
Re-factor 'elfeed-score-scoring.el' to define the logic for title, content, authors & link rules via macro rather than individually.
1111

12-
2021-02-27 Michael Herstine <[email protected]>
12+
2021-03-01 Michael Herstine <[email protected]>
1313

1414
Address issue #11.
1515
This commit introduces a new rule type: link. Link scoring rules
@@ -18,6 +18,13 @@
1818

1919
Additionally, this commit raises the format version to 7.
2020

21+
2021-02-28 Michael Herstine <[email protected]>
22+
23+
Fix issue #12.
24+
Announce the fact when making a backup copy of the score file.
25+
If there is an error on copy, say so & continue (i.e. don't
26+
error out).
27+
2128
2021-02-26 Michael Herstine <[email protected]>
2229

2330
Fixed a few typos in the release workflow.

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
elfeed-score News -- history of user-visible changes -*- outline -*-
22

3+
* Changes in elfeed-score 0.7.7
4+
5+
** New Features
6+
7+
*** When reading an older score file, immediately re-write in the most recent format
38
* Changes in elfeed-score 0.7.6
49

510
No user-visible changes in this build; strictly re-factoring.

README.org

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#+DESCRIPTION: Gnus-style scoring for Elfeed
33
#+AUTHOR: Michael Herstine
44
5-
#+DATE: <2021-03-01 Mon 19:28>
5+
#+DATE: <2021-03-02 Tue 08:24>
66
#+AUTODATE: t
77
#+OPTIONS: toc:nil org-md-headline-style:setext *:t ^:nil
88

@@ -71,7 +71,7 @@ The easiest way to install elfeed-score is [[https://github.com/melpa/melpa][MEL
7171
You can also download the Emacs package file on the GitHub releases [[https://github.com/sp1ff/elfeed-score/releases][page]] or from my personal [[https://www.unwoundstack/distros.html][page]]. Then say:
7272

7373
#+BEGIN_SRC elisp
74-
(package-install-file "elfeed-score-0.7.6.tar")
74+
(package-install-file "elfeed-score-0.7.7.tar")
7575
#+END_SRC
7676

7777
** Autotools Source Distributions
@@ -80,8 +80,8 @@ You can also download Autotools source tarballs (again available either on the G
8080

8181
#+BEGIN_SRC bash
8282
cd /tmp
83-
curl -L --output elfeed-score-0.7.6.tar.gz https://github.com/sp1ff/elfeed-score/releases/download/0.7.6/elfeed-score-0.7.6.tar.gz
84-
tar xvf elfeed-score-0.7.6.tar.gz && cd elfeed-score-0.7.6
83+
curl -L --output elfeed-score-0.7.7.tar.gz https://github.com/sp1ff/elfeed-score/releases/download/0.7.7/elfeed-score-0.7.7.tar.gz
84+
tar xvf elfeed-score-0.7.7.tar.gz && cd elfeed-score-0.7.7
8585
export EMACSLOADPATH=$HOME/.emacs.d/elpa/elfeed-20200209.1942:$EMACSLOADPATH
8686
./configure
8787
make
@@ -96,20 +96,32 @@ The unit tests require some macros defined by the [[https://github.com/skeeto/el
9696
#+BEGIN_SRC bash
9797
cd /tmp
9898
git clone https://github.com/skeeto/elfeed.git
99-
curl -L --output=elfeed-score-0.7.6.tar.gz https://github.com/sp1ff/elfeed-score/releases/download/0.7.6/elfeed-score-0.7.6.tar.gz
100-
tar xvf elfeed-score-0.7.6.tar.gz && cd elfeed-score-0.7.6
101-
export EMACSLOADPATH=/tmp/elfeed-score-0.7.6:/tmp/elfeed:/tmp/elfeed/tests:$EMACSLOADPATH
99+
curl -L --output=elfeed-score-0.7.7.tar.gz https://github.com/sp1ff/elfeed-score/releases/download/0.7.7/elfeed-score-0.7.7.tar.gz
100+
tar xvf elfeed-score-0.7.7.tar.gz && cd elfeed-score-0.7.7
101+
export EMACSLOADPATH=/tmp/elfeed-score-0.7.7:/tmp/elfeed:/tmp/elfeed/tests:$EMACSLOADPATH
102102
./configure
103103
make
104104
make check
105105
sudo make install
106106
#+END_SRC
107107

108-
Again, unless you already use =EMACSLOADPATH=, you'll need to set =EMACSLOADPATH= appropriately to your system, something like =EMACSLOADPATH=/tmp/elfeed-score-0.7.6:/tmp/elfeed:/tmp/elfeed/tests:/usr/share/emacs/25.2/lisp=.
108+
Again, unless you already use =EMACSLOADPATH=, you'll need to set =EMACSLOADPATH= appropriately to your system, something like =EMACSLOADPATH=/tmp/elfeed-score-0.7.7:/tmp/elfeed:/tmp/elfeed/tests:/usr/share/emacs/25.2/lisp=.
109109

110110
** Building From Source
111111

112112
Finally, you can of course just clone this repo & build there. I've started a [[https://github.com/sp1ff/elfeed-score/wiki][wiki]], whose intended audience are people looking to hack on elfeed-score, that includes build instructions.
113+
* Upgrading Your Score File
114+
115+
The format of the score file is updated fairly regularly to accomodate new features, new rule types, and so forth. elfeed-score maintains backward compatibility in that score files in older format versions are still recognized. The most recent format version will always be used when the score file is written to disk, however. Note than an older elfeed-score will reject a more recent score file (since it will not know how to parse it).
116+
117+
When elfeed-score loads a score file that uses an archaic format (i.e. a format verseion less than =elfeed-scor-serde-current-format=) it will:
118+
119+
- announce the fact that your score file will be updated
120+
- make a backup of your current score file in a file by the same name with a suffix of =~%d~= appended, where "%d" is the current format version
121+
- on successful parse, immediately re-write the score file in the most recent version
122+
123+
This should all be transparent to the user.
124+
113125
* Status and Roadmap
114126

115127
I've been using [[https://github.com/sp1ff/elfeed-score][elfeed-score]] day in & day out for my RSS reading for over a year now. I wrote a post on how [[https://github.com/sp1ff/elfeed-score][elfeed-score]] works, along with the process of submitting code to MELPA, [[https://www.unwoundstack.com/blog/scoring-elfeed-entries.html][here]]. [[https://github.com/C-J-Cundy][Chris]] wrote a post on how he uses it to [[https://cundy.me/post/elfeed/][manage ArXiv RSS Feeds]].

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([elfeed-score], [0.7.6], [[email protected]], [elfeed-score], [https://github.com/sp1ff/elfeed-score])
1+
AC_INIT([elfeed-score], [0.7.7], [[email protected]], [elfeed-score], [https://github.com/sp1ff/elfeed-score])
22
AC_CONFIG_AUX_DIR([build-aux])
33
AC_CONFIG_SRCDIR([./elfeed-score.el])
44

doc/elfeed-score.texi

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,21 @@ recent score file.
325325

326326
@cindex score file version
327327

328-
When elfeed-score loads a score file that uses an archaic
329-
version (i.e. a version less than
330-
@code{elfeed-score-serde-current-format}) it will announce the fact
331-
that your score file will be updated and make a backup of your current
332-
score file in @code{%s.~%d~} where @code{%s} is replaced by
333-
@code{elfeed-score-serde-score-file} and @code{%d} is replaced by your
334-
score file's current version (so that you will end up with a copy of
335-
the last score file in each format over time).
328+
When elfeed-score loads a score file that uses an archaic version
329+
(i.e. a version less than @code{elfeed-score-serde-current-format}) it
330+
will announce the fact that your score file will be updated and make a
331+
backup of your current score file in @code{%s.~%d~} where @code{%s} is
332+
replaced by @code{elfeed-score-serde-score-file} and @code{%d} is
333+
replaced by your score file's current version (so that you will end up
334+
with a copy of the last score file in each format over time).
336335

337336
@defvar elfeed-score-serde-current-format
338337
The version of the score file format employed by elfeed-score.
339338
@end defvar
340339

340+
It will also immediately re-write the score file in the current
341+
format.
342+
341343
@item
342344
``title''
343345
The sublist named by the string ``title'' contains rules that

doc/version.texi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@set UPDATED 2 March 2021
22
@set UPDATED-MONTH March 2021
3-
@set EDITION 0.7.6
4-
@set VERSION 0.7.6
3+
@set EDITION 0.7.7
4+
@set VERSION 0.7.7

elfeed-score-pkg.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(define-package
22
"elfeed-score"
3-
"0.7.6"
3+
"0.7.7"
44
"Gnus-style scoring for Elfeed"
55
'((emacs "26.1") (elfeed "3.3.0")))

elfeed-score-serde.el

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ into a property list with the following properties:
757757
- :adjust-tags
758758
- :title-or-content
759759
- :tags
760-
- :links"
760+
- :links
761+
- :version"
761762

762763
(let* ((sexp
763764
(car
@@ -769,15 +770,15 @@ into a property list with the following properties:
769770
(unless (eq version elfeed-score-serde-current-format)
770771
(let ((backup-name (format "%s.~%d~" score-file version)))
771772
(message "elfeed-score will upgrade your score file to version %d; \
772-
a backup file will be in %s."
773+
a backup file will be left in %s."
773774
elfeed-score-serde-current-format backup-name)
774775
(condition-case
775776
data
776777
(copy-file score-file backup-name)
777778
(error
778-
(message "Tried to backup your score file to %s: %s."
779+
(message "Tried to backup your score file to %s but failed: %s."
779780
backup-name (cadr data))))))
780-
(elfeed-score-serde--parse-scoring-sexp sexp)))
781+
(plist-put (elfeed-score-serde--parse-scoring-sexp sexp) :version version)))
781782

782783
(define-obsolete-function-alias 'elfeed-score/write-score-file
783784
#'elfeed-score-serde-write-score-file "0.2.0" "Move to standard-compliant naming.")
@@ -859,7 +860,11 @@ Read SCORE-FILE, store scoring rules into
859860
elfeed-score-serde-tag-rules (plist-get score-entries :tag)
860861
elfeed-score-serde-authors-rules (plist-get score-entries :authors)
861862
elfeed-score-serde-score-mark (plist-get score-entries :mark)
862-
elfeed-score-serde-adjust-tags-rules (plist-get score-entries :adjust-tags))))
863+
elfeed-score-serde-adjust-tags-rules (plist-get score-entries :adjust-tags))
864+
;; If this is an upgrade in file format; re-write the score file in the new
865+
;; format right away (https://github.com/sp1ff/elfeed-score/issues/12)
866+
(unless (eq elfeed-score-serde-current-format (plist-get score-entries :version))
867+
(elfeed-score-serde-write-score-file score-file))))
863868

864869
(provide 'elfeed-score-serde)
865870
;;; elfeed-score-serde.el ends here

elfeed-score.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Copyright (C) 2019-2021 Michael Herstine <[email protected]>
44

55
;; Author: Michael Herstine <[email protected]>
6-
;; Version: 0.7.6
6+
;; Version: 0.7.7
77
;; Package-Requires: ((emacs "26.1") (elfeed "3.3.0"))
88
;; Keywords: news
99
;; URL: https://github.com/sp1ff/elfeed-score
@@ -43,7 +43,7 @@
4343
(require 'elfeed-score-scoring)
4444
(require 'elfeed-score-maint)
4545

46-
(defconst elfeed-score-version "0.7.6")
46+
(defconst elfeed-score-version "0.7.7")
4747

4848
(defgroup elfeed-score nil
4949
"Gnus-style scoring for Elfeed entries."

test/test-serde.el

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Test reading a trival score file (format version 1)."
5858
(elfeed-score-title-rule--create
5959
:text "long way( home)?" :value 100
6060
:type 'r))
61-
:content nil)))))
61+
:content nil :version 1)))))
6262

6363
(ert-deftest test-score-files-1 ()
6464
"Smoke test reading/writing score files.
@@ -91,7 +91,7 @@ Test reading a trival score file (format version 2)."
9191
:text "long way( home)?" :value 100
9292
:type 'r))
9393
:content nil
94-
:title-or-content nil)))))
94+
:title-or-content nil :version 2)))))
9595

9696
(ert-deftest test-score-files-2 ()
9797
"Smoke test reading/writing score files.
@@ -135,7 +135,8 @@ tag-scoping rules)."
135135
:title-or-content
136136
(list (elfeed-score-title-or-content-rule--create
137137
:text "now is the time..." :title-value 150
138-
:content-value 100 :type 's :tags '(t . (foo bar)))))))))
138+
:content-value 100 :type 's :tags '(t . (foo bar))))
139+
:version 2)))))
139140

140141
(ert-deftest test-score-files-3 ()
141142
"Smoke test reading/writing score files.
@@ -171,7 +172,8 @@ Format version defaulted; tag-scoping rules."
171172
:title-or-content nil
172173
:authors nil
173174
:tag nil
174-
:link nil)))))
175+
:link nil
176+
:version elfeed-score-serde-current-format)))))
175177

176178
(ert-deftest test-score-files-4 ()
177179
"Smoke test reading/writing score files.
@@ -225,7 +227,8 @@ Format version defaulted, includes adjust-tags rules."
225227
(elfeed-score-tag-rule--create
226228
:tags '(nil . z)
227229
:value -1))
228-
:link nil)))))
230+
:link nil
231+
:version elfeed-score-serde-current-format)))))
229232

230233
(ert-deftest test-score-files-5 ()
231234
"Smoke test reading/writing score files.
@@ -282,7 +285,8 @@ Format version 4."
282285
:value 10)
283286
(elfeed-score-tag-rule--create
284287
:tags '(nil . z)
285-
:value -1)))))))
288+
:value -1))
289+
:version 4)))))
286290

287291
(ert-deftest test-score-files-6 ()
288292
"Smoke test reading/writing score files.
@@ -344,7 +348,8 @@ Format version 6; tag- and feed-scorping rules; authors rule."
344348
:value 10)
345349
(elfeed-score-tag-rule--create
346350
:tags '(nil . z)
347-
:value -1)))))))
351+
:value -1))
352+
:version 5)))))
348353

349354
(ert-deftest test-issue-7 ()
350355
"Check that the error in issue #7 is caught."
@@ -372,7 +377,7 @@ Format version 6; tag- and feed-scorping rules; authors rule."
372377
(elfeed-score-title-rule--create
373378
:text "hoping" :value -1000 :type 's))
374379
:content nil :title-or-content nil
375-
:authors nil :tag nil)))))
380+
:authors nil :tag nil :version 6)))))
376381

377382
(ert-deftest test-format-version-7 ()
378383
"Smoke tests for format version 7."
@@ -396,7 +401,8 @@ Format version 6; tag- and feed-scorping rules; authors rule."
396401
:link
397402
(list
398403
(elfeed-score-link-rule--create
399-
:text "foo" :value 100 :type 'r)))))))
404+
:text "foo" :value 100 :type 'r))
405+
:version 7)))))
400406

401407
(ert-deftest test-writes-latest-version ()
402408
"Be sure that the score file is written in the lastest format version."
@@ -434,14 +440,51 @@ Format version 6; tag- and feed-scorping rules; authors rule."
434440
(mark -2500)))
435441
(score-text (pp-to-string score-entries))
436442
(score-file (make-temp-file "elfeed-score-test-" nil nil score-text))
437-
;; Pre-create the backup-file
438443
(backup-name (format "%s.~5~" score-file)))
444+
;; Pre-create the backup-file
439445
(with-temp-buffer
440446
(insert score-text)
441447
(write-file backup-name nil))
442448
;; This will attempt to make a backup, but stumble across the one
443449
;; we just made; should *not* error out
444450
(elfeed-score-serde--parse-score-file score-file)))
445451

452+
(ert-deftest test-issue-12-a ()
453+
"Test a secondary aspect to my fix to issue #12.
454+
455+
When elfeed-score reads a score file in an archaic format, it
456+
should immediately re-write the file in the new format (as well
457+
as make a backup copy of the file in the old format--
458+
cf. `test-issue-12'."
459+
(let* ((score-entries
460+
'((version 5)
461+
("title"
462+
("hoping" -1000 s nil (t . (foo bar)) 0 (t . ((t . "foo"))))
463+
("long way( home)?" +100 r))
464+
("feed"
465+
("foo.com" +100 s u nil nil 0)
466+
("title" -100 s t))
467+
("authors"
468+
("esr" +100 s nil nil 100 (t . ((t . "foo")
469+
(u . "http://bar.com/feed")))))
470+
("tag"
471+
((t . (a b c)) +10)
472+
((nil . z) -1))
473+
("adjust-tags"
474+
((t . 100) (t . important))
475+
((nil . -100) (nil . important)))
476+
(mark -2500)))
477+
(score-text (pp-to-string score-entries))
478+
(score-file (make-temp-file "elfeed-score-test-" nil nil score-text))
479+
(backup-name (format "%s.~5~" score-file)))
480+
(elfeed-score-serde-load-score-file score-file)
481+
;; This should leave us with:
482+
;; 1. a copy of the score file in `backup-name'
483+
(should (file-exists-p backup-name))
484+
;; 2. `score-file' updated to `elfeed-score-serde-current-format'
485+
(should
486+
(eq elfeed-score-serde-current-format
487+
(plist-get (elfeed-score-serde--parse-score-file score-file) :version)))))
488+
446489
(provide 'test-serde)
447490
;;; test-serde.el ends here

0 commit comments

Comments
 (0)