Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 22667 Details for
Bug 36509
Automatic "watcher" script
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
gentoo-watch
gentoo-watch (text/plain), 7.02 KB, created by
Tom Payne (RETIRED)
on 2003-12-26 02:51:54 UTC
(
hide
)
Description:
gentoo-watch
Filename:
MIME Type:
Creator:
Tom Payne (RETIRED)
Created:
2003-12-26 02:51:54 UTC
Size:
7.02 KB
patch
obsolete
>#!/usr/bin/ruby > >require "open-uri" >require "optparse" >require "thread" >require "syck" > >module URI > > class Mirror < Generic > > COMPONENT = [ > :scheme, > :host, > :path > ].freeze > > def self.build(arg) > super(Util::make_components_hash(self, arg)) > end > > def initialize(*args) > super(*args) > end > > end > > @@schemes['Mirror'] = Mirror > >end > >class Version > > VERSION_REGEXP = /(\d+(?:\.\d+)*)/ > LETTER_REGEXP = /([A-Za-z])?/ > SUFFIX_VALUE = { "alpha" => -4, "beta" => -3, "pre" => -2, "rc" => -1, nil => 0, "p" => 1 } > CANONICAL_SUFFIX = { "preview" => "pre", "" => "p", "pl" => "p" } > SUFFIX_REGEXP = /(?:[\-_]?(#{SUFFIX_VALUE.keys.delete_if { |k| k.nil? or k.empty? }.join('|')})?(\d+)?)?/ > EBUILD_SUFFIX_REGEXP = /(?:_(alpha|beta|pre|rc|p)(\d+)?)?/ > REVISION_REGEXP = /(?:-r\d+)?/ > > attr_reader(:version, :letter, :suffix, :suffix_version) > > def initialize(version, letter = nil, suffix = nil, suffix_version = nil) > @version = version.split(/\D+/).collect { |s| s.to_i }.extend(Comparable) > @letter = letter > @suffix = suffix.nil? && !suffix_version.nil? ? "p" : (CANONICAL_SUFFIX[suffix] || suffix) > @suffix_version = suffix_version > end > > def <=>(other) > result = @version <=> other.version > return result if result.nonzero? > [[@letter, other.letter], [SUFFIX_VALUE[@suffix], SUFFIX_VALUE[other.suffix]], [@suffix_version, other.suffix_version]].each do |left, right| > case (left ? 2 : 0) | (right ? 1 : 0) > when 1 > return -1 > when 2 > return 1 > when 3 > result = left <=> right > return result if result.nonzero? > end > end > 0 > end > > def to_s > s = @version.join(".") > s << @letter unless @letter.nil? > if @suffix or @suffix_version > s << "_" > s << @suffix unless @suffix.nil? > s << @suffix_version unless @suffix_version.nil? > end > s > end > > include Comparable > > def Version.ebuild(name) > match = /#{VERSION_REGEXP}#{LETTER_REGEXP}#{EBUILD_SUFFIX_REGEXP}#{REVISION_REGEXP}\.ebuild\z/.match(name) > return nil if match.nil? > Version.new(*match[1..-1]) > end > >end > >def scan(portdir, key, options) > > category, name = key.split("/", 2) > options ||= {} > > # Find the most recent ebuild > ebuild_filename = ebuild_version = nil > Dir.entries(File.join(portdir, key)).each do |filename| > version = Version.ebuild(filename) > next if version.nil? > if ebuild_version.nil? or version > ebuild_version > ebuild_filename = filename > ebuild_version = version > end > end > > # Determine the uri to scan: > # 1. If the user has specified a uri, use it. > # 2. Otherwise, use the homepage or src_uri in the ebuild. > uri = nil > if options.has_key?("uri") > uri = URI.parse(options["uri"]) > else > > homepage_uri = src_uri = nil > IO.popen("python -c \"import portage; print '\\n'.join(portage.portdb.aux_get('#{category}/#{ebuild_filename.sub(/\.ebuild\z/, '')}', ['HOMEPAGE', 'SRC_URI']))\"") do |pipe| > homepage_uri = URI.parse(pipe.gets.chomp) > src_uri = URI.parse(pipe.gets.split(/\s+/)[0]) > end > > # Determine if the project is hosted on Sourceforge > if options.has_key?("sourceforge-project") > sourceforge_project = options["sourceforge-project"] > elsif /\.sourceforge\.net\z/ =~ homepage_uri.host > sourceforge_project = homepage_uri.host.split(".")[0] > elsif src_uri.scheme == "mirror" && src_uri.host == "sourceforge" > sourceforge_project = src_uri.path.split("/")[1] > else > sourceforge_project = false > end > > if sourceforge_project > # Scan the project's Sourceforge page to determine the files page > project_uri = URI.parse("http://sourceforge.net/projects/#{sourceforge_project}/") > project_uri.open do |stream| > match = /\/project\/showfiles.php\?group_id=\d+/.match(stream.read) > uri = URI.parse("http://sourceforge.net#{match.to_s}") > end > else > uri = homepage_uri > end > > end > > # Determine the regexp to use: > # 1. If the user has specified a regexp, use it. > # 2. Otherwise, if the user has specified a src regexp, use it to build a regexp. > # 3. Otherwise, if the user has specified a package name and/or extra basename, use it to build a regexp. > # 4. Otherwise, use the default regexp. > if options.has_key?("regexp") > regexp = Regexp.new(options["regexp"]) > else > if options.has_key?("src") > src = options["src"] > else > package_name = options["package-name"] || name.gsub(/[\-_]/, "[\-_]") > extra_basename = options["extra-basename"] || "" > src = /#{package_name}[\-_]#{Version::VERSION_REGEXP}#{Version::LETTER_REGEXP}#{Version::SUFFIX_REGEXP}#{extra_basename}(?:\.tar\.bz2|\.tar\.gz|\.tgz|\.zip)?/i > end > regexp = /<a\s+href\s*=\s*"[^"]*#{src}(?:\?[^"]*)?"[^>]*>/i > end > > # Determine the code block to convert the match object to a version: > # 1. If the user has specified a block, use it. > # 2. Otherwise, use no block. > if options.has_key?("block") > block = eval(options["block"]) > else > block = nil > end > > # Scan the uri and find the latest version > latest_version = nil > begin > uri.fragment = nil > uri.open do |file| > file.read.scan(regexp) do |match| > version = block.nil? ? Version.new(*match) : block.call(match) > latest_version = version if latest_version.nil? or version > latest_version > end > end > rescue > end > > [ebuild_version, latest_version] > >end > >def main > > config_file = File.join(ENV["HOME"], ".gentoo-watch.yaml") > format = "%-26s%12s%12s%8s\n" > only_new = false > threads = 4 > > ARGV.options do |options| > options.on("--help", "Help") { puts(options); exit } > options.on("--config-file", String, "Config file") { |config_file| } > options.on("--format=STRING", String, "Format string") { |format| } > options.on("--only-new", TrueClass, "Only list new packages") { |only_new| } > options.on("--threads=N", Integer, "Number of simultaneous threads") { |threads| } > options.parse! > end > > printf(format, "name", "portage", "available", "state") > > # Determine the portage directory > portdir = IO.popen("python -c 'import portage; print portage.portdb.root'").gets.chomp > > config = YAML::Syck::Parser.new({}).load(File.open(config_file)).to_a > config_mutex = Mutex.new > > (0...threads).collect do |i| > Thread.new do > loop do > key = options = nil > config_mutex.synchronize do > key, options = config.shift > end > break if key.nil? > if ARGV.empty? or ARGV.include?(key) > state = nil > begin > ebuild_version, latest_version = scan(portdir, key, options) > if latest_version.nil? > state = "?" > elsif ebuild_version < latest_version > state = "*" > elsif ebuild_version > latest_version > state = "!" > else > state = nil > end > rescue > state = "-" > end > printf(format, key, ebuild_version, latest_version, state) if !only_new or state > end > end > end > end.each do |thread| > thread.join > end > >end > >main if $0 == __FILE__
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 36509
: 22667 |
22668
|
38299