PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/pkgcl/pkgcl

https://bitbucket.org/kaendfinger/aur-mirror
Ruby | 162 lines | 135 code | 17 blank | 10 comment | 19 complexity | 48024a33b1453d20f5c8e8f969eb5655 MD5 | raw file
Possible License(s): LGPL-2.0, Unlicense, AGPL-1.0, BitTorrent-1.0, EPL-1.0, GPL-3.0, BSD-3-Clause, GPL-2.0, MIT, CC-BY-SA-3.0, BSD-2-Clause, MPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, JSON, AGPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0, LGPL-2.1, ISC, CC-BY-3.0, WTFPL, 0BSD, CC0-1.0, LGPL-3.0, Cube, Apache-2.0
  1. #!/usr/bin/env ruby
  2. # Author: Alex Brown
  3. # email: code@alexpbrown.me
  4. # license: WTFPL
  5. require 'nokogiri'
  6. require 'open-uri'
  7. require 'optparse'
  8. VERSION = "0.3.1"
  9. @options = {}
  10. @options[:commits] = 1
  11. @options[:show_git_svn] = false
  12. @options[:testing_repo] = false
  13. opts = OptionParser.new do |opts|
  14. opts.banner = "Usage: pkgcl [options] <packages>"
  15. opts.separator ""
  16. opts.on("-c", "--commits=NUM", Integer, "Show NUM commit messages") do |n|
  17. @options[:commits] = n
  18. end
  19. opts.on("--show-git-svn-id", "Show git-svn-id messages") do
  20. @options[:show_git_svn] = true
  21. end
  22. opts.on("--enable-testing", "Show commits relevant to packages in [testing]") do
  23. @options[:testing_repo] = true
  24. end
  25. opts.on("-v", "--version", "Show version information") do
  26. puts VERSION
  27. exit
  28. end
  29. opts.on_tail("-h", "--help", "Show this message") do
  30. puts opts
  31. exit
  32. end
  33. end
  34. opts.parse!(ARGV)
  35. # check for stdin and get package list accordingly
  36. # I even decided to be nice and parse both 'pacman -Qu' and 'pacman -Qqu' on stdin
  37. packages = []
  38. if STDIN.tty? == false
  39. ARGF.lines do |line|
  40. packages << {:name => line.strip!.split(" ")[0]}
  41. end
  42. else
  43. ARGV.each {|a| packages << {:name => a} }
  44. end
  45. puts opts if packages.empty?
  46. def colorize(text, color_code)
  47. "\e[#{color_code}m#{text}\e[0m"
  48. end
  49. def get_pkg(pkg)
  50. repo, arch = "", ""
  51. IO.popen([{"LC_ALL"=>"C"}, "pacman", "-Si", pkg[:name], :err => :close]) do |io|
  52. io.lines do |line|
  53. case line
  54. when /^Repository(\s?)*: (.+)$/
  55. pkg[:repo] = $2
  56. when /^Architecture(\s?)*: (.+)$/
  57. pkg[:arch] = $2
  58. when /^Build Date(\s?)*: (.+)$/
  59. build_date = Time.parse($2)
  60. if build_date.strftime("%F") == Time.now.strftime("%F")
  61. build_date = Time.now
  62. end
  63. pkg[:build_date] = build_date
  64. when /^$/
  65. break
  66. end
  67. end
  68. end
  69. end
  70. def get_pkg_info(pkg)
  71. # I need to get the correct git url from here, since some packages use a
  72. # different tracking repo (e.g. linux-headers => linux)
  73. # I'm also getting the last updated date from this url
  74. uri = "http://www.archlinux.org/packages/#{pkg[:repo]}/#{pkg[:arch]}/#{pkg[:name]}"
  75. doc = Nokogiri::HTML(open(uri))
  76. pkg[:git_url] = doc.css("div#actionlist ul li a")[1]['href']
  77. end
  78. def age_test(commit_age, pkg)
  79. case commit_age
  80. when /days/
  81. git_time = Time.now - commit_age.to_i*60*60*24
  82. when /hours/
  83. git_time = Time.now - commit_age.to_i*60*60
  84. when /min/
  85. git_time = Time.now - commit_age.to_i*60
  86. else
  87. git_time = Time.parse(commit_age)
  88. end
  89. if git_time > pkg[:build_date] then
  90. return false
  91. else
  92. return true
  93. end
  94. end
  95. def get_commits(pkg)
  96. pkg[:commits] = []
  97. doc = Nokogiri::HTML(open("#{pkg[:git_url]}&showmsg=1"))
  98. table = doc.css("table.list.nowrap")
  99. table.css("td.logsubject").each_with_index do |n,i|
  100. age = n.parent.children[0].content
  101. if @options[:testing_repo] == false then
  102. next if age_test(age, pkg) == false
  103. end
  104. commit = {}
  105. age+=" ago" if /(days|hours|min)/ === age
  106. commit[:age] = age
  107. commit[:subject] = n.content
  108. content = table.css("td.logmsg")[i].content
  109. content.gsub!(/^git-svn-id.*$/, "") unless @options[:show_git_svn] == true
  110. content.strip!
  111. commit[:msg] = content.empty? ? "None" : content
  112. pkg[:commits] << commit
  113. end
  114. end
  115. def show_output(pkg)
  116. # Format and print the result
  117. print "["+colorize(pkg[:name], 31)+"]"
  118. if pkg[:commits].count < @options[:commits]
  119. print colorize(" (Only #{pkg[:commits].count} commits)\n", 33)
  120. else
  121. print "\n"
  122. end
  123. output = 0
  124. pkg[:commits].each do |p|
  125. break if output == @options[:commits]
  126. puts colorize(p[:subject], 4)
  127. print colorize("Age: ", 37)
  128. print colorize(p[:age], 36)+" - "
  129. puts colorize(p[:msg], 32)
  130. puts
  131. output +=1
  132. end
  133. end
  134. packages.each do |p|
  135. get_pkg(p)
  136. if p.has_key?(:arch) == false && p.has_key?(:repo) == false
  137. puts "["+colorize(p[:name], 31)+"]"
  138. puts "Not Found"
  139. puts
  140. next
  141. end
  142. get_pkg_info(p)
  143. get_commits(p)
  144. show_output(p)
  145. end