dcp 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +8 -2
  4. data/exe/dcp +50 -16
  5. data/lib/dcp/version.rb +1 -1
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ae9bca889c34738a0c2ea78783c973b8d325280251def8ecd31c6fad8aaa16e
4
- data.tar.gz: ee80f7c7f1eea995da97a767ed200ec40612c05b7d41d64500728cff0faab1b3
3
+ metadata.gz: 4a3684057e46d7a76afa18a87a847628f90296b7dbb923fb0b2a61317b53e45b
4
+ data.tar.gz: 407dba1947c83f8bd14ff46f5e57d180a46bfb13623cfe87acb5c47a8082934c
5
5
  SHA512:
6
- metadata.gz: 9c629121e4db91bf98395c7b22a889c538be69d169194e252714ce6f470871b13c81865d8ff065ebbdc0011605c23fff6cd68be1f312feaf1cb80a5aebbcd632
7
- data.tar.gz: ba481ad8eed77700f4701fb5aad056d9ad6d2696904c956d25e2bf43495fac4d1c08014b878a9916581eb84ea3724b8ad4d406e5a26c2e23352c4672b19f927e
6
+ metadata.gz: 280561df8444dac11ebd0988c40ad4b79ff85670b7d87f4a80c124427a3d94cb7fa19626be6d09830967508f652f57919bef4d92556cebda14b707388ed4f643
7
+ data.tar.gz: ea678ec17a77f65f56b07d835be75b17d4c83db9f7d559583fccb454e9deb2b4d06088038b8a44e944728f2fabfb6ddebb126c8209fb440da38ad482ff9aaa46
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dcp (0.2.0)
4
+ dcp (0.2.1)
5
5
  dropbox_api
6
6
  pit
7
7
 
data/README.md CHANGED
@@ -8,11 +8,17 @@ copy files to/from dropbox like scp command
8
8
 
9
9
  ## Usage
10
10
 
11
- TODO: Write usage instructions here
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. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- precheck(args, dst)
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
- dst = dst.chop if dst =~ /\/\z/ # root directory => ''
35
- args.each do |src|
33
+ pairs.each do |src, dst|
34
+ puts "#{src} => #{dst}" if @opts[:debug]
36
35
  open(src, 'r') do |r|
37
- d = directory?(dst) ? "#{dst}/#{File.basename(src)}" : dst
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
- usage "#{e.message} (#{e.class})"
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 precheck(srcs, dst)
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
- if directory?(dst) && srcs.size > 1
141
- errors << "cannot copy multiple files into a file: #{dst}"
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))
@@ -1,3 +1,3 @@
1
1
  module DCP
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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-21 00:00:00.000000000 Z
11
+ date: 2017-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pit