desi 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -31,6 +31,21 @@ It can be used both as a command-line tool and as a library.
31
31
 
32
32
  ## Examples (command-line and Ruby)
33
33
 
34
+ ### Installing Elastic Search
35
+
36
+ ```bash
37
+ $ # The latest version will be installed by default
38
+ $ desi install
39
+ * No release specified, will fetch latest.
40
+ * fetching release elasticsearch-0.19.9.tar.gz
41
+ […]
42
+
43
+ $ # You can also give a specific release name
44
+ $ desi install 0.19.6 # ("v0.19.6" or "elasticsearch-0.19.6" would also work)
45
+ * fetching release elasticsearch-0.19.6.tar.gz
46
+ […]
47
+ ```
48
+
34
49
  ### Get the list of locally installed releases
35
50
 
36
51
  The current version is the one symlinked to `$HOME/elasticsearch/current`, that
@@ -16,8 +16,8 @@ module Desi
16
16
  end
17
17
 
18
18
  def download!(version, opts = {})
19
- path = "/downloads/elasticsearch/elasticsearch/#{version.name}"
20
- destination_name = @destination_dir.join File.basename(version.name)
19
+ path = "/downloads/elasticsearch/elasticsearch/#{version.archive_name}"
20
+ destination_name = @destination_dir.join File.basename(version.archive_name)
21
21
 
22
22
  raise "ERROR: File #{destination_name} already present!" if destination_name.exist?
23
23
 
@@ -8,8 +8,8 @@ module Desi
8
8
 
9
9
  class HttpClient
10
10
 
11
- def initialize(host_string)
12
- @uri = to_uri(host_string)
11
+ def initialize(host)
12
+ @uri = to_uri(host)
13
13
 
14
14
  case @uri.scheme
15
15
  when 'https'
@@ -52,15 +52,8 @@ module Desi
52
52
  private
53
53
 
54
54
  def to_uri(host_string)
55
- scheme, host, port = ['http', '127.0.0.1', 9200]
56
-
57
- %r{(?<scheme>(https?|))(?:\:\/\/|)(?<host>[^:]*?):?(?<port>\d*)/?$}.match(host_string) do |m|
58
- scheme = m[:scheme] unless m[:scheme].empty?
59
- host = m[:host] unless m[:host].empty?
60
- port = m[:port] unless m[:port].empty?
61
- end
62
-
63
- Addressable::URI.new(scheme: scheme, host: host, port: port)
55
+ host_string = "http://#{host_string}" unless host_string.to_s =~ %r[^https?://]
56
+ URI(host_string)
64
57
  end
65
58
  end
66
59
 
@@ -24,7 +24,7 @@ module Desi
24
24
  #
25
25
  # @api public
26
26
  def initialize(opts = {})
27
- @host = opts.fetch(:host, 'http://127.0.0.1:9200')
27
+ @host = to_uri(opts.fetch(:host, 'http://127.0.0.1:9200'))
28
28
  @verbose = opts[:verbose]
29
29
  @outputter = opts.fetch(:outputter, Kernel)
30
30
  @client = opts.fetch(:http_client_factory, Desi::HttpClient).new(@host)
@@ -115,5 +115,17 @@ module Desi
115
115
  }
116
116
  end
117
117
 
118
+ def to_uri(host_string)
119
+ scheme, host, port = ['http', '127.0.0.1', 9200]
120
+
121
+ %r{(?<scheme>(https?|))(?:\:\/\/|)(?<host>[^:]*?):?(?<port>\d*)/?$}.match(host_string.to_s) do |m|
122
+ scheme = m[:scheme] unless m[:scheme].empty?
123
+ host = m[:host] unless m[:host].empty?
124
+ port = m[:port] unless m[:port].empty?
125
+ end
126
+
127
+ "#{scheme}://#{host}:#{port}"
128
+ end
129
+
118
130
  end
119
131
  end
@@ -9,13 +9,14 @@ module Desi
9
9
  def initialize(archive, opts = {})
10
10
  @verbose = opts[:verbose]
11
11
  @archive = archive.to_s
12
- @local_install = Desi::LocalInstall.new(opts[:destination_dir])
12
+ @local_install = Desi::LocalInstall.new(opts[:destination_dir], verbose: @verbose)
13
13
  end
14
14
 
15
15
  def install!
16
16
  extract! unless extracted?
17
17
  install_config_file
18
18
  update_symlink!
19
+ remove_archive!
19
20
  end
20
21
 
21
22
  def extracted?
@@ -32,13 +33,7 @@ module Desi
32
33
 
33
34
 
34
35
  def update_symlink!
