adjustments to the import tool so binary plists can be read...

This commit is contained in:
capitaomorte 2010-03-14 19:59:19 +00:00
parent f1ce4866b6
commit 23bf5b7a1e

View File

@ -103,7 +103,8 @@ class TmSnippet
def initialize(file,info=nil) def initialize(file,info=nil)
@file = file @file = file
@info = info @info = info
@snippet = Plist::parse_xml(file) @snippet = TmSnippet::read_plist(file)
raise RuntimeError.new("Cannot convert this snippet #{file}!") unless @snippet;
end end
def name def name
@ -177,12 +178,27 @@ class TmSnippet
File.join(basedir,canonicalize(@file[0, @file.length-File.extname(@file).length]) + ".yasnippet") File.join(basedir,canonicalize(@file[0, @file.length-File.extname(@file).length]) + ".yasnippet")
end end
def self.read_plist(xml_or_binary)
begin
parsed = Plist::parse_xml(xml_or_binary)
return parsed if parsed;
raise RuntimeError.new "Probably in binary format and parse_xml is very quiet..."
rescue RuntimeError => e
if (system "plutil -convert xml1 '#{xml_or_binary}' -o /tmp/textmate_import")
return Plist::parse_xml("/tmp/textmate_import")
else
raise RuntimeError.new "plutil failed miserably, check if you have it..."
end
end
end
end end
if $0 == __FILE__ if $0 == __FILE__
info_plist = Plist::parse_xml(Choice.choices.info_plist) if Choice.choices.info_plist
info_plist = TmSnippet::read_plist(Choice.choices.info_plist) if Choice.choices.info_plist;
if Choice.choices.output_dir if Choice.choices.output_dir
FileUtils.mkdir_p Choice.choices.output_dir FileUtils.mkdir_p Choice.choices.output_dir
@ -217,7 +233,7 @@ if $0 == __FILE__
puts "\n\n" puts "\n\n"
end end
rescue Exception => e rescue Exception => e
$stderr.puts "Oops... #{e.class}:#{e.message}" $stderr.puts "Oops... #{e.class}:#{e.message}\n#{e.backtrace.join("\n")}"
end end
end end
end end