1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
;;; rt-liberation-update.el --- check updated tickets -*- lexical-binding: t; -*-
;; Copyright (C) 2009 Free Software Foundation, Inc.
;;
;; Authors: Yoni Rabkin <yrk@gnu.org>
;;
;; This file is a part of rt-liberation.
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public
;; License along with this program; if not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
;;; Installation:
;;
;; For installation instructions and detailed help please see the
;; wonderful rt-liberation manual located in the "doc/" directory of
;; the rt-liberation distribution.
;;; Usage:
;;
(require 'rt-liberation)
(defgroup rt-liber-update nil
"*Check updates for rt-liberation."
:prefix "rt-liber-update-"
:group 'rt-liber-update)
(defcustom rt-liber-update-file
(concat (file-name-as-directory rt-liber-directory) "update")
"*File to store update information."
:type 'string
:group 'rt-liber-update)
(defcustom rt-liber-update-default-queue nil
"*Default queue to run queries against."
:type 'string
:group 'rt-liber-update)
(defun rt-liber-update-timestamp ()
"Write the current time to disk as a time-stamp."
(rt-liber-update-write (format "%s" (current-time))))
(defun rt-liber-update-write (str)
"Write STR to disk under the rt-liber directory."
(when (and (stringp rt-liber-directory)
(not (file-exists-p rt-liber-directory)))
(make-directory rt-liber-directory))
(when (stringp rt-liber-update-file)
(with-temp-buffer
(insert str)
(insert "\n")
(write-file rt-liber-update-file))))
(defun rt-liber-update-read ()
"Return the time-stamp read from disk or the current time."
(when (file-exists-p rt-liber-update-file)
(let ((timestamp (current-time)))
(with-temp-buffer
(insert-file-contents rt-liber-update-file)
(setq timestamp (read (current-buffer))))
timestamp)))
(defun rt-liber-update-run-query (query-queue timestamp)
"Run query on QUERY-QUEUE since TIMESTAMP."
(rt-liber-browse-query
(rt-liber-compile-query
(and (queue query-queue)
(lastupdated nil
(format-time-string "%Y-%m-%d"
timestamp))))))
(defun rt-liber-update (&optional no-update)
"Show tickets last updated since `rt-liber-update' last run.
With the NO-UPDATE prefix, don't update the time-stamp on disk.
If no time-stamp is found, for instance when you run this for the
first time, today's date is used and then recorded as the
time-stamp."
(interactive "P")
(when (not rt-liber-update-default-queue)
(error "`rt-liber-update-default-queue' is nil"))
(let ((timestamp (rt-liber-update-read)))
(rt-liber-update-run-query rt-liber-update-default-queue
timestamp)
(when (not no-update)
(rt-liber-update-timestamp))
(message "showing tickets updated after: %s (time-stamp %s)"
(format-time-string "%Y-%m-%d" timestamp)
(if no-update
"not updated"
"updated"))))
(provide 'rt-liberation-update)
;;; rt-liberation-update.el ends here.
|