Use xmllint which is part of libxml2, which is part of most distros.
You can use XMLStarlet if you want, the XPath is the same whichever XML tool you use (it's a standard, after all).
For example, to retrieve details about package "0ad" from index.plist, do this
Code: Select all
xmllint --xpath '/plist/dict/key[text()="0ad"]/following-sibling::dict[1]' index.plist
To get the same thing for "rox" package (the beloved rox filer):
Code: Select all
xmllint --xpath '/plist/dict/key[text()="rox"]/following-sibling::dict[1]' index.plist
To match the output of your example, it's just a matter of re-building the missing elements (of which you know all the details already).
The complete code for extract the package looks like this:
Code: Select all
#$1-package to extract, $2-path to index.plist
extract() {
local pkg=$1 plist="$2"
cat << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>$pkg</key>
$(xmllint --xpath '/plist/dict/key[text()="'$pkg'"]/following-sibling::dict[1]' "$plist")
</dict>
</plist>
EOF
}
_________________
Out of topic rant: (since peebee already SOLVED/CLOSED the main topic anyway):
When posting this, I want to reference my post that performs the conversion of Void's index.plist to PPM package database. And tell you what, I'm very surprised that I cannot find my own post. In fact, it seems that the whole thread about the "Let's build a Community Puppy" has completely disappeared.
This is disheartening.
I spent time to experiment and wrote that script, and then posted it. The time that I could never recover back. It was a time worthwhile spent, because, I thought, others could see and learn from it.
And now, through no fault of my own, because of other bickering personalities that has nothing to do with me or with the original post, that thread has now disappeared. I saw it when the thread was locked, and I thought it was good enough - but no, the entire thread HAS to go down the drain too.
Please, answer me: why would I bother to post anything in the future, if my posts can be taken down because others happen to pollute the thread?
Why does the thread have to go, anyway? Is it because we're ashamed that we're not a shining example of peace to the world? Is it because we're ashamed that we're not as civil as the image we try to project?
Here's a suggestion: if a thread gets too hot, by all means, LOCK IT. If you have the time and motivation to edit/remove the irrelevant posts, by all means, do that. In fact, do that right after the insults are posted, so things don't accumulate and it gets too difficult to separate the chaff from the wheat.
But please, don't take it down. Don't hide it. EVER. Leave it, for everybody to see, to learn from it.
Disagreements are part of everyday life, sometimes, even strong disagreements. We can't all agree at all time. Sometimes disagreement can be civil, sometimes it isn't. It happens even to people with the best intentions. Even to the nicest forum in the known galaxy: this forum.
To hide it is the same as not admitting that we have disagreements, pretending that we're better than what we actually are. But we know we're fooling no one. That Puppy Linux Community isn't ideal, because its members are not ideal either. We are friendly, but we should not try to show a friendly facade by sweeping the dirt under the carpet.
The same thing had happened in the old forum, and I can happily share with you that it was one of the reasons why I gradually stopped posting. Because there is really no point spending 1-2 hours writing a guide to help a newbie, when someone could just come, throw insults, and then entire thread disappears.
Merry Christmas everybody, and please, be civil.
Even if you disagree with one another.