geminabox_command 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ = Gem command inabox for geminabox
2
+
3
+ Source[https://github.com/neopoly/geminabox_command]
4
+
5
+ Here's the original +geminabox+ gem including hosting server:
6
+
7
+ https://github.com/cwninja/geminabox
8
+
9
+ == Description
10
+
11
+ This fork contains only the gem command <tt>gem inabox</tt> *without* the server part.
12
+
13
+ == Why forking?
14
+
15
+ <tt>geminabox</tt> is great but has too many dependencies when you don't want to run the geminabox server.
16
+
17
+ == Installation and usage
18
+
19
+ gem install geminabox_command
20
+ gem inabox --help
21
+
22
+ == Licence
23
+
24
+ Fork it, mod it, choose it, use it, make it better. All under the do what the fuck you want to + beer/pizza public license[http://tomlea.co.uk/WTFBPPL.txt].
@@ -0,0 +1,161 @@
1
+ require 'uri'
2
+ require 'yaml'
3
+
4
+ class Gem::Commands::InaboxCommand < Gem::Command
5
+ def description
6
+ 'Push a gem up to your GemInABox'
7
+ end
8
+
9
+ def arguments
10
+ "GEM built gem to push up"
11
+ end
12
+
13
+ def usage
14
+ "#{program_name} GEM"
15
+ end
16
+
17
+ def initialize
18
+ super 'inabox', description
19
+
20
+ add_option('-c', '--configure', "Configure GemInABox") do |value, options|
21
+ options[:configure] = true
22
+ end
23
+
24
+ add_option('-g', '--host HOST', "Host to upload to.") do |value, options|
25
+ options[:host] = value
26
+ end
27
+ end
28
+
29
+ def execute
30
+ return configure if options[:configure]
31
+ setup
32
+ send_gem
33
+ end
34
+
35
+ def setup
36
+ @gemfile = if options[:args].size == 0
37
+ find_gem
38
+ else
39
+ get_one_gem_name
40
+ end
41
+ configure unless geminabox_host
42
+ end
43
+
44
+ def find_gem
45
+ say "You didn't specify a gem, looking for one in pkg..."
46
+ path, directory = File.split(Dir.pwd)
47
+ possible_gems = Dir.glob("pkg/#{directory}-*.gem")
48
+ raise Gem::CommandLineError, "Couldn't find a gem in pkg, please specify a gem name on the command line (e.g. gem inabox GEMNAME)" unless possible_gems.any?
49
+ name_regexp = Regexp.new("^pkg/#{directory}-")
50
+ possible_gems.sort_by{ |a| Gem::Version.new(a.sub(name_regexp,'')) }.last
51
+ end
52
+
53
+ def send_gem
54
+ # sanitize printed URL if a password is present
55
+ url = URI.parse(geminabox_host)
56
+ url_for_presentation = url.clone
57
+ url_for_presentation.password = '***' if url_for_presentation.password
58
+
59
+ say "Pushing #{File.split(@gemfile).last} to #{url_for_presentation}..."
60
+
61
+ File.open(@gemfile, "rb") do |file|
62
+ request_body, request_headers = Multipart::MultipartPost.new.prepare_query("file" => file)
63
+
64
+ proxy.start(url.host, url.port) {|con|
65
+ req = Net::HTTP::Post.new('/upload', request_headers)
66
+ req.basic_auth(url.user, url.password) if url.user
67
+ handle_response(con.request(req, request_body))
68
+ }
69
+ end
70
+ end
71
+
72
+ def proxy
73
+ if proxy_info = ENV['http_proxy'] || ENV['HTTP_PROXY'] and uri = URI.parse(proxy_info)
74
+ Net::HTTP::Proxy(uri.host, uri.port, uri.user, uri.password)
75
+ else
76
+ Net::HTTP
77
+ end
78
+ end
79
+
80
+ def handle_response(response)
81
+ case response
82
+ when Net::HTTPSuccess, Net::HTTPRedirection
83
+ puts response.body
84
+ else
85
+ response.error!
86
+ end
87
+ end
88
+
89
+ def config_path
90
+ File.join(Gem.user_home, '.gem', 'geminabox')
91
+ end
92
+
93
+ def configure
94
+ say "Enter the root url for your personal geminabox instance. (E.g. http://gems/)"
95
+ host = ask("Host:")
96
+ self.geminabox_host = host
97
+ end
98
+
99
+ def geminabox_host
100
+ @geminabox_host ||= options[:host] || Gem.configuration.load_file(config_path)[:host]
101
+ end
102
+
103
+ def geminabox_host=(host)
104
+ config = Gem.configuration.load_file(config_path).merge(:host => host)
105
+
106
+ dirname = File.dirname(config_path)
107
+ Dir.mkdir(dirname) unless File.exists?(dirname)
108
+
109
+ File.open(config_path, 'w') do |f|
110
+ f.write config.to_yaml
111
+ end
112
+ end
113
+
114
+ module Multipart
115
+ require 'net/http'
116
+ require 'cgi'
117
+
118
+ class Param
119
+ attr_accessor :k, :v
120
+ def initialize( k, v )
121
+ @k = k
122
+ @v = v
123
+ end
124
+
125
+ def to_multipart
126
+ return "Content-Disposition: form-data; name=\"#{k}\"\r\n\r\n#{v}\r\n"
127
+ end
128
+ end
129
+
130
+ class FileParam
131
+ attr_accessor :k, :filename, :content
132
+ def initialize( k, filename, content )
133
+ @k = k
134
+ @filename = filename
135
+ @content = content
136
+ end
137
+
138
+ def to_multipart
139
+ return "Content-Disposition: form-data; name=\"#{k}\"; filename=\"#{filename}\"\r\n" + "Content-Transfer-Encoding: binary\r\n" + "Content-Type: application/octet-stream\r\n\r\n" + content + "\r\n"
140
+ end
141
+ end
142
+
143
+ class MultipartPost
144
+ BOUNDARY = 'tarsiers-rule0000'
145
+ HEADER = {"Content-type" => "multipart/form-data, boundary=" + BOUNDARY + " "}
146
+
147
+ def prepare_query(params)
148
+ fp = []
149
+ params.each {|k,v|
150
+ if v.respond_to?(:read)
151
+ fp.push(FileParam.new(k, v.path, v.read))
152
+ else
153
+ fp.push(Param.new(k,v))
154
+ end
155
+ }
156
+ query = fp.collect {|p| "--" + BOUNDARY + "\r\n" + p.to_multipart }.join("") + "--" + BOUNDARY + "--"
157
+ return query, HEADER
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ require 'rubygems/command'
4
+ require 'rubygems/dependency'
5
+ require 'rubygems/version_option'
6
+
7
+ Gem::CommandManager.instance.register_command :inabox
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geminabox_command
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Tom Lea
14
+ - Peter Suschlik
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-05-26 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Provides the "gem inabox" command for geminabox server.
24
+ email: contrib@tomlea.co.uk
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - README.rdoc
31
+ files:
32
+ - README.rdoc
33
+ - lib/rubygems/commands/inabox_command.rb
34
+ - lib/rubygems_plugin.rb
35
+ has_rdoc: true
36
+ homepage: http://tomlea.co.uk/p/gem-in-a-box
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --main
42
+ - README.rdoc
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.6.2
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Gem command for really simple rubygem hosting.
70
+ test_files: []
71
+