1 require "cruxutils/ohash.rb"
8 COMMENT_MAP = OHash.new
9 COMMENT_MAP["Description"] = :description
10 COMMENT_MAP["URL"] = :url
11 COMMENT_MAP["Packager"] = :packager
12 COMMENT_MAP["Maintainer"] = :maintainer
13 COMMENT_MAP["Depends on"] = :dependencies
14 COMMENT_MAP["Group"] = :group
15 COMMENT_MAP["Nice to have"] = :nice_to_have
24 @attribs = Hash.new { |h, k| h[k] = "" }
26 @attribs[:dependencies] = Dependencies.new
27 @attribs[:source] = Sources.new
28 @attribs[:build] = BuildFunc.new
33 def method_missing(meth, *args)
34 if meth.to_s.match(/=$/) then
35 m2 = meth.to_s[0...-1].to_sym
36 @attribs[m2] = (args.length < 2 ? args.first : args)
43 @attribs[:dependencies].uniq!
44 @attribs[:dependencies]
48 File.exist?(footprint)
56 Tempfile.open("pkgfile") do |file|
57 COMMENT_MAP.each do |key, symbol|
58 value = @attribs[symbol]
61 file << "# #{key}: " << value << "\n"
66 vars = [:name, :version, :release, :source]
72 file << "\n" << build << "\n"
75 FileUtils.cp(file.path, pkgfile)
81 vars = [:name, :version, :release]
84 cmt_map = OHash.new.replace(COMMENT_MAP)
86 File.read(pkgfile).split("\n").each do |line|
89 cmt_map.each do |key, symbol|
90 md = line.match(/^#\s*#{key}: (.+)$/)
92 @attribs[symbol].replace(md.captures.first.strip)
98 md = line.match(/^#{var}=(.+)$/)
100 @attribs[var] = $1.strip
105 # handle source array
106 section = :void if line.match(/^\s*$/) && section != :build
108 if section == :source && line.match(/(.+)\)$/)
109 @attribs[:source] << $1.strip
110 elsif section == :source && line.match(/(.+)\\$/)
111 @attribs[:source] << $1.strip
112 elsif line.match(/^source=\((.+)\)$/)
113 @attribs[:source] << $1.strip
114 elsif line.match(/^source=\((.+)\\$/)
115 @attribs[:source] << $1.strip
119 section = :end unless line.match(/^\}/).nil?
121 # remove initial indentation
122 tmp = line.sub(/^( |\t)/, "")
124 @attribs[:build] << (tmp || "")
126 section = :build unless line.match(/^build/).nil?
131 File.join(@dir, "Pkgfile")
135 File.join(@dir, ".footprint")
139 File.join(@dir, ".md5sum")
143 class Dependencies < Array
154 arg.split(", ").each { |d| self << d.strip }
163 class Sources < Array
165 indent = " " * "source=(".length
166 "(" + join(" \\\n" + indent) + ")"
170 class BuildFunc < Array
172 inject("build() {\n") do |a, line|