Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#filter_by_name(packages, regexp) ⇒ Object

This method takes an array of packages and filters it by name. Another package array is returned, with only those packages whose name matches the regular expression given.



78
79
80
81
82
# File 'lib/pacmine.rb', line 78

def filter_by_name(packages, regexp)

  packages.keep_if { |package| package[:pkgname].match(regexp) }

end

#filter_by_repo(packages, repo) ⇒ Object

This method takes an array of packages and filters it by repo. Another package array is returned, with only those packages in ‘repo’ present.



69
70
71
72
73
# File 'lib/pacmine.rb', line 69

def filter_by_repo(packages, repo)

  packages.keep_if { |package| package[:repo] === repo }

end

#get_package_list(maintainer, file = nil) ⇒ Object

Get a list of packages for the maintainer specified If file is a string containing a filename, query that instead, ignoring whichever maintainer username was given.



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
# File 'lib/pacmine.rb', line 7

def get_package_list maintainer, file=nil

  # Query the package source
  if file
    begin
      doc = Hpricot( File.open(file, "r") { |f| f.read } )
    rescue
      warn "There was a problem reading the file specified."
      exit 1
    end
  else
    begin
      doc = open("https://www.archlinux.org/packages/?sort=&q=&maintainer=#{maintainer}&limit=9999") { |f| Hpricot(f) }
    rescue
      warn "There was a problem querying www.archlinux.org for the package list."
      exit 1
    end
  end

  # Get the results table from the document
  table = doc.at("//table[@class='results']")

  # Put each of the rows in the table into an array
  begin
    rows = table.search("//tr")
  rescue
    warn "Could not find any packages."
    exit 1
  end

  # Remove the first row, which contains column headers
  rows.shift

  # We will store our list of packages here
  packages = Array.new

  # Collect the packages and their repos from the array of rows,
  # put them in to the packages array.
  rows.each do |row|

    # The columns (td elements) for this row
    columns = row.search("//td")

    # The repo is in column 1
    repo = columns[1].inner_html.downcase

    # The package name is in column 2 as a hyperlink
    pkgname = columns[2].at("//a").inner_html

    # Add this package and repo name to the packages array
    packages.push ({:repo => repo, :pkgname => pkgname})

  end

  # Finally, remove duplicates and return.
  # (For example, packages with multiple architectures will be duplicated).
  packages.uniq

end