dcp 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -2
- data/exe/dcp +50 -16
- data/lib/dcp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a3684057e46d7a76afa18a87a847628f90296b7dbb923fb0b2a61317b53e45b
|
4
|
+
data.tar.gz: 407dba1947c83f8bd14ff46f5e57d180a46bfb13623cfe87acb5c47a8082934c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 280561df8444dac11ebd0988c40ad4b79ff85670b7d87f4a80c124427a3d94cb7fa19626be6d09830967508f652f57919bef4d92556cebda14b707388ed4f643
|
7
|
+
data.tar.gz: ea678ec17a77f65f56b07d835be75b17d4c83db9f7d559583fccb454e9deb2b4d06088038b8a44e944728f2fabfb6ddebb126c8209fb440da38ad482ff9aaa46
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,11 +8,17 @@ copy files to/from dropbox like scp command
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
11
|
-
|
11
|
+
```
|
12
|
+
Usage: dcp [options] [db:]SRC [SRC...] [db:]DEST
|
13
|
+
-q, --quiet quiet mode
|
14
|
+
-h, --help print this messages
|
15
|
+
```
|
16
|
+
|
17
|
+
specify Dropbox path start with 'db:' or 'dropbox:'.
|
12
18
|
|
13
19
|
## Development
|
14
20
|
|
15
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
21
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
16
22
|
|
17
23
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
18
24
|
|
data/exe/dcp
CHANGED
@@ -19,10 +19,9 @@ module DCP
|
|
19
19
|
|
20
20
|
class CLI
|
21
21
|
def run
|
22
|
-
opts, args = parse_options
|
23
|
-
dst = args.pop
|
22
|
+
@opts, args = parse_options
|
24
23
|
begin
|
25
|
-
|
24
|
+
pairs = make_pairs(args.pop, args)
|
26
25
|
rescue MultiError => e
|
27
26
|
e.messages.each{|m| error m}
|
28
27
|
exit 1
|
@@ -31,27 +30,29 @@ module DCP
|
|
31
30
|
exit 1
|
32
31
|
end
|
33
32
|
begin
|
34
|
-
|
35
|
-
|
33
|
+
pairs.each do |src, dst|
|
34
|
+
puts "#{src} => #{dst}" if @opts[:debug]
|
36
35
|
open(src, 'r') do |r|
|
37
|
-
|
38
|
-
open(d, 'w') do |w|
|
36
|
+
open(dst, 'w') do |w|
|
39
37
|
while data = r.read(10_000_000) do
|
40
38
|
w.write(data)
|
41
|
-
print '.' unless opts[:quiet]
|
39
|
+
print '.' unless @opts[:quiet]
|
42
40
|
end
|
43
41
|
end
|
44
|
-
puts unless opts[:quiet]
|
45
42
|
end
|
43
|
+
puts if @opts[:debug]
|
46
44
|
end
|
45
|
+
puts unless @opts[:quiet]
|
47
46
|
rescue => e
|
48
|
-
|
47
|
+
error "#{e.message} (#{e.class})"
|
48
|
+
exit 1
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
private
|
53
53
|
def error(msg)
|
54
54
|
$stderr.puts "dcp: #{msg}"
|
55
|
+
$@.each{|e| $stderr.puts e} if @opts[:debug]
|
55
56
|
end
|
56
57
|
|
57
58
|
def parse_options(argv = ARGV)
|
@@ -66,12 +67,16 @@ module DCP
|
|
66
67
|
end
|
67
68
|
|
68
69
|
opts = {
|
69
|
-
quiet: false
|
70
|
+
quiet: false,
|
71
|
+
debug: false
|
70
72
|
}
|
71
73
|
|
72
74
|
op.on('-q', '--quiet', "quiet mode") do
|
73
75
|
opts[:quiet] = true
|
74
76
|
end
|
77
|
+
op.on('-D', '--debug', "debug mode") do
|
78
|
+
opts[:debug] = true
|
79
|
+
end
|
75
80
|
op.on('-h', '--help', "print this messages") do
|
76
81
|
usage
|
77
82
|
end
|
@@ -120,8 +125,11 @@ module DCP
|
|
120
125
|
file.split(/:/, 2)[1]
|
121
126
|
end
|
122
127
|
|
123
|
-
def
|
128
|
+
def make_pairs(dst, srcs)
|
124
129
|
errors = []
|
130
|
+
dst_is_directory = false
|
131
|
+
|
132
|
+
# cheking src file existance
|
125
133
|
srcs.each do |src|
|
126
134
|
begin
|
127
135
|
if dropbox_path?(src)
|
@@ -136,15 +144,33 @@ module DCP
|
|
136
144
|
end
|
137
145
|
end
|
138
146
|
|
147
|
+
# cheking dst file correctness
|
139
148
|
begin
|
140
|
-
|
141
|
-
|
149
|
+
d = dst =~ /\/\z/ ? dst.chop : dst # root directory => ''
|
150
|
+
if file?(d)
|
151
|
+
if srcs.size > 1
|
152
|
+
errors << "cannot copy multiple files into a file: #{dst}"
|
153
|
+
end
|
154
|
+
elsif directory?(d)
|
155
|
+
dst_is_directory = true
|
156
|
+
end
|
157
|
+
rescue Errno::ENOENT # check parent directory existance
|
158
|
+
begin
|
159
|
+
if directory?(File.dirname(d)) && srcs.size > 1
|
160
|
+
errors << "cannot copy multiple files into a file: #{dst}"
|
161
|
+
end
|
162
|
+
rescue Errno::ENOENT
|
163
|
+
errors << "file not found: #{dst}"
|
142
164
|
end
|
143
|
-
rescue Errno::ENOENT
|
144
|
-
errors << "file not found: #{dst}"
|
145
165
|
end
|
146
166
|
|
147
167
|
raise MultiError.new(errors) unless errors.empty?
|
168
|
+
|
169
|
+
if dst_is_directory
|
170
|
+
return srcs.map{|src| [src, "#{d}/#{File.basename(src)}"]}
|
171
|
+
else
|
172
|
+
return [[srcs[0], dst]]
|
173
|
+
end
|
148
174
|
end
|
149
175
|
|
150
176
|
def open(file, opts)
|
@@ -155,6 +181,14 @@ module DCP
|
|
155
181
|
end
|
156
182
|
end
|
157
183
|
|
184
|
+
def file?(file)
|
185
|
+
if dropbox_path?(file)
|
186
|
+
dropbox.file?(dropbox_path(file))
|
187
|
+
else
|
188
|
+
File.stat(file).file?
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
158
192
|
def directory?(file)
|
159
193
|
if dropbox_path?(file)
|
160
194
|
dropbox.directory?(dropbox_path(file))
|
data/lib/dcp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dcp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TADA Tadashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pit
|