aliyun-oss-sync 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 77bf52c78219f3aa6964e3bdfdd4ea1f1b13daf4
4
+ data.tar.gz: 9ffb4d6a1597dba5f12a9364bbfc334f8028eadd
5
+ SHA512:
6
+ metadata.gz: fd721ebdb99518edcccad6ee6945d0a1876460018a11dfdc75d4bf07c7f12448620101d34f377d9a57c6684b98dfd0841fa0f411ac0e56fc3f59d148c712047b
7
+ data.tar.gz: 5865bb41615fe77af1fb5c0548e6a5f42985ef732724ee7c78296b3fefade4fe28310e81c1bf7a66834019f3e93a08470e7ba0ff05e1d4bf629198f702c9f958
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://ruby.taobao.org'
2
+ #source 'https://rubygems.org'
3
+ gemspec
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aliyun-oss-sync (0.0.1)
5
+ aliyun-oss
6
+ colored
7
+ gli (= 2.9.0)
8
+ listen
9
+ mime-types
10
+
11
+ GEM
12
+ remote: http://ruby.taobao.org/
13
+ specs:
14
+ aliyun-oss (0.7.0.1349333720)
15
+ builder
16
+ mime-types
17
+ xml-simple
18
+ aruba (0.5.4)
19
+ childprocess (>= 0.3.6)
20
+ cucumber (>= 1.1.1)
21
+ rspec-expectations (>= 2.7.0)
22
+ builder (3.2.2)
23
+ celluloid (0.15.2)
24
+ timers (~> 1.1.0)
25
+ celluloid-io (0.15.0)
26
+ celluloid (>= 0.15.0)
27
+ nio4r (>= 0.5.0)
28
+ childprocess (0.5.1)
29
+ ffi (~> 1.0, >= 1.0.11)
30
+ colored (1.2)
31
+ cucumber (1.3.13)
32
+ builder (>= 2.1.2)
33
+ diff-lcs (>= 1.1.3)
34
+ gherkin (~> 2.12)
35
+ multi_json (>= 1.7.5, < 2.0)
36
+ multi_test (>= 0.1.1)
37
+ diff-lcs (1.2.5)
38
+ ffi (1.9.3)
39
+ gherkin (2.12.2)
40
+ multi_json (~> 1.3)
41
+ gli (2.9.0)
42
+ json (1.8.1)
43
+ listen (2.7.1)
44
+ celluloid (>= 0.15.2)
45
+ celluloid-io (>= 0.15.0)
46
+ rb-fsevent (>= 0.9.3)
47
+ rb-inotify (>= 0.9)
48
+ mime-types (2.2)
49
+ multi_json (1.9.2)
50
+ multi_test (0.1.1)
51
+ nio4r (1.0.0)
52
+ rake (10.2.1)
53
+ rb-fsevent (0.9.4)
54
+ rb-inotify (0.9.3)
55
+ ffi (>= 0.5.0)
56
+ rdoc (4.1.1)
57
+ json (~> 1.4)
58
+ rspec-expectations (2.14.5)
59
+ diff-lcs (>= 1.1.3, < 2.0)
60
+ timers (1.1.0)
61
+ xml-simple (1.1.3)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ aliyun-oss-sync!
68
+ aruba
69
+ rake
70
+ rdoc
@@ -0,0 +1,25 @@
1
+ # aliyun-oss-sync
2
+
3
+ 阿里云OSS同步工具
4
+
5
+ ## 安装
6
+
7
+ gem install aliyun-oss-sync
8
+
9
+ ## 同步
10
+
11
+ ### 本地文件同步到OSS
12
+
13
+ OSS_ACCESS_ID=your-access-id \
14
+ OSS_ACCESS_SECRET=your-access-secret \
15
+ aliyun-oss-sync push bucket名称:远程目录 本地目录
16
+
17
+ ### OSS文件同步到本地
18
+
19
+ OSS_ACCESS_ID=your-access-id \
20
+ OSS_ACCESS_SECRET=your-access-secret \
21
+ aliyun-oss-sync pull bucket名称:远程目录 本地目录
22
+
23
+ 具体的参数可以用 `aliyun-oss-sync --help [子命令]` 查看
24
+
25
+
@@ -0,0 +1,44 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+ Rake::RDocTask.new do |rd|
8
+ rd.main = "README.rdoc"
9
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
+ rd.title = 'Your application title'
11
+ end
12
+
13
+ spec = eval(File.read('aosss.gemspec'))
14
+
15
+ Gem::PackageTask.new(spec) do |pkg|
16
+ end
17
+ CUKE_RESULTS = 'results.html'
18
+ CLEAN << CUKE_RESULTS
19
+ desc 'Run features'
20
+ Cucumber::Rake::Task.new(:features) do |t|
21
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
+ t.cucumber_opts = opts
24
+ t.fork = false
25
+ end
26
+
27
+ desc 'Run features tagged as work-in-progress (@wip)'
28
+ Cucumber::Rake::Task.new('features:wip') do |t|
29
+ tag_opts = ' --tags ~@pending'
30
+ tag_opts = ' --tags @wip'
31
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32
+ t.fork = false
33
+ end
34
+
35
+ task :cucumber => :features
36
+ task 'cucumber:wip' => 'features:wip'
37
+ task :wip => 'features:wip'
38
+ require 'rake/testtask'
39
+ Rake::TestTask.new do |t|
40
+ t.libs << "test"
41
+ t.test_files = FileList['test/*_test.rb']
42
+ end
43
+
44
+ task :default => [:test,:features]
@@ -0,0 +1,30 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__),'lib','aosss','version.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'aliyun-oss-sync'
5
+ s.version = Aosss::VERSION
6
+ s.author = 'qhwa'
7
+ s.email = 'qhwa@163.com'
8
+ s.homepage = 'http://q.pnq.cc'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'Sync script for aliyun OSS'
11
+ s.files = `git ls-files`.split("
12
+ ")
13
+ s.require_paths << 'lib'
14
+ s.has_rdoc = true
15
+ s.extra_rdoc_files = ['README.md','aosss.rdoc']
16
+ s.rdoc_options << '--title' << 'aosss' << '--main' << 'README.rdoc' << '-ri'
17
+ s.bindir = 'bin'
18
+ s.executables << 'aliyun-oss-sync'
19
+
20
+
21
+ s.add_development_dependency('rake')
22
+ s.add_development_dependency('rdoc')
23
+ s.add_development_dependency('aruba')
24
+
25
+ s.add_runtime_dependency('gli','2.9.0')
26
+ s.add_runtime_dependency('aliyun-oss')
27
+ s.add_runtime_dependency('listen')
28
+ s.add_runtime_dependency('colored')
29
+ s.add_runtime_dependency('mime-types')
30
+ end
@@ -0,0 +1,5 @@
1
+ = aosss
2
+
3
+ Generate this with
4
+ aosss rdoc
5
+ After you have described your command line interface
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ begin # XXX: Remove this begin/rescue before distributing your app
4
+ require 'aosss'
5
+ rescue LoadError
6
+ STDERR.puts "In development, you need to use `bundle exec bin/aosss` to run your app"
7
+ STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
8
+ STDERR.puts "Feel free to remove this message from bin/aosss now"
9
+ exit 64
10
+ end
11
+
12
+ include GLI::App
13
+
14
+ program_desc 'aliyun oss sync'
15
+ version Aosss::VERSION
16
+
17
+ #desc 'Describe some switch here'
18
+ #switch [:s,:switch]
19
+
20
+ desc 'aliyun access key id'
21
+ flag [:k, :key]
22
+
23
+ desc 'aliyun access key secret'
24
+ flag [:s, :secret]
25
+
26
+ pre do |global,command,options,args|
27
+ true
28
+ end
29
+
30
+ post do |global,command,options,args|
31
+ end
32
+
33
+ on_error do |exception|
34
+ # Error logic here
35
+ # return false to skip default error handling
36
+ puts exception.message
37
+ puts exception.backtrace
38
+ true
39
+ end
40
+
41
+
42
+ desc 'pull files from Aliyun OSS to local directory'
43
+ arg_name 'bucket'
44
+
45
+ command :pull do |c|
46
+
47
+ c.action do |global, options, args|
48
+ Aosss.pull key: global[:key],
49
+ secret: global[:secret],
50
+ remote: args[0],
51
+ local_path: args[1] || Dir.pwd
52
+
53
+ end
54
+ end
55
+
56
+ desc 'push files from local directory to Aliyun OSS'
57
+ command :push do |c|
58
+ c.desc 'only test, not do real file uploading'
59
+ c.switch [:d, :dryrun]
60
+
61
+ c.desc 'copy method'
62
+ c.default_value 'skip'
63
+ c.flag :method
64
+
65
+ c.action do |global, options, args|
66
+ Aosss.push key: global[:key],
67
+ secret: global[:secret],
68
+ dryrun: options[:dryrun],
69
+ method: options[:method],
70
+ remote: args[0],
71
+ local_path: args[1] || Dir.pwd
72
+ end
73
+ end
74
+
75
+ desc 'sync files between local directory and Aliyun OSS'
76
+ command :sync do |c|
77
+ c.action do
78
+ end
79
+ end
80
+
81
+
82
+ exit run(ARGV)
@@ -0,0 +1,8 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "aosss"
8
+ Then the exit status should be 0
@@ -0,0 +1,6 @@
1
+ When /^I get help for "([^"]*)"$/ do |app_name|
2
+ @app_name = app_name
3
+ step %(I run `#{app_name} help`)
4
+ end
5
+
6
+ # Add more step definitions here
@@ -0,0 +1,15 @@
1
+ require 'aruba/cucumber'
2
+
3
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
+
6
+ Before do
7
+ # Using "announce" causes massive warnings on 1.9.2
8
+ @puts = true
9
+ @original_rubylib = ENV['RUBYLIB']
10
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ ENV['RUBYLIB'] = @original_rubylib
15
+ end
@@ -0,0 +1,20 @@
1
+ require 'aosss/version.rb'
2
+ require 'aosss/sync.rb'
3
+
4
+ module Aosss
5
+
6
+ class << self
7
+ def pull( options )
8
+ Sync.new( options ).pull
9
+ end
10
+
11
+ def push( options )
12
+ Sync.new( options ).push
13
+ end
14
+
15
+ def sync( options )
16
+ Sync.new( options ).sync
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,119 @@
1
+ require 'colored'
2
+ require 'aliyun/oss'
3
+ require 'listen'
4
+ require 'find'
5
+ require 'pathname'
6
+
7
+ module Aosss
8
+
9
+ class Sync
10
+
11
+ attr_reader :bucket, :key, :secret, :remote, :remote_path, :local_path
12
+
13
+ def initialize( options )
14
+ @key = options[:key] || ENV['OSS_ACCESS_ID']
15
+ @secret = options[:secret] || ENV['OSS_ACCESS_SECRET']
16
+ @remote = options[:remote]
17
+ @dryrun = options[:dryrun]
18
+ @method = options[:method]
19
+ @local_path = File.expand_path(options[:local_path])
20
+ parse_remote
21
+ init_connection
22
+ end
23
+
24
+ def pull
25
+ step_info "pulling #{"(dryrun)" if @dryrun}"
26
+
27
+ print indent << "#{bucket}:#{remote_path}"
28
+ print " => "
29
+ print "local:#{local_path}\n"
30
+ end
31
+
32
+ def push
33
+ step_info "pushing #{"(dryrun)" if @dryrun}"
34
+
35
+ print "\n#{indent} " <<
36
+ "#{bucket}:#{remote_path}".bold <<
37
+ " => local:#{local_path}".bold <<
38
+ "\n\n"
39
+
40
+ Find.find( local_path ) do |path|
41
+ if File.basename(path).start_with? ?.
42
+ Find.prune
43
+ elsif !File.directory?(path)
44
+ file = short_path(path)
45
+
46
+ print indent << "=> ".black << file
47
+
48
+ if @method == "skip" and exist_on_oss?( File.join( remote_path, file ) )
49
+ print " ~skip\n".yellow
50
+ else
51
+ push_to_oss( file ) unless @dryrun
52
+ print " ✔\n".green
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ private
60
+
61
+ def parse_remote
62
+ @bucket, @remote_path = @remote.split(":")
63
+ @remote_path ||= "/"
64
+ end
65
+
66
+ def init_connection
67
+ step_info "init connection"
68
+ Aliyun::OSS::Base.establish_connection!(
69
+ :access_key_id => key,
70
+ :secret_access_key => secret
71
+ )
72
+ end
73
+
74
+ def step_info( msg )
75
+ puts "----> #{msg}"
76
+ end
77
+
78
+ def indent
79
+ " " * 6
80
+ end
81
+
82
+ def short_path( path )
83
+ Pathname.new( path ).relative_path_from( Pathname.new( local_path ) ).to_path
84
+ end
85
+
86
+ def push_to_oss( file )
87
+ Aliyun::OSS::OSSObject.store(
88
+ File.join( remote_path, file ),
89
+ open(file),
90
+ bucket
91
+ )
92
+ end
93
+
94
+ def open( file )
95
+ File.open( File.expand_path(file, local_path) )
96
+ end
97
+
98
+ def exist_on_oss?( file )
99
+ oss_bucket
100
+ Aliyun::OSS::OSSObject.exists? file, bucket
101
+ end
102
+
103
+ def oss_bucket
104
+ @oss_bucket ||= Aliyun::OSS::Bucket.find bucket
105
+ end
106
+
107
+ public
108
+
109
+ def watch
110
+ Listen.to!( local_path, relative_paths: true ) do |modified, added, removed|
111
+ modified.each {|file| push_to_oss(file) }
112
+ added.each {|file| push_to_oss(file) }
113
+ removed.each {|file| del_in_oss(file) }
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ end
@@ -0,0 +1,3 @@
1
+ module Aosss
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_the_truth
12
+ assert true
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ # Add test libraries you want to use here, e.g. mocha
4
+
5
+ class Test::Unit::TestCase
6
+
7
+ # Add global extensions to the test case class here
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aliyun-oss-sync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - qhwa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: aliyun-oss
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: listen
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: colored
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: mime-types
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email: qhwa@163.com
127
+ executables:
128
+ - aliyun-oss-sync
129
+ extensions: []
130
+ extra_rdoc_files:
131
+ - README.md
132
+ - aosss.rdoc
133
+ files:
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - README.md
137
+ - Rakefile
138
+ - aosss.gemspec
139
+ - aosss.rdoc
140
+ - bin/aliyun-oss-sync
141
+ - features/aosss.feature
142
+ - features/step_definitions/aosss_steps.rb
143
+ - features/support/env.rb
144
+ - lib/aosss.rb
145
+ - lib/aosss/sync.rb
146
+ - lib/aosss/version.rb
147
+ - test/default_test.rb
148
+ - test/test_helper.rb
149
+ homepage: http://q.pnq.cc
150
+ licenses: []
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options:
154
+ - "--title"
155
+ - aosss
156
+ - "--main"
157
+ - README.rdoc
158
+ - "-ri"
159
+ require_paths:
160
+ - lib
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 2.2.2
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: Sync script for aliyun OSS
178
+ test_files: []