baidupan 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63a2a4e78c3b198d7c4c375c7939794b1288856e
4
- data.tar.gz: 31b1d38ef8145ec73121c9866c37526ebf3349f8
3
+ metadata.gz: a7bf29bd9e970583b16dcc95efbe8bd58c555d81
4
+ data.tar.gz: 50a1d6c214706ab0bead3a76a36c7201dde7b63c
5
5
  SHA512:
6
- metadata.gz: 111618908ebb33590dc4550361cfb5d352e022e52523955f62bbd0a9d6458cb928a320b8e3b72f3cbbca7668944bafbfaadd81a7149ab9fedfc948ebd8cfc05c
7
- data.tar.gz: fdf6e40a76af0b387ee7d2a5b8afec1ca0c03fb059c9071c55354e2e5259dafa8330a336c3024176a4bb7cdbd664524166e8962c59a118b0a7190e4c499db6d9
6
+ metadata.gz: e9615c5148eff1c8ab80e5351296ff70898dc9f1fcb8dabfc62fa32b09e1c196bcd4d7757e59ec88cafe6e80c19de99843e6db2cc5721722f0989dd685bb4ab2
7
+ data.tar.gz: 63de6c09ef2a05555c8a550d0748133e3d490f37dd6bedfe8b968e977382ef7ac5bc79870e159b098062f3e633c3f44122a74b0347fb33925be5d4db9299b9a9
data/README.md CHANGED
@@ -20,24 +20,35 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
  如何使用该gem:
23
+
23
24
  * 创建百度应用 http://developer.baidu.com/wiki/index.php?title=%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3%E9%A6%96%E9%A1%B5
25
+
24
26
  * baidupan setup 应用名字 api_key, secret_key
27
+
25
28
  * baidupan config 按照提示 进行授权
26
29
 
27
30
  基本命令:
31
+
28
32
  * baidupan setup 添加文件信息
33
+
29
34
  * baidupan config 进行授权
35
+
30
36
  * baidupan list or ls 显示app应用的文件列表
37
+
31
38
  * baidupan upload 文件
39
+
32
40
  * 更多命令 请运行baidupan 查看即可
33
41
 
34
42
  Todo:
35
43
  * 移动文件的位置
44
+
36
45
  * 删除文件
46
+
37
47
  * 对文件重命名
38
48
 
39
49
  已经实现:
40
50
  * 通过配置连接百度盘
51
+
41
52
  * 能够上传、下载以及显示文件
42
53
 
43
54
 
@@ -35,6 +35,48 @@ overwrite:表示覆盖同名文件;newcopy:表示生成文件副本并进
35
35
  print_item res.body
36
36
  end
37
37
 
38
+ desc 'batch_upload [local dir, remote dir, file_pattern="*"]', <<-Desc
39
+ 批量上传文件, 模式需要进行转义, 如下:
40
+ baidupan ./ test_dir \*.gem --show:
41
+ baidupan-0.0.4.gem
42
+ baidupan-0.0.2.gem
43
+ baidupan-0.0.3.gem
44
+ Desc
45
+ option :show, desc: "show files that will be uploaded"
46
+ option :recursive, desc: "对子目录递归上传", type: :boolean
47
+ def batch_upload(ldir, rdir, file_pattern="*")
48
+ opts = options.dup
49
+ old_ldir = ldir
50
+
51
+ if opts[:recursive]
52
+ ldir = File.join(ldir, "**")
53
+ opts.delete(:recursive)
54
+ end
55
+
56
+
57
+ files = Dir.glob(File.join(ldir, file_pattern)).select{|f| File.file?(f)}
58
+
59
+ if options[:show]
60
+ files.each{|file| puts file}
61
+ say "total #{files.size} files"
62
+ return
63
+ end
64
+
65
+ count = 0
66
+ origin_rdir = rdir
67
+ current_dir = Regexp.new("^#{File.join(old_ldir, '')}")
68
+
69
+ files.each do |file|
70
+ dirname = File.dirname(file.gsub(current_dir, ''))
71
+ dirname = '' if dirname == '.'
72
+
73
+ rdir = File.join(origin_rdir, dirname)
74
+ Baidupan::FsCmd.upload(file, rdir, opts)
75
+ say file
76
+ count += 1
77
+ end
78
+ say "total upload #{count} files"
79
+ end
38
80
 
39
81
  desc 'download file [Remote path, Local path', 'download remote file to local, not support for download dir'
40
82
  def download(rpath, lpath=nil)
@@ -26,6 +26,12 @@ module Baidupan
26
26
  def time_format
27
27
  "%Y%m%d%H%M%S"
28
28
  end
29
+
30
+ def join_path(*files)
31
+ files.inject(self.app_root) do |rpath, lpath|
32
+ File.join(rpath, lpath)
33
+ end
34
+ end
29
35
  end
30
36
 
31
37
  private
@@ -12,7 +12,7 @@ module Baidupan
12
12
  end
13
13
 
14
14
  def upload(lpath, rpath, opts={})
15
- params = common_params(:upload, path: "#{Config.app_root}/#{rpath}/#{lpath}").merge(ondup: :newcopy)
15
+ params = common_params(:upload, path: "#{Config.join_path(rpath, File.basename(lpath))}").merge(ondup: :newcopy)
16
16
  params[:ondup] = opts.delete(:ondup) if opts[:ondup]
17
17
 
18
18
  body = {:file => File.open(lpath)}
@@ -23,7 +23,6 @@ module Baidupan
23
23
 
24
24
  def download(rpath, lpath, opts={})
25
25
  params = common_params(:download, path: "#{Config.app_root}/#{rpath}")
26
-
27
26
  get(Config.file_path, params, opts.merge(followlocation: true))
28
27
  end
29
28
  end
@@ -1,3 +1,3 @@
1
1
  module Baidupan
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baidupan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyHu
@@ -129,7 +129,6 @@ files:
129
129
  - lib/baidupan/cmd/fs_cmd.rb
130
130
  - lib/baidupan/config.rb
131
131
  - lib/baidupan/fs_cmd.rb
132
- - lib/baidupan/test.rb
133
132
  - lib/baidupan/version.rb
134
133
  homepage: http://ml-china.org
135
134
  licenses:
@@ -1,13 +0,0 @@
1
- require 'baidupan'
2
- require 'thor'
3
-
4
- module Baidupan
5
- class Test < Thor
6
- include Thor::Actions
7
-
8
- desc 'test', 'test'
9
- def test
10
- puts 'test'
11
- end
12
- end
13
- end