Skip to content
Browse files

first serious metadata collecting (from github)

  • Loading branch information...
1 parent a74cb8d commit 97b2b02d2ec114e996d988d2637cac6150b96497 @darwin committed Feb 7, 2009
Showing with 63 additions and 4 deletions.
  1. +1 −1 bin/pbdev
  2. +6 −0 lib/pbdev.rb
  3. +1 −1 lib/pbdev/checkout.rb
  4. +3 −0 lib/pbdev/errors.rb
  5. +52 −2 lib/pbdev/repo.rb
View
2 bin/pbdev
@@ -62,7 +62,7 @@ case cmd
begin
resource.bake(dest)
rescue Exception
- Trollop::die "Error: "+$!
+ Trollop::die $!
end
puts "Resource baked into #{dest}"
end
View
6 lib/pbdev.rb
@@ -2,7 +2,13 @@
require 'rubygems'
require 'fileutils'
+begin
+ require 'hpricot'
+rescue
+ raise "Do: sudo gem install hpricot"
+end
require 'grit/lib/grit.rb'
+#Grit.debug = true
unless defined? OSX then
OSX = PLATFORM =~ /darwin/
View
2 lib/pbdev/checkout.rb
@@ -86,7 +86,7 @@ def prepare_final(final, prolog, *results)
def minify(path)
yui_root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'yui-compressor'))
jar_path = File.join(yui_root, 'yuicompressor-2.4.2.jar')
- filecompress = "java -jar \"" + jar_path + "\" --charset utf-8 \"" + path + "\" -o \"" + path + "\""
+ filecompress = "java -jar \"" + jar_path + "\" --charset utf-8 --line-break 120 \"" + path + "\" -o \"" + path + "\""
PB.logger.info(' crunching with YUI Compressor ...')
# puts "> "+yellow(filecompress)
res = `#{filecompress} 2>&1`
View
3 lib/pbdev/errors.rb
@@ -12,4 +12,7 @@ class ResourceNotFoundError < StandardError
class YUICompressorError < StandardError
end
+ class RepoError < StandardError
+ end
+
end
View
54 lib/pbdev/repo.rb
@@ -35,11 +35,61 @@ def replace_urls(source)
res.gsub!("\#{FRONT_URL}", @front_url)
res
end
+
+ def collect_meta()
+ res = @repo.git.remote({}, "show", "origin")
+ unless res =~ /URL: (.*)$/
+ raise RepoError.new("unable to retrieve origin/master in #{@repo.path}")
+ end
+ url = $1
+ if url =~ /git@github\.com:([^\/]+)\/([^\/]+)\.git$/
+ return {
+ 'description' => "private repo",
+ 'tags' => [],
+ 'origin' => url,
+ 'home' => '?'
+ }
+ end
+
+ unless url =~ /git:\/\/github\.com\/([^\/]+)\/([^\/]+)\.git$/
+ raise RepoError.new("unable to parse repo url: #{url}")
+ end
+ author = $1
+ project = $2
+ home = "http://github.com/#{author}/#{project}"
+
+ project_human = project
+ if project_human =~ /pb.-(.*)/
+ project_human = $1
+ end
+
+ require 'open-uri'
+ PB.logger.info("Fetching: #{home}")
+ doc = open(home) { |f| Hpricot(f) }
+ raise RepoError.new("unable to download: #{home}") unless doc
+
+ desc = doc.search("//meta[@name='description']")[0]['content']
+ raise RepoError.new("unable to parse description in #{doc}") unless desc
+
+ tags = [author, project_human]
+ if desc =~ /(.*)\[(.*)\]$/
+ desc = $1
+ tags = $2.split(',').map{|t| t.strip }
+ end
+
+ {
+ 'description' => desc,
+ 'tags' => tags,
+ 'origin' => url,
+ 'home' => home
+ }
+ end
def bake(dest=".")
FileUtils.makedirs(dest)
- File.open(File.join(dest, "description.txt"), "w") do |f|
- f << @repo.description
+ meta = collect_meta
+ File.open(File.join(dest, "meta.yaml"), "w") do |f|
+ f << meta.to_yaml
end
postprocess(bake_version("master", dest))
@repo.tags.each do |tag|

0 comments on commit 97b2b02

Please sign in to comment.
Something went wrong with that request. Please try again.