-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpkgcl
executable file
·160 lines (143 loc) · 3.94 KB
/
pkgcl
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env ruby
# Author: Alex Brown
# email: [email protected]
# license: WTFPL
require 'nokogiri'
require 'open-uri'
require 'optparse'
VERSION = "0.2.1"
@options = {}
@options[:commits] = 1
@options[:show_git_svn] = false
@options[:testing_repo] = false
opts = OptionParser.new do |opts|
opts.banner = "Usage: pkgcl [options] <packages>"
opts.separator ""
opts.on("-c", "--commits=NUM", Integer, "Show NUM commit messages") do |n|
@options[:commits] = n
end
opts.on("--show-git-svn-id", "Show git-svn-id messages") do
@options[:show_git_svn] = true
end
opts.on("--enable-testing", "Show commits relevant to packages in [testing]") do
@options[:testing_repo] = true
end
opts.on("-v", "--version", "Show version information") do
puts VERSION
exit
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
opts.parse!(ARGV)
# check for stdin and get package list accordingly
# I even decided to be nice and parse both 'pacman -Qu' and 'pacman -Qqu' on stdin
packages = []
if STDIN.tty? == false
ARGF.lines do |line|
packages << {:name => line.strip!.split(" ")[0]}
end
else
ARGV.each {|a| packages << {:name => a} }
end
puts opts if packages.empty?
def colorize(text, color_code)
"\e[#{color_code}m#{text}\e[0m"
end
def get_pkg(pkg)
repo, arch = "", ""
IO.popen([{"LC_ALL"=>"C"}, "pacman", "-Si", pkg[:name], :err => :close]) do |io|
io.lines do |line|
case line
when /^Repository(\s?)*: (.+)$/
pkg[:repo] = $2
when /^Architecture(\s?)*: (.+)$/
pkg[:arch] = $2
when /^Build Date(\s?)*: (.+)$/
build_date = Time.parse($2)
if build_date.strftime("%F") == Time.now.strftime("%F")
build_date = Time.now
end
pkg[:build_date] = build_date
end
end
end
end
def get_pkg_info(pkg)
# I need to get the correct git url from here, since some packages use a
# different tracking repo (e.g. linux-headers => linux)
# I'm also getting the last updated date from this url
uri = "http://www.archlinux.org/packages/#{pkg[:repo]}/#{pkg[:arch]}/#{pkg[:name]}"
doc = Nokogiri::HTML(open(uri))
pkg[:git_url] = doc.css("div#actionlist ul li a")[1]['href']
end
def age_test(commit_age, pkg)
case commit_age
when /days/
git_time = Time.now - commit_age.to_i*60*60*24
when /hours/
git_time = Time.now - commit_age.to_i*60*60
when /min/
git_time = Time.now - commit_age.to_i*60
else
git_time = Time.parse(commit_age)
end
if git_time > pkg[:build_date] then
return false
else
return true
end
end
def get_commits(pkg)
pkg[:commits] = []
doc = Nokogiri::HTML(open("#{pkg[:git_url]}&showmsg=1"))
table = doc.css("table.list.nowrap")
table.css("td.logsubject").each_with_index do |n,i|
age = n.parent.children[0].content
if @options[:testing_repo] == false then
next if age_test(age, pkg) == false
end
commit = {}
age+=" ago" if /(days|hours|min)/ === age
commit[:age] = age
commit[:subject] = n.content
content = table.css("td.logmsg")[i].content
content.gsub!(/^git-svn-id.*$/, "") unless @options[:show_git_svn] == true
content.strip!
commit[:msg] = content.empty? ? "None" : content
pkg[:commits] << commit
end
end
def show_output(pkg)
# Format and print the result
print "["+colorize(pkg[:name], 31)+"]"
if pkg[:commits].count < @options[:commits]
print colorize(" (Only #{pkg[:commits].count} commits)\n", 33)
else
print "\n"
end
output = 0
pkg[:commits].each do |p|
break if output == @options[:commits]
puts colorize(p[:subject], 4)
print colorize("Age: ", 37)
print colorize(p[:age], 36)+" - "
puts colorize(p[:msg], 32)
puts
output +=1
end
end
packages.each do |p|
get_pkg(p)
if p.has_key?(:arch) == false && p.has_key?(:repo) == false
puts "["+colorize(p[:name], 31)+"]"
puts "Not Found"
puts
next
end
get_pkg_info(p)
get_commits(p)
show_output(p)
end