$LOAD_PATH << File.dirname(__FILE__) + '/roastbeef'
require 'yaml'
require 'open-uri'
require 'package_manager'
require 'package'
module RoastBeef
VERSION = '0.0.4'
USAGE = "roastbeef #{VERSION}
uh ok so roast beef is some kind of package manager that uses upstream
repositories instead of maintaining its own. basically it helps you download
configure and install the newest version of a program.
#{File.read(File.dirname(__FILE__) + '/../README.txt').split(/==.*$/)[2].strip}
of course you can find out more things at http://roastbeef.rubyforge.org"
SRC_DIR = File.expand_path("~/src") # TODO: allow customization?
LISTING_FILENAME = File.expand_path('~/.roastbeef/sources.yml')
# URLs to check for sources. only one is used
# TODO: allow users to add their own
UPDATE_SOURCES = ['http://github.com/technomancy/roast-beef/tree/master/sources.yml?raw=true',
'http://roastbeef.rubyforge.org/sources.yml']
module_function
def install(package)
Package.find(package).install
end
# find the first usable source listing and cache it
def update
# TODO: eventually a single YAML file will not scale.
# will probably have to marshall.
setup if !File.exist?(SRC_DIR) or !File.exist?(LISTING_FILENAME)
File.open(LISTING_FILENAME, 'w') do |f|
UPDATE_SOURCES.select { |s| !f.puts(open(s).read) rescue nil }
end
@listing = nil # force the in-memory copy to be reloaded
end
# upgrade all installed packages
def upgrade
listing.map { |name, meta| find(name).upgrade if find(name).checked_out? }
end
def remove(package)
Package.find(package).remove
end
# searches the name and description of all packages
def search(term)
term = Regexp.new(Regexp.escape(term)) if term.is_a? String
Package.all.select{ |p| p.inspect =~ term }.map{ |pack| puts pack.to_s }
end
def show(name)
p Package.find(name)
end
def listing
update if !File.exist?(LISTING_FILENAME) or
# source list is older than a week
File.mtime(LISTING_FILENAME) < Time.now - 604800
@listing ||= YAML.load(File.read(LISTING_FILENAME))
end
# when we first run we need to do some setup
def setup
puts "ok we are performing some initial setup here..."
system "mkdir -p #{File.dirname(LISTING_FILENAME)} #{SRC_DIR}"
PackageManager.setup
puts "... and now we are done."
end
end