From db63966873ab68753c3a12e1426e6573daa09ce5 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Tue, 24 Jul 2007 20:35:02 +0000 Subject: [PATCH] initial --- listversioned/listversioned.rb | 143 +++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100755 listversioned/listversioned.rb diff --git a/listversioned/listversioned.rb b/listversioned/listversioned.rb new file mode 100755 index 0000000..19afe7d --- /dev/null +++ b/listversioned/listversioned.rb @@ -0,0 +1,143 @@ +#!/usr/bin/env ruby + +# $Id$ +# $URL$ + +# +# Copyright (c) 2007 Ward Wouts +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +require 'net/https' +require 'uri' +require 'rexml/document' +require 'date' +require 'getoptlong' + +def usage + puts < + +-h, --help show this message +-u set baseurl +EOT + exit +end + +def cmdline + options = Hash.new + begin + opts = GetoptLong.new( + [ "-h", "--help", GetoptLong::NO_ARGUMENT ], + [ "-u", GetoptLong::REQUIRED_ARGUMENT ] + ) + opts.quiet=true + + opts.each do |opt, arg| + options[opt] = arg + end + + rescue + print "#{$!}\n" + usage + end + if options["-h"] + usage + end + return options +end + +def fetch(uri_str, limit = 10) + # You should choose better exception. + raise ArgumentError, 'HTTP redirect too deep' if limit == 0 + + host = URI.parse(uri_str).host + path = URI.parse(uri_str).path + query = URI.parse(uri_str).query + + Net::HTTP.start(host) {|http| + req = Net::HTTP::Get.new("#{path}?#{query}") + req.basic_auth @user, @pass + response = http.request(req) + case response + when Net::HTTPSuccess then response + when Net::HTTPRedirection then fetch(response['location'], limit - 1) + when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"; response.error! + when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"; response.error! + else + response.error! + end + } +end + +def svnparse(url) + puts "\n#{url}" + begin + body = fetch("#{url}/.svn/entries").body + rescue + end + dirs = Array.new + xmldoc = REXML::Document.new(body) + xmldoc.elements.each("wc-entries/entry") {|item| + case item.attribute("kind").to_s + when "dir" then + if item.attribute("name").to_s == "" + next + end + puts "#{item.attribute("name")}/" + dirs.push(item.attribute("name").to_s) + when "file" then + puts "#{item.attribute("name")} #{item.attribute("last-author")} #{item.attribute("committed-date")}" + else + puts " Strange kind #{item.attribute("kind")}" + end + } + dirs.each{|dir| + svnparse("#{url}/#{dir}") + } +end + +options = cmdline +if options["-u"].nil? + usage +end + +mode=nil + +# first test for subversion entries +if mode.nil? + begin + body = fetch("#{options["-u"]}/.svn/entries").body + mode="subversion" + rescue + end +end + +# then test for CVS entries +if mode.nil? + begin + body = fetch("#{options["-u"]}/CVS/Entries").body + mode="cvs" + rescue + end +end + +if mode.nil? + puts "Couldn't determine versioning information" +else + case mode + when "subversion" then svnparse(options["-u"]) + when "cvs" then cvsparse(options["-u"]) + end +end