sfget 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sfget +76 -0
- metadata +62 -0
data/bin/sfget
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'hpricot'
|
6
|
+
|
7
|
+
requested_package = ARGV[0]
|
8
|
+
requested_version = ARGV[1]
|
9
|
+
|
10
|
+
$stdout.puts "Downloading #{requested_package} #{requested_version ? "v#{requested_version}" : ''} from sourceforge.net"
|
11
|
+
|
12
|
+
project_page = "http://sourceforge.net/projects/#{requested_package}/"
|
13
|
+
|
14
|
+
data = open(project_page).read
|
15
|
+
|
16
|
+
SFRelease = Struct.new(:name, :version, :link)
|
17
|
+
|
18
|
+
if link = (Hpricot(data) / 'a[@href^=/project/showfiles.php]').first
|
19
|
+
data = open("http://sourceforge.net" + link['href'])
|
20
|
+
releases = (Hpricot(data) / 'table[@summary=Latest file listings]') / '/tbody/tr'
|
21
|
+
|
22
|
+
releases = releases.map do |release_row|
|
23
|
+
name = (release_row / 'td:first').inner_text
|
24
|
+
version = (release_row / 'td[2]').inner_text
|
25
|
+
link = "http://sourceforge.net" + (release_row / 'td[@class=download]').at('a')['href']
|
26
|
+
SFRelease.new(name, version, link)
|
27
|
+
end
|
28
|
+
|
29
|
+
release = releases.detect { |r| (r.name == requested_package) && (r.version == requested_version) }
|
30
|
+
|
31
|
+
if release.nil?
|
32
|
+
$stdout.puts "I coulnd't find the package you're looking for, are any of these what you're looking for?"
|
33
|
+
|
34
|
+
max_name_length = releases.inject(0) { |max, release| max = release.name.size if release.name.size > max; max }
|
35
|
+
max_version_length = releases.inject(0) { |max, release| max = release.version.size if release.version.size > max; max }
|
36
|
+
|
37
|
+
releases.each_with_index do |release, index|
|
38
|
+
puts "#{(index+1).to_s.rjust(2, ' ')}: #{release.name.ljust(max_name_length + 3, ' ')} - #{release.version}"
|
39
|
+
end
|
40
|
+
|
41
|
+
puts "#{'-' * (max_name_length + max_version_length + 10)}\n#{(releases.size + 1).to_s.rjust(2, ' ')}: Quit"
|
42
|
+
|
43
|
+
answer = ''
|
44
|
+
until (answer =~ /^(\d+)$/) && ($1.to_i <= (releases.size + 1))
|
45
|
+
$stdout << "Choose Package: "
|
46
|
+
answer = $stdin.readline
|
47
|
+
end
|
48
|
+
|
49
|
+
if answer.to_i < (releases.size + 1)
|
50
|
+
release = releases[answer.to_i - 1]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
exit(1) unless release
|
55
|
+
|
56
|
+
release_doc = Hpricot(open(release.link).read)
|
57
|
+
|
58
|
+
if download_url = (release_doc / 'a[@href^=http://downloads.sourceforge.net]').first['href']
|
59
|
+
download_uri = URI.parse(download_url)
|
60
|
+
download_url = download_uri.to_s.sub('?' + download_uri.query, '')
|
61
|
+
filename = File.basename(download_url)
|
62
|
+
|
63
|
+
`curl -s -L -C - -O "#{download_url}"`
|
64
|
+
|
65
|
+
if File.exists?(filename)
|
66
|
+
puts "Downloaded #{filename}"
|
67
|
+
else
|
68
|
+
puts "Failed to download"
|
69
|
+
end
|
70
|
+
else
|
71
|
+
puts "Couldn't find the download link"
|
72
|
+
end
|
73
|
+
|
74
|
+
else
|
75
|
+
$stderr << "Couldn't find Project Group Id on #{project_page}"
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sfget
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-19 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.6"
|
24
|
+
version:
|
25
|
+
description: Bypass Sourceforge.net's website to get the package you need
|
26
|
+
email: bauer.mail@gmail.com
|
27
|
+
executables:
|
28
|
+
- sfget
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files: []
|
34
|
+
|
35
|
+
has_rdoc: false
|
36
|
+
homepage:
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.2.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: Bypass Sourceforge.net's website to get the package you need
|
61
|
+
test_files: []
|
62
|
+
|