baidupan 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/baidupan/cmd/fs_cmd.rb +42 -0
- data/lib/baidupan/config.rb +6 -0
- data/lib/baidupan/fs_cmd.rb +1 -2
- data/lib/baidupan/version.rb +1 -1
- metadata +1 -2
- data/lib/baidupan/test.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7bf29bd9e970583b16dcc95efbe8bd58c555d81
|
4
|
+
data.tar.gz: 50a1d6c214706ab0bead3a76a36c7201dde7b63c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/baidupan/cmd/fs_cmd.rb
CHANGED
@@ -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)
|
data/lib/baidupan/config.rb
CHANGED
data/lib/baidupan/fs_cmd.rb
CHANGED
@@ -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.
|
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
|
data/lib/baidupan/version.rb
CHANGED
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
|
+
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:
|