I am trying to extend a bit the features-set available to manage groups in BibDesk and I want to manipulate from a program the bibtex comments in which BibDesk writes down information for Static Groups.
To do this I need a systematic and robust way to get all that is inside this comment part of the bibtex file.
@comment{BibDesk Static Groups{
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>group name</key>
<string>MyGroupName</string>
<key>keys</key>
<string>BitexRefId1,BitexRefId2</string>
</dict>
</array>
</plist>
}}
Once I put my hands on the XML array
I think I know what to do with it, but the first part, getting the @comment{BibDesk Static Groups{
is a bit tricky to me.
I would know how to it with sed
using sed -e '/@comment{BibDesk Static Groups{/,/}/!d' test.bib
, but what would be the pythonic way to do that?
My best thing was essentially a home-grown parser
file = open(file_name,"r")
for line in file:
if static_groups_group:
if "}" in line:
static_groups_group=False
print "ending static group block"
if static_groups_group:
xml_groups.append(line)
if "@comment{BibDesk Static Groups{" in line:
print line," found"
static_groups_group=True