This repository has been archived by the owner on Mar 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fluidinfoutils.el
78 lines (65 loc) · 3.03 KB
/
fluidinfoutils.el
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
;; fluidinfoutils.el --- Some utility routines based on fluidinfo I found useful
;;
;; Copyright (C) 2009, 2010 Holger Durer
;;
;;
;; This file 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; version 2.
;; This file 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 GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth floor,
;; Boston, MA 02110-1301, USA.
(require 'fluidinfo)
(defun fluidinfo-query-and-fetch (query tags-to-fetch)
"Perform 'query' and fetch all 'tags-to-fetch' for all objects found.
Returns a list of items, each item is a list comprising of
a) the guid of the object, and
b) the list of values for each tag given.
In b) a value will be either nil if the value could not be retrieved
or a list of (value mime-type) for the value"
(flet ((fetch-tag (guid tag)
(let ((res (fluidinfo-get-object-tag-value guid tag "*/*")))
(message "fetch-tag %s %s -> %s %s" guid tag (second res) (third res))
(if (car res)
(list (second res) (fourth res))
nil))))
(let* ((res (fluidinfo-query-objects query))
(ids (and (car res)
(coerce (cdr (assoc 'ids (second res)))
'list))))
(message "Query >>%s<< returns %s: %s (%s)" query (length ids) ids res)
(if (car res)
(progn
(if (null ids)
(message "No results found from query"))
(loop for guid in ids
collecting (cons guid
(loop for tag in tags
collecting (fetch-tag guid tag)))))
(message "Query failed with code %s" (third res))))))
(defun fluidinfo-query-and-fetch-and-insert-result (query tags-to-fetch)
"Query the DB and fetch all 'tags-to-fetch' (a string space separated names).
Inserts all tag values in a row -- one row per result"
(interactive "sQuery:\nsTags to fetch:")
(let ((tags (split-string tags-to-fetch)))
(cond
((string-equal "" query)
(message "No query given"))
((null tags)
(message "No tags to fetch"))
(t
(let ((res (fluidinfo-query-and-fetch query tags-to-fetch)))
(loop for (guid . tag-values) in res
do (progn
(loop for tag-value in tag-values
for first = t then nil
do (progn
(unless first (insert " "))
(when tag-value (insert (format "%s" (first tag-value))))))
(newline))))))))
(provide 'fluidinfoutils)