Re: exporting records
On Mon Oct 3 2011 Eric Abrahamsen wrote: > Okay, it sounds like this is different enough to warrant me waiting on > it. In the meantime, if you have any clever ideas about the string > format/templating side of things, don't be shy! ...maybe not a bad idea. Indeed, my patch has grown more than I had expected. I want to test it a bit more before checking it in. Roland -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Sun, Oct 02 2011, Roland Winkler wrote: > On Sun Oct 2 2011 Eric Abrahamsen wrote: >> Can you drop any hints about how it will change? Extra arguments? > > I didn't want to do anything fancy. Yet if the field argument > doesn't match anything what it is supposed to match now, the new > code also tries to match the keys of individual note fields. So if > the value of field is 'note, it returns a list of all note fields. > If the value is 'notes, it returns the value of the 'notes field. Okay, it sounds like this is different enough to warrant me waiting on it. In the meantime, if you have any clever ideas about the string format/templating side of things, don't be shy! -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Sun Oct 2 2011 Roland Winkler wrote: > So if the value of field is 'note, it returns a list of all note > fields. If the value is 'notes, it returns the value of the 'notes > field. Of course this is confusing - it should be the other way round: `notes' should represent all note fields, and `note' should be an individual one. But this fails because there is also a notes field `notes'. This is a historical inconsistency that cannot be changed unless one wants to rename everybody's BBDB records. Roland -- All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Sun Oct 2 2011 Eric Abrahamsen wrote: > Can you drop any hints about how it will change? Extra arguments? I didn't want to do anything fancy. Yet if the field argument doesn't match anything what it is supposed to match now, the new code also tries to match the keys of individual note fields. So if the value of field is 'note, it returns a list of all note fields. If the value is 'notes, it returns the value of the 'notes field. Other ideas are welcome. I just realized one thing: This function used to throw an error if the field arg had an `illegal' value. That made sense for the old scheme where the allowed values were well-defined for every record (though possibly the value was nil). With the new scheme it's probably better to simply return nil if field does not exist. > Just to confirm: address and phone fields can have multiple > identical string keys, but note-type fields can't, is that right? Yes. All this is partly historical, partly it is motivated by efficiency / transparency. All in all, BBDB uses individual note fields in more ways than individual address and phone fields. So it helps if the note fields can be accessed efficiently and if there is no need to worry about mutliple fields with the same key. BBDB doesn't do similar things with individual addresses or phone numbers. Yet for the few things that BBDB can do with addresses and phone numbers, it turned out to be less a problem to allow keys to occur multiple times. (Address and phone "keys" like "home" or "work" are really not used at all like keys. That's why this works.) Roland -- All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Sun, Oct 02 2011, Roland Winkler wrote: > On Fri Sep 30 2011 Eric Abrahamsen wrote: >> 1. If there's no value for a field, you get a nice ugly "nil". Ideally >>we'd have conditional insertion of strings depending on whether or >>not there's a value for a given field, but that means we can't use >>`format' anymore, and suddenly this whole thing gets a *lot* more >>complicated than a Friday afternoon project. > > This reminds me of BBDB address via bbdb-address-format-list. > One needs to keep track of everything... > >> 2. There's no obvious way of indicating which value of a multi-valued >>field you want. `bbdb-record-get-field' only gets us so far, as it's >>indiscriminate about fields with string values, list values and >>struct values. > > Currently I am trying to make bbdb-record-get-field a bit more > flexible as this had also popped up here in some other context. I > want to install my patch in the near future. Yet this might not > solve all your problems. (See my comments on string labels below.) Can you drop any hints about how it will change? Extra arguments? >>With a little work it would be possible to access subvalues by >>constructing complex field names: for instance, address-home >>(to get the address field labelled "home") > > Note that "home" may appear multiple times (i.e., the string labels > used for addresses and phone numbers) > >>I've seen people mess with symbol names like this before, and >>could probably figure it out. > > The keys of note fields (which are symbols) are intended to be > unique for each record. Just to confirm: address and phone fields can have multiple identical string keys, but note-type fields can't, is that right? I'm not sure an exporter needs options that fine-grained. I'm inclined to produce either the first field with a given key, or else all the fields with a given key. Anyway, if bbdb-record-get-field is under construction, I'll put some thought into conditional strings first. E -- All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Fri Sep 30 2011 Eric Abrahamsen wrote: > 1. If there's no value for a field, you get a nice ugly "nil". Ideally >we'd have conditional insertion of strings depending on whether or >not there's a value for a given field, but that means we can't use >`format' anymore, and suddenly this whole thing gets a *lot* more >complicated than a Friday afternoon project. This reminds me of BBDB address via bbdb-address-format-list. One needs to keep track of everything... > 2. There's no obvious way of indicating which value of a multi-valued >field you want. `bbdb-record-get-field' only gets us so far, as it's >indiscriminate about fields with string values, list values and >struct values. Currently I am trying to make bbdb-record-get-field a bit more flexible as this had also popped up here in some other context. I want to install my patch in the near future. Yet this might not solve all your problems. (See my comments on string labels below.) >With a little work it would be possible to access subvalues by >constructing complex field names: for instance, address-home >(to get the address field labelled "home") Note that "home" may appear multiple times (i.e., the string labels used for addresses and phone numbers) >I've seen people mess with symbol names like this before, and >could probably figure it out. The keys of note fields (which are symbols) are intended to be unique for each record. Roland -- All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Mon, Sep 26 2011, Roland Winkler wrote: > On Mon Sep 26 2011 Eric Abrahamsen wrote: >> While we're on the subject of features that won't be considered until >> version 3 is finished, if ever >> >> I've been writing a small function to export BBDB records according to >> an arbitrary text template. I'm running up against the problem that >> there seems to be no generic "get the value of this field for this >> record" function. Ie, something like (bbdb-field-value 'mail record) --> >> "exam...@mail.com". > > How about bbdb-record-get-field? I just noticed that at the end, > before throwing an error this function could also try to resolve > individual note fields (same for bbdb-record-set-field). > >> Also, does this seem like a good idea in general? I know that we're in >> some kind of feature freeze, but this would also be relatively distinct >> from the rest of the codebase, and if it's an attractive idea I'd be >> happy to chew on it in my spare time. Some generic templates could be >> included for common needs > > Sounds useful to me. Okay, I've got this working. It's very bare bones, but works well enough that the design flaws are becoming apparent. As I conceived of/implemented this, it's basically a format string, with the format string's typical placeholders. Two problems with this are already obvious: 1. If there's no value for a field, you get a nice ugly "nil". Ideally we'd have conditional insertion of strings depending on whether or not there's a value for a given field, but that means we can't use `format' anymore, and suddenly this whole thing gets a *lot* more complicated than a Friday afternoon project. 2. There's no obvious way of indicating which value of a multi-valued field you want. `bbdb-record-get-field' only gets us so far, as it's indiscriminate about fields with string values, list values and struct values. With a little work it would be possible to access subvalues by constructing complex field names: for instance, address-home (to get the address field labelled "home") or mail-3 (to get the third element of the mail list, assuming there is one) or phone-all (to get some reasonably-formatted list of all the phone values). I've seen people mess with symbol names like this before, and could probably figure it out. Issue number one seems way harder to solve, largely because I have no good ideas for solving it. Issue could be solved the way I mentioned, or else some other way. I've attached the patch, including a new file. The whole thing is early-stage enough that I'd be perfectly happy reworking any aspect of it, or tossing it out altogether. Eric diff --git a/lisp/bbdb-export.el b/lisp/bbdb-export.el new file mode 100644 index 000..ca717aa --- /dev/null +++ b/lisp/bbdb-export.el @@ -0,0 +1,72 @@ +;;; Commentary + +;; This is meant to be a generic text-based exporter for the BBDB. +;; Per-record templates are recorded `bbdb-export-templates', and +;; exporting is performed by selecting a number of records to export, +;; then selecting the appropriate template. A temporary buffer is +;; created, containing first the value of `bbdb-export-preamble', then +;; the export template filled once per record and separated by +;; `bbdb-export-separator', and lastly followed by +;; `bbdb-export-postamble'. + +;; Add new templates like this: + +;; (bbdb-export-register-template FORMAT_STRING VAL_LIST PREAMBLE POSTAMBLE SEPARATOR) +;; where PREAMBLE POSTAMBLE and SEPARATOR are optional strings, with defaults. + +(require 'bbdb) +(require 'bbdb-com) + +(setq bbdb-export-templates nil) +(defconst bbdb-export-default-preamble "") +(defconst bbdb-export-default-postamble "") +(defconst bbdb-export-default-separator "\n\n") + +;;;###autoload +(defun bbdb-export (records) + "Export RECORDS according to a chosen template." + (interactive (list (bbdb-do-records))) + (setq records (bbdb-record-list records)) + (let* ((buf (get-buffer-create "*BBDB Export*")) + (templ (rest (assoc (completing-read "Template name: " bbdb-export-templates) + bbdb-export-templates))) + (pre (or (nth 2 templ) + bbdb-export-default-preamble)) + (post (or (nth 3 templ) + bbdb-export-default-postamble)) + (sep (or (nth 4 templ) + bbdb-export-default-separator)) + (fields (nth 1 templ)) + (strg (first templ)) + (count 0)) +(set-buffer buf) +(erase-buffer) +(fundamental-mode) +(insert pre) +(insert + (mapconcat + (lambda (i) + (apply 'format strg (mapcar + (lambda (f) + (let ((val (cond ((eq f 'bbdb-export-counter) + (progn + (setq count (1+ count)) + count)) + ;; Something with callable sexps here + (t + (bbdb-record-get-field i f) + (when (consp val) ; totally fudging multi-value fields here + (setq val (first val))) + val)) + fields))) + records sep)) +(insert post) +(switch-to-buffer buf))) + +(defmacro bbdb-export-register-tem
Re: exporting records
On Mon Sep 26 2011 Leo wrote: > (nickname () "jvm") > (phone ((type "home")) "01223 399255") > (phone ((type "cell")) "07899 825396") > > (timestamp ((value list)) (20096 21292 563816)) > (timestamp ((value string)) "Mon Sep 26 18:26:13 2011") > > (photo ((value binary)) "%\211Do^\DXlY\2005^H") Somehow I am still missing the point. What benefit do you expect here over the format of the original BBDB record structure? Roland -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On 2011-09-26 17:50 +0800, Roland Winkler wrote: > On Mon Sep 26 2011 Leo wrote: >> It might be desirable to export a record to a canonical sexp then we can >> further write the sexp to any other formats such as vcards, xmls etc. >> For example, the sexp can be a list of elements of the form: >> >> (field parameters value) > > Maybe you can explain in a bit more detail what you have in mind > here. What would be parameters? How about multiple fields of the > same type (snail mail addresses and phone numbers)? How to deal with > values that are lists (organizations, email addresses, AKAs)? I haven't thought this through. But something like: (nickname () "jvm") (phone ((type "home")) "01223 399255") (phone ((type "cell")) "07899 825396") (timestamp ((value list)) (20096 21292 563816)) (timestamp ((value string)) "Mon Sep 26 18:26:13 2011") (photo ((value binary)) "%\211Do^\DXlY\2005^H") Leo -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Mon Sep 26 2011 Leo wrote: > It might be desirable to export a record to a canonical sexp then we can > further write the sexp to any other formats such as vcards, xmls etc. > For example, the sexp can be a list of elements of the form: > > (field parameters value) Maybe you can explain in a bit more detail what you have in mind here. What would be parameters? How about multiple fields of the same type (snail mail addresses and phone numbers)? How to deal with values that are lists (organizations, email addresses, AKAs)? On Mon Sep 26 2011 Eric Abrahamsen wrote: > (I like the idea of a canonical lisp representation of a record, > though I suppose the current struct format is pretty close to > that? Haven't looked at it in detail ) Same question here. -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Mon, Sep 26 2011, Roland Winkler wrote: > On Mon Sep 26 2011 Eric Abrahamsen wrote: >> While we're on the subject of features that won't be considered until >> version 3 is finished, if ever >> >> I've been writing a small function to export BBDB records according to >> an arbitrary text template. I'm running up against the problem that >> there seems to be no generic "get the value of this field for this >> record" function. Ie, something like (bbdb-field-value 'mail record) --> >> "exam...@mail.com". > > How about bbdb-record-get-field? I just noticed that at the end, > before throwing an error this function could also try to resolve > individual note fields (same for bbdb-record-set-field). Erm, yes, that's just what I meant, thank you. Don't know how I missed that… If this happens, it absolutely seems like an export to vcard should be the first order of business. Does anyone here know where the vcard export effort is right now? Would my little scenario outlined above fit in with that? (I like the idea of a canonical lisp representation of a record, though I suppose the current struct format is pretty close to that? Haven't looked at it in detail…) Eric -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
It might be desirable to export a record to a canonical sexp then we can further write the sexp to any other formats such as vcards, xmls etc. For example, the sexp can be a list of elements of the form: (field parameters value) Leo -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Mon Sep 26 2011 Roland Winkler wrote: > > Also, does this seem like a good idea in general? I know that we're in > > some kind of feature freeze, but this would also be relatively distinct > > from the rest of the codebase, and if it's an attractive idea I'd be > > happy to chew on it in my spare time. Some generic templates could be > > included for common needs > > Sounds useful to me. I should add here that previously on this list some people have been thinking about adding some kind of support for exporting records in the vcard format. I do not know much about the vcard format nor do I know details about your plans. Yet I want to suggest that code duplication should be avoided. If ultimately your scheme could also include a template for the vcard format, that would be cool. Roland -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
Re: exporting records
On Mon Sep 26 2011 Eric Abrahamsen wrote: > While we're on the subject of features that won't be considered until > version 3 is finished, if ever > > I've been writing a small function to export BBDB records according to > an arbitrary text template. I'm running up against the problem that > there seems to be no generic "get the value of this field for this > record" function. Ie, something like (bbdb-field-value 'mail record) --> > "exam...@mail.com". How about bbdb-record-get-field? I just noticed that at the end, before throwing an error this function could also try to resolve individual note fields (same for bbdb-record-set-field). > Also, does this seem like a good idea in general? I know that we're in > some kind of feature freeze, but this would also be relatively distinct > from the rest of the codebase, and if it's an attractive idea I'd be > happy to chew on it in my spare time. Some generic templates could be > included for common needs Sounds useful to me. Roland -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/
exporting records
While we're on the subject of features that won't be considered until version 3 is finished, if ever… I've been writing a small function to export BBDB records according to an arbitrary text template. I'm running up against the problem that there seems to be no generic "get the value of this field for this record" function. Ie, something like (bbdb-field-value 'mail record) --> "exam...@mail.com". To explain what I'm thinking, here's a totally fictional macro call I'd like to make: (bbdb-export-register-template "my-template-name" "Record number %d: %s\n \tEmail: %s\n \tNotes: %s" bbdb-export-counter (upcase full-name) mail notes) Anyway, you get the idea. Then you get the records you want in the *BBDB* buffer, hit "bbdb-export", pick a registered export template, and a temp buffer pops up with your text export. `bbdb-export-preamble', `bbdb-export-postamble' and 'bbdb-export-record-separator' all do their thing. So you can see this would be much easier with a generic `bbdb-field-value' function. What are the chances of that? Also, does this seem like a good idea in general? I know that we're in some kind of feature freeze, but this would also be relatively distinct from the rest of the codebase, and if it's an attractive idea I'd be happy to chew on it in my spare time. Some generic templates could be included for common needs… Eric -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/