Permalink
Browse files

Initial commit

Working import of formulae from the main Homebrew repository
  • Loading branch information...
0 parents commit 9170043fa48a3c36b1fd2b6f8c7e42d7761ea267 @koraktor committed Jan 6, 2012
@@ -0,0 +1,3 @@
+.bundle
+log/*.log
+tmp/
@@ -0,0 +1,15 @@
+source 'http://rubygems.org'
+
+gem 'bson_ext', '~> 1.5.2'
+gem 'jquery-rails', '~> 1.0.19'
+gem 'mongoid', '~> 2.3.4'
+gem 'rails', '3.1.3'
+
+group :assets do
+ gem 'sass-rails', '~> 3.1.5'
+ gem 'uglifier', '~> 1.2.1'
+end
+
+group :production do
+ gem 'newrelic_rpm', '~> 3.3.1'
+end
@@ -0,0 +1,117 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.3)
+ actionpack (= 3.1.3)
+ mail (~> 2.3.0)
+ actionpack (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.5)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.3)
+ activemodel (3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ bson (1.5.2)
+ bson_ext (1.5.2)
+ bson (= 1.5.2)
+ builder (3.0.0)
+ erubis (2.7.0)
+ execjs (1.2.13)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.19)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.6.4)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ mongo (1.5.2)
+ bson (= 1.5.2)
+ mongoid (2.3.4)
+ activemodel (~> 3.1)
+ mongo (~> 1.3)
+ tzinfo (~> 0.3.22)
+ multi_json (1.0.4)
+ newrelic_rpm (3.3.1)
+ polyglot (0.3.3)
+ rack (1.3.6)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.3)
+ actionmailer (= 3.1.3)
+ actionpack (= 3.1.3)
+ activerecord (= 3.1.3)
+ activeresource (= 3.1.3)
+ activesupport (= 3.1.3)
+ bundler (~> 1.0)
+ railties (= 3.1.3)
+ railties (3.1.3)
+ actionpack (= 3.1.3)
+ activesupport (= 3.1.3)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ sass (3.1.12)
+ sass-rails (3.1.5)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (~> 3.1.10)
+ tilt (~> 1.3.2)
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (!= 1.3.0, ~> 1.1)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+ uglifier (1.2.1)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bson_ext (~> 1.5.2)
+ jquery-rails (~> 1.0.19)
+ mongoid (~> 2.3.4)
+ newrelic_rpm (~> 3.3.1)
+ rails (= 3.1.3)
+ sass-rails (~> 3.1.5)
+ uglifier (~> 1.2.1)
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+
+Braumeister::Application.load_tasks
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,9 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+
+ def not_found
+ flash[:error] = 'The page you requested does not exist.'
+ redirect_to '/'
+ end
+
+end
@@ -0,0 +1,22 @@
+# This code is free software; you can redistribute it and/or modify it under
+# the terms of the new BSD License.
+#
+# Copyright (c) 2012, Sebastian Staudt
+
+class Formula
+
+ include Mongoid::Document
+
+ field :removed, :type => Boolean
+ field :name, :type => String
+ field :homepage, :type => String
+ field :version, :type => String
+ key :name
+
+ embedded_in :repository
+
+ def path
+ File.join(repository.path, 'Library', 'Formula', name) + '.rb'
+ end
+
+end
@@ -0,0 +1,157 @@
+# This code is free software; you can redistribute it and/or modify it under
+# the terms of the new BSD License.
+#
+# Copyright (c) 2012, Sebastian Staudt
+
+class Repository
+
+ include Mongoid::Document
+
+ FORMULA_REGEX = /^Library\/Formula\/(.+?)\.rb$/
+
+ field :date, :type => Time, :default => Time.at(0)
+ field :name, :type => String
+ field :sha, :type => String, :default => 'unknown'
+ key :name
+
+ embeds_many :formulae
+
+ def clone_or_pull
+ if File.exists? path
+ Rails.logger.info "Pulling changes from #{name} into #{path}"
+ git 'fetch --force --quiet origin master'
+
+ last_sha = sha
+ log = git('log -1 --format=format:"%H %ct" FETCH_HEAD').split
+ self.sha = log[0]
+
+ if last_sha == sha
+ Rails.logger.info "Repository #{name} is already up-to-date"
+ return []
+ end
+
+ self.date = Time.at log[1].to_i
+
+ git 'reset --hard --quiet FETCH_HEAD'
+ changes = git "diff --name-status #{last_sha}..HEAD"
+ changes = changes.lines.map { |file| file.split }
+ changes = changes.select { |file| file[1] =~ FORMULA_REGEX }
+
+ Rails.logger.info "Updated #{name} from #{last_sha} to #{sha}:"
+ else
+ Rails.logger.info "Cloning #{name} into #{path}"
+ git "clone --depth 1 --quiet #{url} #{path}"
+
+ log = git('log -1 --format=format:"%H %ct" HEAD').split
+ self.sha = log[0]
+ self.date = Time.at log[1].to_i
+
+ changes = git 'ls-tree --name-only HEAD Library/Formula/*.rb'
+ changes = changes.lines.map { |file| ['A', file.strip] }
+
+ Rails.logger.info "Checked out #{sha} in #{path}"
+ end
+
+ changes
+ end
+
+ def formula_files
+ files = Dir.glob File.join(path, 'Library', 'Formula', '*.rb')
+ files.map { |f| File.basename f, '.rb' }
+ end
+
+ def path
+ "#{Braumeister::Application.tmp_path}/repos/#{name}"
+ end
+
+ def refresh
+ changes = clone_or_pull
+
+ added = changes.select { |file| file[0] == 'A' }
+ modified = changes.select { |file| file[0] == 'M' }
+ removed = changes.select { |file| file[0] == 'D' }
+
+ if changes.size == 0
+ Rails.logger.info 'No formulae changed.'
+ return
+ end
+
+ updated_formulae = []
+ changes.each do |type, fpath|
+ updated_formulae << fpath.match(FORMULA_REGEX)[1] unless type == 'D'
+ end
+
+ formulae_info = formulae_info updated_formulae
+
+ changes.each do |type, fpath|
+ formula = formulae.find_or_create_by :name => fpath.match(FORMULA_REGEX)[1]
+ formula.repository = self if formula.new_record?
+ if type == 'D'
+ formula.removed = true
+ else
+ formula.homepage = formulae_info[formula.name][:homepage]
+ formula.removed = false
+ formula.version = formulae_info[formula.name][:version]
+ end
+ formula.save
+ end
+
+ Rails.logger.info "#{added.size} formulae added, #{modified.size} formulae modified, #{removed.size} formulae removed."
+ end
+
+ def refresh_formula(formula)
+ original_formula = @sandbox::Formula.factory formula.name
+ formula.homepage = original_formula.homepage
+ formula.version = original_formula.version
+ end
+
+ def url
+ "git://github.com/#{name}.git"
+ end
+
+ private
+
+ def git(command)
+ command = "git --git-dir #{path}/.git #{command}"
+ Rails.logger.debug "Executing `#{command}`"
+ `#{command}`.strip
+ end
+
+ def formulae_info(formulae)
+ pipe_read, pipe_write = IO.pipe
+ pid = fork do
+ pipe_read.close
+
+ $LOAD_PATH.unshift File.join(path, 'Library', 'Homebrew')
+ Object.send :remove_const, :Base64
+ Object.send :remove_const, :Formula
+ Object.send :remove_const, :Syck
+
+ require 'global'
+ require 'formula'
+
+ formulae_info = {}
+ formulae.each do |name|
+ formula = Formula.factory name
+ formulae_info[name] = {
+ :homepage => formula.homepage,
+ :version => formula.version
+ }
+ end
+
+ Marshal.dump formulae_info, pipe_write
+ pipe_write.close
+
+ exit!
+ end
+
+ pipe_write.close
+ formulae_info = Marshal.load pipe_read
+ pipe_read.close
+
+ Process.wait pid
+
+ formulae_info
+ end
+
+end
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Braumeister::Application
@@ -0,0 +1,26 @@
+# This code is free software; you can redistribute it and/or modify it under
+# the terms of the new BSD License.
+#
+# Copyright (c) 2012, Sebastian Staudt
+
+require File.expand_path('../boot', __FILE__)
+
+require 'action_controller/railtie'
+require 'sprockets/railtie'
+
+Bundler.require :default, :assets, Rails.env
+
+module Braumeister
+ class Application < Rails::Application
+
+ config.assets.enabled = true
+ config.assets.version = '1.0'
+
+ config.encoding = "utf-8"
+
+ def self.tmp_path
+ @@tmp_path ||= File.join Rails.root, 'tmp'
+ end
+
+ end
+end
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Braumeister::Application.initialize!
@@ -0,0 +1,16 @@
+Braumeister::Application.configure do
+ config.cache_classes = false
+
+ config.whiny_nils = true
+
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ config.active_support.deprecation = :log
+
+ config.action_dispatch.best_standards_support = :builtin
+
+ config.assets.compress = false
+
+ config.assets.debug = true
+end
Oops, something went wrong.

0 comments on commit 9170043

Please sign in to comment.