Add Gramps-and-calendar post.
authorW. Trevor King <wking@drexel.edu>
Thu, 8 Dec 2011 12:29:27 +0000 (07:29 -0500)
committerW. Trevor King <wking@drexel.edu>
Thu, 8 Dec 2011 12:31:54 +0000 (07:31 -0500)
posts/Gramps_and_calendar.mdwn [new file with mode: 0644]
posts/Gramps_and_calendar/CalendarDates.gpr.py [new file with mode: 0644]
posts/Gramps_and_calendar/CalendarDates.patch [new file with mode: 0644]

diff --git a/posts/Gramps_and_calendar.mdwn b/posts/Gramps_and_calendar.mdwn
new file mode 100644 (file)
index 0000000..2c0b0dc
--- /dev/null
@@ -0,0 +1,29 @@
+I use [calendar][] to display birthdays and things that I should
+remember a few days before they hit the fan.  However, `calendar`
+doesn't know all of my relative's birthdays out of the box.  I use
+[Gramps][] to track my family's genealogy, so all the birthday data is
+in the Gramps database.  This is how we get that information out in a
+format that calendar can read:
+
+    $ python src/gramps.py -O wtk -a report -p name=calendar_dates,of="${HOME}/.calendar/birthday"
+    $ grep --color=always -e 'Important Name' -e ^ ~/.calendar/birthday.txt > ~/.calendar/birthday.color
+
+The `-e ^` ensures that every line in `birthday.txt` is copied to
+`birthday.color`, and `-e 'Important Name'` uses ANSI escape sequences
+to highlight the name of someone particularly close to you.
+
+The `CalendarDates` plugin is my adaptation of the `BirthdayReport`
+plugin distributed with Gramps ([[CalendarDates.patch]]).  To install
+my plugin, create `~/.gramps/gramps34/plugins/CalendarDates`, drop
+[[CalendarDates.gpr.py]] into the new directory, copy your Gramps
+installation's version of `BirthdayReport.py` into the new directory
+as `CalendarDates.py` and apply my patch with:
+
+    $ patch CalendarDates < CalendarDates.patch
+
+[calendar]: http://bsdcalendar.sourceforge.net/
+[Gramps]: http://www.gramps-project.org/
+
+[[!tag tags/linux]]
+[[!tag tags/tools]]
+[[!tag tags/python]]
diff --git a/posts/Gramps_and_calendar/CalendarDates.gpr.py b/posts/Gramps_and_calendar/CalendarDates.gpr.py
new file mode 100644 (file)
index 0000000..d36a2a5
--- /dev/null
@@ -0,0 +1,38 @@
+# Gramps - a GTK+/GNOME based genealogy program
+#
+# Copyright (C) 2008 - 2009  Douglas S. Blank <doug.blank@gmail.com>
+# Copyright (C) 2009         B. Malengier <benny.malengier@gmail.com>
+#
+# 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
+#
+# $Id:$
+#
+
+register(
+    REPORT,
+    id                   = 'calendar_dates',
+    name                 = _('Calendar dates report'),
+    description          = _(
+        'Record birthdays and aniversaries for the calendar program'),
+    version = '0.1',
+    gramps_target_version= '3.4',
+    status               = STABLE,
+    fname                = 'CalendarDates.py',
+    category             = CATEGORY_TEXT,
+    reportclass          = 'CalendarReport',
+    optionclass          = 'CalendarOptions',
+    report_modes         = [
+        REPORT_MODE_GUI, REPORT_MODE_BKI, REPORT_MODE_CLI],
+         )
diff --git a/posts/Gramps_and_calendar/CalendarDates.patch b/posts/Gramps_and_calendar/CalendarDates.patch
new file mode 100644 (file)
index 0000000..66d3536
--- /dev/null
@@ -0,0 +1,162 @@
+--- /home/wking/src/gramps/src/plugins/textreport/BirthdayReport.py    2011-09-15 07:09:35.000000000 -0400
++++ CalendarDates/CalendarDates.py     2011-12-08 07:16:13.000000000 -0500
+@@ -2,8 +2,9 @@
+ #
+ # Copyright (C) 2000-2007  Donald N. Allingham
+ # Copyright (C) 2008-2009  Brian G. Matherly
+-# Copyright (C) 2009           Rob G. Healey <robhealey1@gmail.com>
++# Copyright (C) 2009       Rob G. Healey <robhealey1@gmail.com>
+ # Copyright (C) 2010       Jakim Friant
++# Copyright (C) 2011       W. Trevor King <wking@drexel.edu>
+ #
+ # 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
+@@ -144,26 +145,6 @@
+         # get data from database:
+         self.collect_data()
+         # generate the report:
+-        self.doc.start_paragraph('BIR-Title') 
+-        self.doc.write_text(str(self.titletext) + ": " + str(self.year))
+-        self.doc.end_paragraph()
+-        if self.text1.strip() != "":
+-            self.doc.start_paragraph('BIR-Text1style')
+-            self.doc.write_text(str(self.text1))
+-            self.doc.end_paragraph()
+-        if self.text2.strip() != "":
+-            self.doc.start_paragraph('BIR-Text2style')
+-            self.doc.write_text(str(self.text2))
+-            self.doc.end_paragraph()
+-        if self.text3.strip() != "":
+-            self.doc.start_paragraph('BIR-Text3style')
+-            self.doc.write_text(str(self.text3))
+-            self.doc.end_paragraph()
+-        if self.relationships:
+-            name = self.center_person.get_primary_name()
+-            self.doc.start_paragraph('BIR-Text3style')
+-            self.doc.write_text(_("Relationships shown are to %s") % _nd.display_name(name))
+-            self.doc.end_paragraph()
+         self.progress.set_pass(_('Formatting months...'), 12)
+         for month in range(1, 13):
+             self.progress.step()
+@@ -173,26 +154,17 @@
+     def print_page(self, month):
+         """ Prints a month as a page """
+         year = self.year
+-        self.doc.start_paragraph('BIR-Monthstyle')
+-        self.doc.write_text(_dd.long_months[month].capitalize())
+-        self.doc.end_paragraph()
+         current_date = datetime.date(year, month, 1)
+         current_ord = current_date.toordinal()
+-        started_day = {}
+         for i in range(31):
+             thisday = current_date.fromordinal(current_ord)
+             if thisday.month == month:
+                 list = self.calendar.get(month, {}).get(thisday.day, [])
+                 for p in list:
+                     p = p.replace("\n", " ")
+-                    if thisday not in started_day:
+-                        self.doc.start_paragraph("BIR-Daystyle")
+-                        self.doc.write_text(str(thisday.day))
+-                        self.doc.end_paragraph()
+-                        started_day[thisday] = 1
+-                    self.doc.start_paragraph("BIR-Datastyle")
+-                    self.doc.write_text(p)
+-                    self.doc.end_paragraph()
++                    self.doc.f.write(
++                        '{}\t{}\n'.format(
++                            thisday.strftime('%B %d'), p))
+             current_ord += 1
+     def collect_data(self):
+@@ -241,7 +213,10 @@
+                                 if father_handle:
+                                     father = self.database.get_person_from_handle(father_handle)
+                                     if father is not None:
+-                                        father_lastname = father.get_primary_name().surname
++                                        try:
++                                            father_lastname = father.get_primary_name().surname
++                                        except AttributeError:
++                                            pass
+                 short_name = self.get_name(person, father_lastname)
+                 alive = probably_alive(person, self.database, prob_alive_date)
+@@ -255,17 +230,10 @@
+                                                          person)
+                         if relation:
+                             comment = " --- %s" % relation
+-                    if nyears == 0:
+-                        text = _('%(person)s, birth%(relation)s') % {
+-                            'person'   : short_name,
+-                            'relation' : comment}
+-                    else:
+-                        text = (ngettext('%(person)s, %(age)d%(relation)s', 
+-                                         '%(person)s, %(age)d%(relation)s', nyears)
+-                                % {'person'   : short_name,
+-                                   'age'      : nyears,
+-                                   'relation' : comment})
+-
++                    text = _('%(person)s, birth%(relation)s (%(year)d)') % {
++                        'person'   : short_name,
++                        'relation' : comment,
++                        'year'     : year}
+                     self.add_day_item(text, month, day)
+             if self.anniversaries:
+                 family_list = person.get_family_handle_list()
+@@ -305,24 +273,18 @@
+                                     nyears = self.year - year
+                                     if event_obj.is_valid():
+-                                        if nyears == 0:
+-                                            text = _("%(spouse)s and\n %(person)s, wedding") % {
+-                                                     'spouse' : spouse_name, 
+-                                                     'person' : short_name}
+-                                        else:
+-                                            text = (ngettext("%(spouse)s and\n %(person)s, %(nyears)d",
+-                                                             "%(spouse)s and\n %(person)s, %(nyears)d", nyears)
+-                                                    % {'spouse' : spouse_name, 
+-                                                       'person' : short_name, 
+-                                                       'nyears' : nyears})
++                                        text = _("%(spouse)s and %(person)s, wedding (%(year)d)") % {
++                                            'spouse' : spouse_name, 
++                                            'person' : short_name,
++                                            'year'   : year}
+  
+-                                            prob_alive_date = Date(self.year, month, day)
+-                                            alive1 = probably_alive(person, self.database,
+-                                                                    prob_alive_date)
+-                                            alive2 = probably_alive(spouse, self.database,
+-                                                                    prob_alive_date)
+-                                            if (self.alive and alive1 and alive2) or not self.alive:
+-                                                self.add_day_item(text, month, day)
++                                        prob_alive_date = Date(self.year, month, day)
++                                        alive1 = probably_alive(person, self.database,
++                                                                prob_alive_date)
++                                        alive2 = probably_alive(spouse, self.database,
++                                                                prob_alive_date)
++                                        if (self.alive and alive1 and alive2) or not self.alive:
++                                            self.add_day_item(text, month, day)
+ #------------------------------------------------------------------------
+ #
+@@ -476,19 +438,5 @@
+         
+     def make_default_style(self, default_style):
+         """ Add the styles used in this report """
+-        self.make_my_style(default_style, "BIR-Title", 
+-                           _('Title text style'), 14, 
+-                           bold=1, justified="center")
+-        self.make_my_style(default_style, "BIR-Datastyle", 
+-                           _('Data text display'), 12, indent=1.0)
+-        self.make_my_style(default_style, "BIR-Daystyle", 
+-                           _('Day text style'), 12, indent=.5, 
+-                           italic=1, bold=1)
+-        self.make_my_style(default_style, "BIR-Monthstyle", 
+-                           _('Month text style'), 14, bold=1)
+-        self.make_my_style(default_style, "BIR-Text1style", 
+-                           _('Text at bottom, line 1'), 12, justified="center")
+-        self.make_my_style(default_style, "BIR-Text2style", 
+-                           _('Text at bottom, line 2'), 12, justified="center")
+-        self.make_my_style(default_style, "BIR-Text3style", 
+-                           _('Text at bottom, line 3'), 12, justified="center")
++        self.make_my_style(default_style, "Line-style", 
++                           _('Data line display'))