forked from vbatts/slackware-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_paths.rb
93 lines (83 loc) · 2.23 KB
/
get_paths.rb
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env ruby
require 'open-uri'
module Slackware
class Repo
DEFAULT_MIRROR = "http://mirrors.kernel.org/slackware"
DEFAULT_RELEASE = "slackware64-current"
RE_FILELIST = /.*(\d{4}-\d{2}-\d{2} \d{2}:\d{2})\s\.\/(\w*)\/(.*\.t.z)\n?/
def initialize(release = nil, mirror = nil)
@mirror = mirror || DEFAULT_MIRROR
@release = release || DEFAULT_RELEASE
@tag_done = false
@pkgs = []
end
def pkgs
return @pkgs unless @pkgs.empty?
fl = open("#{@mirror}/#{@release}/#{_base_rel}/FILE_LIST")
fl.each_line do |line|
line.strip!
puts line
if line =~ RE_FILELIST
@pkgs << Slackware::Package.parse($2 + "/" + $3)
end
end
fl.close
return @pkgs
end
def sections
return pkgs.map {|p| p.section }.uniq
end
def tagfiles
return pkgs.map {|p| p.tag }.uniq if @tag_done
sections.each do |section|
fl = open("#{@mirror}/#{@release}/#{_base_rel}/#{section}/tagfile")
fl.each_line do |line|
p_name, tag = line.strip.split(":",2)
pkg = pkgs.detect {|p| p.name == p_name }
if pkg
pkg.tag = tag
else
$stderr.puts("#{p_name} not in pkgs")
end
end
fl.close
end
@tag_done = true
return @pkgs.map {|p| p.tag }.uniq
end
private
def _base_rel
@release.split("-").first
end
end
class Package
attr_accessor :section, :name, :version, :arch, :build, :ext, :tag
def self.parse(str)
pkg = self.new
paths = str.split('/')
pkg_str = paths.pop
if paths.length > 0
pkg.section = paths.join('/')
end
pkg.ext = File.extname(pkg_str)
chunks = File.basename(pkg_str, pkg.ext).split('-')
pkg.build = chunks.pop
pkg.arch = chunks.pop
pkg.version = chunks.pop
pkg.name = chunks.join('-')
return pkg
end
def to_s
"#{@section.nil? ? '' : @section + '/'}#{@name}-#{@version}-#{@arch}-#{@build}#{@ext}"
end
end
end
def main(args)
# build out the tag files
r = Slackware::Repo.new(args.first)
r.tagfiles
r.pkgs.each do |pkg|
puts "#{pkg}:#{pkg.tag}" unless pkg.tag.nil?
end
end
main(ARGV)