daps 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- daps(7) -- semi automatic deployment of rails applications
2
- ===============================================================
1
+ daps(7) -- Like taps but for data files
2
+ =======================================
3
3
 
4
4
  ## INSTALL
5
5
 
6
6
  Install with Rubygems:
7
7
 
8
8
  $ [sudo] gem install daps
9
- $ dapsd
9
+ $ daps
@@ -1,14 +1,15 @@
1
1
  class Daps::Client
2
2
 
3
+ require 'fileutils'
4
+
3
5
  def initialize(dir, remote, token, port)
4
6
  @dir, @remote, @token, @port = File.expand_path(dir), remote, token, port
5
7
  end
6
8
 
7
9
  def start!
10
+ FileUtils.mkdir_p(@dir)
8
11
  system(%{
9
- wget -T 600 -O /tmp/daps-#{@token}-client.tar.gz http://#{@remote}:#{@port}/#{@token} &&
10
- tar --directory=#{@dir} -xzf /tmp/daps-#{@token}-client.tar.gz ;
11
- rm -f /tmp/daps-#{@token}-client.tar.gz
12
+ curl http://#{@remote}:#{@port}/#{@token} | tar --directory=#{@dir} -xzf -
12
13
  })
13
14
  end
14
15
 
@@ -22,59 +22,68 @@ class Daps::Server
22
22
  end
23
23
 
24
24
  class ArchiveStreamer < Cramp::Controller::Action
25
- before_start :verify_token, :build_archive
26
- on_start :prepare_stream
25
+ before_start :verify_token
26
+ on_start :open_stream
27
27
  on_finish :terminate
28
28
 
29
+ @@activated = false
30
+
29
31
  def verify_token
30
32
  @token = File.basename(@env['PATH_INFO'])
31
- if @env['daps.token'] != @token
32
- halt 403, {}, 'back off!!'
33
+ if @env['daps.token'] != @token or @@activated
34
+ halt 403, {'Content-Type' => 'text/html'}, 'back off!!'
33
35
  else
36
+ @@activated = true
34
37
  yield
35
38
  end
36
39
  end
37
40
 
38
- def build_archive
39
- puts "Compressing files..."
40
- system(%{
41
- cd #{@env['daps.dir']} ;
42
- tar -czf /tmp/daps-#{@token}-server.tar.gz . ;
43
- })
44
-
45
- @length = File.size("/tmp/daps-#{@token}-server.tar.gz")
46
- @archive = File.open("/tmp/daps-#{@token}-server.tar.gz")
47
-
48
- yield
49
- end
50
-
51
41
  def respond_with
52
- [200, {'Content-Type' => 'text/html', 'Content-Length' => @length.to_s}]
42
+ [200, {'Content-Type' => 'application/x-gzip', 'Transfer-Encoding' => 'chunked'}]
53
43
  end
54
44
 
55
- def prepare_stream
45
+ def open_stream
56
46
  puts "Transferring archive..."
57
- stream_chunks
58
- end
59
-
60
- def stream_chunks
61
- if data = @archive.read(1024 * 156)
62
- render data
63
- EM.add_timer(0.01) { stream_chunks }
64
- else
65
- finish
66
- end
47
+ @pipe = EM.popen('tar -czf - .', Daps::Server::Pipe, self)
67
48
  end
68
49
 
69
50
  def terminate
51
+ @pipe.terminate if @pipe
70
52
  EM.next_tick {
71
53
  if @env['daps.token'] == @token
72
- File.unlink("/tmp/daps-#{@token}-server.tar.gz")
73
54
  EM.stop_event_loop
74
55
  end
75
56
  }
76
57
  end
77
58
 
59
+ def render(data)
60
+ term = "\r\n"
61
+ size = Rack::Utils.bytesize(data)
62
+ super([size.to_s(16), term, data, term].join)
63
+ end
64
+
65
+ end
66
+
67
+ module Pipe
68
+
69
+ def initialize(connection)
70
+ @connection = connection
71
+ # super
72
+ end
73
+
74
+ def receive_data(data)
75
+ @connection.render data
76
+ end
77
+
78
+ def unbind
79
+ @connection.render('')
80
+ EM.next_tick{ @connection.finish }
81
+ end
82
+
83
+ def terminate
84
+ Process.kill('INT', get_pid) rescue nil
85
+ end
86
+
78
87
  end
79
88
 
80
89
  end
@@ -1,3 +1,3 @@
1
1
  module Daps
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daps
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Menke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-15 00:00:00 +02:00
18
+ date: 2010-06-16 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.13.6
66
66
  type: :runtime
67
67
  version_requirements: *id003
68
- description: Ad hoc rsync server.
68
+ description: Like taps but for files.
69
69
  email:
70
70
  - simon.menke@gmail.com
71
71
  executables:
@@ -118,6 +118,6 @@ rubyforge_project: daps
118
118
  rubygems_version: 1.3.7
119
119
  signing_key:
120
120
  specification_version: 3
121
- summary: Ad hoc rsync server
121
+ summary: Like taps but for files
122
122
  test_files: []
123
123