remote_cp 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +7 -3
- data/bin/rt +20 -50
- data/lib/remote_cp/version.rb +1 -1
- data/lib/remote_cp.rb +74 -89
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
remote_cp (0.0.
|
4
|
+
remote_cp (0.0.8)
|
5
5
|
aws-s3
|
6
|
+
minitar
|
7
|
+
thor
|
6
8
|
|
7
9
|
GEM
|
8
10
|
remote: http://rubygems.org/
|
@@ -11,13 +13,15 @@ GEM
|
|
11
13
|
builder
|
12
14
|
mime-types
|
13
15
|
xml-simple
|
14
|
-
builder (
|
16
|
+
builder (3.0.0)
|
15
17
|
mime-types (1.16)
|
18
|
+
minitar (0.5.3)
|
19
|
+
thor (0.14.6)
|
16
20
|
xml-simple (1.0.12)
|
17
21
|
|
18
22
|
PLATFORMS
|
19
23
|
ruby
|
20
24
|
|
21
25
|
DEPENDENCIES
|
22
|
-
|
26
|
+
bundler (~> 1.0)
|
23
27
|
remote_cp!
|
data/bin/rt
CHANGED
@@ -5,22 +5,21 @@ require 'archive/tar/minitar'
|
|
5
5
|
require 'thor'
|
6
6
|
require 'aws/s3'
|
7
7
|
require 'yaml'
|
8
|
+
require 'remote_cp'
|
8
9
|
|
9
|
-
class
|
10
|
+
class Clipboard < Thor
|
10
11
|
include Archive::Tar
|
11
|
-
|
12
|
+
include AWS::S3
|
13
|
+
include RemoteCp
|
12
14
|
|
13
15
|
def initialize(*args)
|
14
|
-
|
15
|
-
:access_key_id => config[:access_key_id],
|
16
|
-
:secret_access_key => config[:secret_access_key]
|
17
|
-
)
|
16
|
+
@clipboard = Clipboard.new
|
18
17
|
super
|
19
18
|
end
|
20
19
|
|
21
20
|
desc "cp [FILENAME]", "copy FILENAME to the cloud. If FILENAME not given send STDIN to the cloud"
|
22
21
|
def cp(filename = nil)
|
23
|
-
type =
|
22
|
+
type = 'file'
|
24
23
|
content_type = nil
|
25
24
|
|
26
25
|
content = if filename.nil?
|
@@ -42,27 +41,22 @@ class RemoteCp < Thor
|
|
42
41
|
File.open(full_path)
|
43
42
|
end
|
44
43
|
end
|
45
|
-
|
46
|
-
# I think that all this info should be included file's metadata
|
47
|
-
S3Object.store("file_name.txt", basename, bucket_name)
|
48
|
-
S3Object.store("content", content, bucket_name, :content_type => content_type)
|
49
|
-
S3Object.store("type", type, bucket_name)
|
44
|
+
@clipboard.push(content, basename, type, content_type)
|
50
45
|
end
|
51
46
|
|
52
47
|
desc "p", "paste from the cloud to current dir"
|
53
48
|
def p
|
54
|
-
file_name =
|
55
|
-
type = S3Object.find("type", bucket_name).value
|
56
|
-
|
49
|
+
file_name = @clipboard.filename
|
57
50
|
if File.exist?(file_name)
|
58
51
|
puts "#{file_name} already exist."
|
59
52
|
print "Do you want to replace it (y/n)? "
|
60
53
|
res = $stdin.gets.chomp
|
61
54
|
return unless res == "y"
|
62
55
|
end
|
63
|
-
|
64
|
-
content =
|
65
|
-
|
56
|
+
|
57
|
+
content = @clipboard.content
|
58
|
+
|
59
|
+
case @clipboard.filetype
|
66
60
|
when 'file'
|
67
61
|
File.open(file_name, "w+") {|f| f << content}
|
68
62
|
puts "#{file_name} copied."
|
@@ -74,42 +68,18 @@ class RemoteCp < Thor
|
|
74
68
|
|
75
69
|
desc "fn", "Returns the file name of the copied file"
|
76
70
|
def fn
|
77
|
-
puts
|
78
|
-
end
|
79
|
-
|
80
|
-
desc "cat", "Dump the copied file to stdout"
|
81
|
-
def cat
|
82
|
-
puts rm_content
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
def bucket_name
|
87
|
-
config[:bucket_name]
|
71
|
+
puts @clipboard.filename
|
88
72
|
end
|
89
73
|
|
90
|
-
|
91
|
-
|
74
|
+
desc "ft", "Returns the file type"
|
75
|
+
def ft
|
76
|
+
puts @clipboard.filetype
|
92
77
|
end
|
93
78
|
|
94
|
-
|
95
|
-
|
96
|
-
|
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 your home dir."
|
111
|
-
end
|
79
|
+
desc "cat", "Dump the copied file to stdout"
|
80
|
+
def cat
|
81
|
+
puts @clipboard.content
|
112
82
|
end
|
113
83
|
end
|
114
84
|
|
115
|
-
|
85
|
+
Clipboard.start
|
data/lib/remote_cp/version.rb
CHANGED
data/lib/remote_cp.rb
CHANGED
@@ -4,101 +4,86 @@ require 'archive/tar/minitar'
|
|
4
4
|
require 'thor'
|
5
5
|
require 'aws/s3'
|
6
6
|
|
7
|
-
|
8
|
-
include Archive::Tar
|
9
|
-
include AWS::S3
|
10
|
-
|
11
|
-
def initialize(*args)
|
12
|
-
AWS::S3::Base.establish_connection!(
|
13
|
-
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
|
14
|
-
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
|
15
|
-
)
|
16
|
-
super
|
17
|
-
end
|
18
|
-
|
19
|
-
desc "cp", "copy to the cloud clipboard"
|
20
|
-
def cp(filename = nil)
|
21
|
-
type = nil
|
22
|
-
content_type = nil
|
7
|
+
include AWS::S3
|
23
8
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
type = 'directory'
|
36
|
-
io.rewind
|
37
|
-
io.string
|
38
|
-
else
|
39
|
-
type = 'file'
|
40
|
-
File.open(full_path)
|
41
|
-
end
|
9
|
+
module RemoteCp
|
10
|
+
class Clipboard
|
11
|
+
include AWS::S3
|
12
|
+
attr_accessor :content_bucket, :filename_bucket, :type_bucket
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
connect
|
16
|
+
@bucket = Bucket.find(bucket_name)
|
17
|
+
@content_bucket = @bucket['content'] || create_obj("content", "")
|
18
|
+
@filename_bucket = @bucket['file_name.txt'] || create_obj("file_name.txt", "")
|
19
|
+
@type_bucket = @bucket['type'] || create_obj("type", "")
|
42
20
|
end
|
43
21
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
desc "p", "paste from the cloud to current dir"
|
51
|
-
def rmp
|
52
|
-
s3_connect
|
22
|
+
def connect
|
23
|
+
AWS::S3::Base.establish_connection!(
|
24
|
+
:access_key_id => config[:access_key_id],
|
25
|
+
:secret_access_key => config[:secret_access_key]
|
26
|
+
)
|
27
|
+
end
|
53
28
|
|
54
|
-
|
55
|
-
|
29
|
+
def config
|
30
|
+
config_filename = File.join(ENV["HOME"], ".remote_cp.yml")
|
56
31
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
32
|
+
@config ||= if File.exist?(config_filename)
|
33
|
+
conf = Hash.new {|key, val| raise "Missing key #{key} in config file: #{config_filename}"}
|
34
|
+
conf.replace(YAML::load_file(config_filename))
|
35
|
+
else
|
36
|
+
config = {:access_key_id => "MY_ACCESS_KEY", :secret_access_key => "MY_SECRET", :bucket_name => "MY_BUCKET_NAME"}
|
37
|
+
File.open(config_filename, "w") do |f|
|
38
|
+
f << YAML::dump(config)
|
39
|
+
end
|
40
|
+
File.chmod(0600, config_filename)
|
41
|
+
raise "Please setup your .remote_cp.yml config file in your home dir."
|
42
|
+
end
|
62
43
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
44
|
+
|
45
|
+
# str : content to copy
|
46
|
+
# type : :file, :directory
|
47
|
+
def push(str, filename = "anomymous", type = :file, content_type = nil)
|
48
|
+
# I think that all this info should be included file's metadata
|
49
|
+
# AWS::S3 does not support metadata setting on creation.
|
50
|
+
@filename_bucket.value = filename
|
51
|
+
@filename_bucket.save
|
52
|
+
|
53
|
+
@content_bucket.value = str
|
54
|
+
@content_bucket.content_type = content_type
|
55
|
+
@content_bucket.save
|
56
|
+
|
57
|
+
@type_bucket.value = type.to_s
|
58
|
+
@type_bucket.save
|
59
|
+
end
|
60
|
+
|
61
|
+
def pull
|
62
|
+
@content_bucket.value
|
63
|
+
end
|
64
|
+
|
65
|
+
def bucket_name
|
66
|
+
config[:bucket_name]
|
67
|
+
end
|
68
|
+
|
69
|
+
def filetype
|
70
|
+
@type_bucket.value
|
71
|
+
end
|
72
|
+
|
73
|
+
def content
|
74
|
+
@bucket['content'].value
|
72
75
|
end
|
73
|
-
end
|
74
|
-
|
75
|
-
desc "fn", "Returns the file name of the copied file"
|
76
|
-
def fn
|
77
|
-
rm_filename
|
78
|
-
end
|
79
|
-
|
80
|
-
desc "cat", "Dump the copied file to stdout"
|
81
|
-
def cat
|
82
|
-
rm_content
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
def s3_connect
|
87
|
-
require 'aws/s3'
|
88
|
-
include AWS::S3
|
89
|
-
AWS::S3::Base.establish_connection!(
|
90
|
-
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
|
91
|
-
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
|
92
|
-
)
|
93
|
-
end
|
94
|
-
|
95
|
-
def filename
|
96
|
-
S3Object.find("file_name.txt", 'RemoteClipboard').value
|
97
|
-
end
|
98
76
|
|
99
|
-
|
100
|
-
|
77
|
+
def filename
|
78
|
+
@filename_bucket.value
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_obj(key, value)
|
82
|
+
obj = @bucket.new_object
|
83
|
+
obj.key = key
|
84
|
+
obj.value = value
|
85
|
+
obj.store
|
86
|
+
obj
|
87
|
+
end
|
101
88
|
end
|
102
|
-
end
|
103
|
-
|
104
|
-
RemoteCp.start
|
89
|
+
end
|
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: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
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-04-
|
18
|
+
date: 2011-04-23 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|