Snippet: SVN Info Parsing with YAML
Posted by kev Fri, 17 Aug 2007 23:44:00 GMT
require 'yaml'
require 'pp'
pp YAML.load(`svn info`) # =>
# {"Node Kind"=>"directory",
# "Last Changed Author"=>"nzkoz",
# "URL"=>"http://dev.rubyonrails.org/svn/rails/trunk",
# "Schedule"=>"normal",
# "Last Changed Rev"=>7332,
# "Repository UUID"=>"5ecf4fe2-1ee6-0310-87b1-e25e094e27de",
# "Repository Root"=>"http://dev.rubyonrails.org/svn/rails",
# "Last Changed Date"=>"2007-08-16 18:11:11 -0700 (Thu, 16 Aug 2007)",
# "Revision"=>7340,
# "Path"=>"."}


Nice catch!
is nice - Borat
That’s a nice one. But svn info output depends on the machine’s locale, so you could run into potential errors when trying to use the parsed info.
I prefer to take advantage of the—xml option you can pass to every svn command use XmlSimple.
The XML nodes keep the name in English no matter what your locale is.
>> pp XmlSimple.xml_in(`svn info --xml`) {"entry"=> [{"commit"=> [{"date"=>["2007-06-25T13:06:18.342675Z"], "author"=>["jramirez"], "revision"=>"278"}], "kind"=>"dir", "repository"=> [{"uuid"=>["ef259510-392e-0410-90f3-ae674396ba6e"], "root"=>["http://svn_aspgems/jramirez"]}], "wc-info"=>[{"schedule"=>["normal"]}], "url"=>["http://svn_aspgems/jramirez/trunk"], "revision"=>"278", "path"=>"."}]}regards,
j
hpricot version:
Hpricot::XML
regards