35
- unless @local_install.current_dir.symlink?
36
- raise "Mmmm!! #{@local_install.current_dir} is not a symlink!"
37
- end
38
-
39
- puts " * Updating #{@local_install.current_dir} symlink" if @verbose
40
- FileUtils.remove(@local_install.current_dir)
41
- FileUtils.ln_sf(release_dir, @local_install.current_dir)
36
+ @local_install.update_current_to(release_dir)
42
37
  end
43
38
 
44
39
  def config_file
@@ -67,6 +62,10 @@ module Desi
67
62
  end
68
63
  end
69
64
 
65
+ def remove_archive!
66
+ FileUtils.rm @archive
67
+ end
68
+
70
69
  def release_dir
71
70
  @release_dir ||= Pathname(@local_install).join(File.basename(@archive, '.tar.gz'))
72
71
  end
@@ -51,8 +51,10 @@ module Desi
51
51
  end
52
52
  end
53
53
 
54
- def initialize(workdir = nil)
54
+ def initialize(workdir = nil, opts = {})
55
+ @verbose = opts[:verbose]
55
56
  @workdir = Pathname(File.expand_path(workdir || DEFAULT_DIR))
57
+ create!
56
58
  end
57
59
 
58
60
  def exists?
@@ -63,6 +65,14 @@ module Desi
63
65
  @workdir.join('current')
64
66
  end
65
67
 
68
+ def update_current_to(release_dir)
69
+ current_dir_must_be_nil_or_symlink!
70
+
71
+ puts " * Updating #{@local_install.current_dir} symlink" if @verbose
72
+ FileUtils.remove(current_dir) if current_dir.exist?
73
+ FileUtils.ln_sf(release_dir, current_dir)
74
+ end
75
+
66
76
  def create!
67
77
  FileUtils.mkdir_p @workdir
68
78
  end
@@ -86,5 +96,13 @@ module Desi
86
96
  def launcher
87
97
  current_dir.join('bin', 'elasticsearch')
88
98
  end
99
+
100
+ private
101
+
102
+ def current_dir_must_be_nil_or_symlink!
103
+ if current_dir.exist? && ! current_dir.symlink?
104
+ raise "Mmmm!! #{current_dir} is not a symlink!"
105
+ end
106
+ end
89
107
  end
90
108
  end
data/lib/desi/upstream.rb CHANGED
@@ -6,9 +6,21 @@ require "json"
6
6
  module Desi
7
7
  class Upstream
8
8
 
9
- class Release < Struct.new(:name, :description, :release_date, :download_url)
9
+ class Release < Struct.new(:archive_name, :description, :release_date, :download_url)
10
10
  def to_s
11
- self.name
11
+ archive_name
12
+ end
13
+
14
+ def name
15
+ @name ||= archive_name.scan(/^(elasticsearch-.*?)\.tar\.gz$/).flatten.first
16
+ end
17
+
18
+ def version
19
+ @version ||= archive_name.scan(/^elasticsearch-(.*?)\.tar\.gz$/).flatten.first
20
+ end
21
+
22
+ def ===(name_or_version)
23
+ name_or_version == version || name_or_version == name || name_or_version == "v#{version}"
12
24
  end
13
25
  end
14
26
 
@@ -27,8 +39,8 @@ module Desi
27
39
  releases.first
28
40
  end
29
41
 
30
- def find_release(name)
31
- releases.detect {|r| r.name == name || r.version == name }
42
+ def find_release(name_or_version)
43
+ releases.detect {|r| r === name_or_version }
32
44
  end
33
45
 
34
46
  private
data/lib/desi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Desi
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -125,9 +125,9 @@ describe Desi::IndexManager do
125
125
  let(:factory_for_remote_host) { double("http_client_factory") }
126
126
 
127
127
  it "sends the other host's url to initialize the client" do
128
- factory_for_remote_host.should_receive(:new).with("http://foobar.com")
128
+ factory_for_remote_host.should_receive(:new).with("http://foobar.com:9400")
129
129
 
130
- described_class.new(host: "http://foobar.com", http_client_factory: factory_for_remote_host)
130
+ described_class.new(host: "http://foobar.com:9400", http_client_factory: factory_for_remote_host)
131
131
  end
132
132
  end
133
133
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: desi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-27 00:00:00.000000000 Z
12
+ date: 2012-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: boson
@@ -206,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  segments:
208
208
  - 0
209
- hash: 3454323007955509059
209
+ hash: 65546366130698177
210
210
  required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  none: false
212
212
  requirements:
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  version: '0'
216
216
  segments:
217
217
  - 0
218
- hash: 3454323007955509059
218
+ hash: 65546366130698177
219
219
  requirements: []
220
220
  rubyforge_project:
221
221
  rubygems_version: 1.8.24