public
Description: A bleeding-edge package manager.
Homepage: http://roastbeef.rubyforge.org
Clone URL: git://github.com/technomancy/roast-beef.git
roast-beef / lib / roastbeef.rb
100644 79 lines (62 sloc) 2.396 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
$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