summaryrefslogtreecommitdiff
path: root/rt-liberation-update.el
diff options
context:
space:
mode:
authorJohnathan Rabkin <yonirabkin@member.fsf.org>2013-12-13 15:14:45 -0500
committerJohnathan Rabkin <yonirabkin@member.fsf.org>2013-12-13 15:14:45 -0500
commit5de9af64f18301ca1943ed1e362255f050424fcd (patch)
treead35d76fe74696d092dba59b1d30f40ce95ab7a8 /rt-liberation-update.el
import for initial Savannah tree
Diffstat (limited to 'rt-liberation-update.el')
-rw-r--r--rt-liberation-update.el106
1 files changed, 106 insertions, 0 deletions
diff --git a/rt-liberation-update.el b/rt-liberation-update.el
new file mode 100644
index 0000000..8c57bf8
--- /dev/null
+++ b/rt-liberation-update.el
@@ -0,0 +1,106 @@
+;;; rt-liberation-update.el --- check updated tickets
+
+;; Copyright (C) 2009 Yoni Rabkin
+;;
+;; Authors: Yoni Rabkin <yonirabkin@member.fsf.org>
+;;
+;; 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 2 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.