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
26 @attribs = Hash.new { |h, k| h[k] = "" }
28 @attribs[:dependencies] = Dependencies.new
29 @attribs[:source] = Sources.new
30 @attribs[:build] = BuildFunc.new
35 def method_missing(meth, *args)
36 if meth.to_s.match(/=$/) then
37 m2 = meth.to_s[0...-1].to_sym
38 @attribs[m2] = (args.length < 2 ? args.first : args)
45 @attribs[:dependencies].uniq!
46 @attribs[:dependencies]
50 File.exist?(footprint)
58 Tempfile.open("pkgfile") do |file|
59 COMMENT_MAP.each do |key, symbol|
60 value = @attribs[symbol]
63 file << "# #{key}: " << value << "\n"
68 vars = [:name, :version, :release, :source]
74 file << "\n" << build << "\n"
77 FileUtils.cp(file.path, pkgfile)
83 vars = [:name, :version, :release]
86 cmt_map = OHash.new.replace(COMMENT_MAP)
88 File.read(pkgfile).split("\n").each do |line|
91 cmt_map.each do |key, symbol|
92 md = line.match(/^#\s*#{key}: (.+)$/)
94 @attribs[symbol].replace(md.captures.first.strip)
100 md = line.match(/^#{var}=(.+)$/)
102 @attribs[var] = $1.strip
107 # handle source array
108 section = :void if line.match(/^\s*$/) && section != :build
110 if section == :source && line.match(/(.+)\)$/)
111 @attribs[:source] << $1.strip
112 elsif section == :source && line.match(/(.+)\\$/)
113 @attribs[:source] << $1.strip
114 elsif line.match(/^source=\((.+)\)$/)
115 @attribs[:source] << $1.strip
116 elsif line.match(/^source=\((.+)\\$/)
117 @attribs[:source] << $1.strip
121 section = :end unless line.match(/^\}/).nil?
123 # remove initial indentation
124 tmp = line.sub(/^( |\t)/, "")
126 @attribs[:build] << (tmp || "")
128 section = :build unless line.match(/^build/).nil?
133 File.join(@dir, "Pkgfile")
137 File.join(@dir, ".footprint")
141 File.join(@dir, ".md5sum")
145 class Dependencies < Array
156 arg.split(", ").each { |d| self << d.strip }
165 class Sources < Array
167 indent = " " * "source=(".length
168 "(" + join(" \\\n" + indent) + ")"
172 class BuildFunc < Array
174 inject("build() {\n") do |a, line|