-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables.rb
executable file
·80 lines (65 loc) · 1.81 KB
/
tables.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
#!/usr/bin/env ruby
require 'aptly'
require 'optparse'
require 'ostruct'
require 'uri'
require 'net/ssh/gateway'
require 'logger'
require 'logger/colors'
require 'html/table'
include HTML
options = OpenStruct.new
options.repos = nil
options.all = false
options.host = 'localhost'
options.port = '8080'
options.distribution = nil
parser = OptionParser.new do |opts|
opts.banner = "Usage: #{opts.program_name} [options] --repo yolo"
opts.on('-g', '--gateway URI', 'open gateway to remote') do |v|
options.gateway = URI(v)
end
opts.on('-d', '--distribution DIST', 'Override distribution in released repository') do |v|
options.distribution = v
end
end
parser.parse!
raise parser.help if options.distribution.nil?
if options.gateway
case options.gateway.scheme
when 'ssh'
gateway = Net::SSH::Gateway.new(options.gateway.host, options.gateway.user)
options.port = gateway.open('localhost', options.gateway.port)
else
raise 'Gateway scheme not supported'
end
end
Aptly.configure do |config|
config.host = options.host
config.port = options.port
end
Faraday.default_connection_options =
Faraday::ConnectionOptions.new(timeout: 2 * 60 * 60)
@log = Logger.new(STDOUT).tap do |l|
l.progname = 'snapshotter'
l.level = Logger::INFO
end
@html = ''
@repos = Aptly::PublishedRepository.list.select { |x| x if x.Distribution.include? options.distribution }
@repos.each do |repo|
@log.info "Getting #{repo}"
source = repo.Sources[0]
@table = HTML::Table.new do
header source.Name
end
packages = source.packages(q: '$Architecture (= source)')
packages.each do |package|
_, source, version = package.split
@table.push Table::Row.new { |r|
r.align = 'right'
r.content = [source, version]
}
end
@html += @table.html + '<br>'
end
File.write('packages.html', @html)