remote_cp 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -4
- data/bin/rt +20 -12
- data/lib/remote_cp/version.rb +1 -1
- metadata +4 -5
- data/lib/rt +0 -103
data/README.md
CHANGED
@@ -7,11 +7,11 @@ Install the gem
|
|
7
7
|
|
8
8
|
$ gem install remote_cp
|
9
9
|
|
10
|
-
|
10
|
+
Setup your remote cp by editing ~/.remote_cp.yml config file:
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
:access_key_id: MY_ACCESS_KEY
|
13
|
+
:secret_access_key: MY_SECRET
|
14
|
+
:bucket_name: MY_BUCKET_NAME
|
15
15
|
##Usage
|
16
16
|
To copy a file to the remote clipboard:
|
17
17
|
|
data/bin/rt
CHANGED
@@ -4,6 +4,7 @@ require 'zlib'
|
|
4
4
|
require 'archive/tar/minitar'
|
5
5
|
require 'thor'
|
6
6
|
require 'aws/s3'
|
7
|
+
require 'yaml'
|
7
8
|
|
8
9
|
class RemoteCp < Thor
|
9
10
|
include Archive::Tar
|
@@ -11,8 +12,8 @@ class RemoteCp < Thor
|
|
11
12
|
|
12
13
|
def initialize(*args)
|
13
14
|
AWS::S3::Base.establish_connection!(
|
14
|
-
:access_key_id =>
|
15
|
-
:secret_access_key =>
|
15
|
+
:access_key_id => config[:access_key_id],
|
16
|
+
:secret_access_key => config[:secret_access_key]
|
16
17
|
)
|
17
18
|
super
|
18
19
|
end
|
@@ -82,17 +83,8 @@ class RemoteCp < Thor
|
|
82
83
|
end
|
83
84
|
|
84
85
|
private
|
85
|
-
def s3_connect
|
86
|
-
require 'aws/s3'
|
87
|
-
include AWS::S3
|
88
|
-
AWS::S3::Base.establish_connection!(
|
89
|
-
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
|
90
|
-
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
|
91
|
-
)
|
92
|
-
end
|
93
|
-
|
94
86
|
def bucket_name
|
95
|
-
|
87
|
+
config[:bucket_name]
|
96
88
|
end
|
97
89
|
|
98
90
|
def filename
|
@@ -102,6 +94,22 @@ private
|
|
102
94
|
def rm_content
|
103
95
|
S3Object.find('content', bucket_name).value
|
104
96
|
end
|
97
|
+
|
98
|
+
def config
|
99
|
+
config_filename = File.join(ENV["HOME"], ".remote_cp.yml")
|
100
|
+
|
101
|
+
@config ||= if File.exist?(config_filename)
|
102
|
+
conf = Hash.new {|key, val| raise "Missing key #{key} in config file: #{config_filename}"}
|
103
|
+
conf.replace(YAML::load_file(config_filename))
|
104
|
+
else
|
105
|
+
config = {:access_key_id => "MY_ACCESS_KEY", :secret_access_key => "MY_SECRET", :bucket_name => "MY_BUCKET_NAME"}
|
106
|
+
File.open(config_filename, "w") do |f|
|
107
|
+
f << YAML::dump(config)
|
108
|
+
end
|
109
|
+
File.chmod(0600, config_filename)
|
110
|
+
raise "Please setup your .remote_cp.yml config file in you home dir."
|
111
|
+
end
|
112
|
+
end
|
105
113
|
end
|
106
114
|
|
107
115
|
RemoteCp.start
|
data/lib/remote_cp/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_cp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Martin Chabot
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-27 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- bin/rt
|
81
81
|
- lib/remote_cp.rb
|
82
82
|
- lib/remote_cp/version.rb
|
83
|
-
- lib/rt
|
84
83
|
- remote_cp.gemspec
|
85
84
|
has_rdoc: true
|
86
85
|
homepage: http://github.com/martinos/remote_cp
|
data/lib/rt
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'rubygems'
|
3
|
-
require 'zlib'
|
4
|
-
require 'archive/tar/minitar'
|
5
|
-
require 'thor'
|
6
|
-
require 'aws/s3'
|
7
|
-
|
8
|
-
class RemoteCp < Thor
|
9
|
-
include Archive::Tar
|
10
|
-
include AWS::S3
|
11
|
-
|
12
|
-
def initialize(*args)
|
13
|
-
AWS::S3::Base.establish_connection!(
|
14
|
-
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
|
15
|
-
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
|
16
|
-
)
|
17
|
-
super
|
18
|
-
end
|
19
|
-
|
20
|
-
desc "cp [FILENAME]", "copy FILENAME to the cloudi. If FILENAME not given send STDIN to the cloud"
|
21
|
-
def cp(filename = nil)
|
22
|
-
type = nil
|
23
|
-
content_type = nil
|
24
|
-
|
25
|
-
content = if filename.nil?
|
26
|
-
basename = "anonymous"
|
27
|
-
$stdin.read
|
28
|
-
else
|
29
|
-
full_path = File.expand_path(filename)
|
30
|
-
basename = File.basename(full_path)
|
31
|
-
if File.directory?(full_path)
|
32
|
-
content_type = "application/gzip"
|
33
|
-
io = StringIO.new("")
|
34
|
-
tgz = Zlib::GzipWriter.new(io)
|
35
|
-
Minitar.pack(basename, tgz)
|
36
|
-
type = 'directory'
|
37
|
-
io.rewind
|
38
|
-
io.string
|
39
|
-
else
|
40
|
-
type = 'file'
|
41
|
-
File.open(full_path)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# I think that all this info should be included file's metadata
|
46
|
-
S3Object.store("file_name.txt", basename, 'RemoteClipboard')
|
47
|
-
S3Object.store("content", content, 'RemoteClipboard', :content_type => content_type)
|
48
|
-
S3Object.store("type", type, 'RemoteClipboard')
|
49
|
-
end
|
50
|
-
|
51
|
-
desc "p", "paste from the cloud to current dir"
|
52
|
-
def p
|
53
|
-
file_name = S3Object.find("file_name.txt", 'RemoteClipboard').value
|
54
|
-
type = S3Object.find("type", 'RemoteClipboard').value
|
55
|
-
|
56
|
-
if File.exist?(file_name)
|
57
|
-
puts "#{file_name} already exist."
|
58
|
-
print "Do you want to replace it (y/n)? "
|
59
|
-
res = $stdin.gets.chomp
|
60
|
-
return unless res == "y"
|
61
|
-
end
|
62
|
-
|
63
|
-
content = S3Object.find('content', 'RemoteClipboard').value
|
64
|
-
case type
|
65
|
-
when 'file'
|
66
|
-
File.open(file_name, "w+") {|f| f << content}
|
67
|
-
puts "#{file_name} copied."
|
68
|
-
when 'directory'
|
69
|
-
tgz = Zlib::GzipReader.new(StringIO.new(content))
|
70
|
-
Minitar.unpack(tgz, ".")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
desc "fn", "Returns the file name of the copied file"
|
75
|
-
def fn
|
76
|
-
rm_filename
|
77
|
-
end
|
78
|
-
|
79
|
-
desc "cat", "Dump the copied file to stdout"
|
80
|
-
def cat
|
81
|
-
rm_content
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
def s3_connect
|
86
|
-
require 'aws/s3'
|
87
|
-
include AWS::S3
|
88
|
-
AWS::S3::Base.establish_connection!(
|
89
|
-
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
|
90
|
-
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
|
91
|
-
)
|
92
|
-
end
|
93
|
-
|
94
|
-
def filename
|
95
|
-
S3Object.find("file_name.txt", 'RemoteClipboard').value
|
96
|
-
end
|
97
|
-
|
98
|
-
def rm_content
|
99
|
-
S3Object.find( 'content', 'RemoteClipboard').value
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
RemoteCp.start
|