Difference between revisions of "User:JohnRSibert"

From Gramps
Jump to: navigation, search
(Initial commit of personal page.)
 
(Create draft How to "customize reports with an XML tool")
Line 1: Line 1:
I'm a retired marine scientist with a lot of lines of code under my belt. The pandemic has given me the excuse to play with more code and perhaps make another open source contribution. I can be contacted via gmail or github.
+
I'm a retired marine scientist with a lot of lines of code under my belt. The pandemic has given me the excuse to play with more code and perhaps make another open source contribution. I can be contacted via gmail or github [https://github.com/johnrsibert/Grampsish].
 +
 
 +
 
 +
== customize reports with an XML tool ==
 +
Families often have complicated structure, especially for Twenty-first century blended families. Creatating a Family Lines Graph for such families often involves carefully selecting multiple people to include. Gramps stores these selections in a file named report_options.xml in the ~/.gramps directory. The report options are '''overwitten''' every time a graphical report is created. It is possible to edit this file manually with a text editor, but that is a tedious and error-prone procedure. The following bash script will take care of the process for you backing up the current file and saving the list of persion IDs in a file that can be reused.
 +
 
 +
#!/bin/bash
 +
if [ $# -lt 1 ];then
 +
    echo "Utility to replace list of People of Ineterst in Gramps Family Lines Graph."
 +
    echo "The file 'report_options.xml' is overwritten after making a backup."
 +
    echo "The current list of People of Ineterst is saved for possible reuse"
 +
    echo "Usage: "$0" current_pid [new_pid]"
 +
    echo "  current_pid is the file name in which to save current pid list"
 +
    echo "  Optional. If present, new_pid is the name of the file containing"
 +
    echo "  the new pid list"
 +
    echo "  eg " $0" bigfamily.pid three_gen.pid"
 +
    exit 1
 +
fi
 +
 +
gramps_home=~/.gramps/
 +
#echo "gramps_home = "$gramps_home
 +
opts=$gramps_home"report_options.xml"
 +
#echo "opts = "$opts
 +
bak=$opts".bak"
 +
#echo "bak = "$bak
 +
 +
echo "Backing up "$opts " to " $bak
 +
cp -irp $opts $bak
 +
 +
echo "Saving current pid list to "$gramps_home$1
 +
lxprintf -e 'module[@name="familylines_graph"]/option[@name="gidlist"]'\
 +
  "%s\n" @value $opts > $gramps_home$1
 +
 +
echo "Replacing pids in "$opts
 +
echo "    with the contents of "$gramps_home$2
 +
 +
# replacing the xml in situ does not seem to work correctly
 +
# instead send it to a temporary file and copy
 +
lxreplace -q \
 +
  'module[@name="familylines_graph"]/option[@name="gidlist"]' \
 +
  -@ '"value"' "'`cat $gramps_home$2`'" \
 +
  ~/.gramps/report_options.xml > /tmp/temp.xml
 +
 +
cp -fv /tmp/temp.xml $opts 2>>/dev/null
 +
echo "Updated "$opts

Revision as of 15:12, 25 March 2021

I'm a retired marine scientist with a lot of lines of code under my belt. The pandemic has given me the excuse to play with more code and perhaps make another open source contribution. I can be contacted via gmail or github [1].


customize reports with an XML tool

Families often have complicated structure, especially for Twenty-first century blended families. Creatating a Family Lines Graph for such families often involves carefully selecting multiple people to include. Gramps stores these selections in a file named report_options.xml in the ~/.gramps directory. The report options are overwitten every time a graphical report is created. It is possible to edit this file manually with a text editor, but that is a tedious and error-prone procedure. The following bash script will take care of the process for you backing up the current file and saving the list of persion IDs in a file that can be reused.

#!/bin/bash
if [ $# -lt 1 ];then
    echo "Utility to replace list of People of Ineterst in Gramps Family Lines Graph."
    echo "The file 'report_options.xml' is overwritten after making a backup."
    echo "The current list of People of Ineterst is saved for possible reuse" 
    echo "Usage: "$0" current_pid [new_pid]"
    echo "   current_pid is the file name in which to save current pid list"
    echo "   Optional. If present, new_pid is the name of the file containing"
    echo "   the new pid list"
    echo "   eg " $0" bigfamily.pid three_gen.pid"
    exit 1
fi 

gramps_home=~/.gramps/
#echo "gramps_home = "$gramps_home
opts=$gramps_home"report_options.xml"
#echo "opts = "$opts
bak=$opts".bak"
#echo "bak = "$bak

echo "Backing up "$opts " to " $bak 
cp -irp $opts $bak

echo "Saving current pid list to "$gramps_home$1
lxprintf -e 'module[@name="familylines_graph"]/option[@name="gidlist"]'\
 "%s\n" @value $opts > $gramps_home$1

echo "Replacing pids in "$opts
echo "    with the contents of "$gramps_home$2

# replacing the xml in situ does not seem to work correctly
# instead send it to a temporary file and copy
lxreplace -q \
  'module[@name="familylines_graph"]/option[@name="gidlist"]' \
  -@ '"value"' "'`cat $gramps_home$2`'" \
  ~/.gramps/report_options.xml > /tmp/temp.xml

cp -fv /tmp/temp.xml $opts 2>>/dev/null
echo "Updated "$opts