uploadr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
File without changes
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dan Ryan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Uploadr
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'uploadr'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install uploadr
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ $: << File.join(File.dirname(__FILE__), "..", "lib")
5
+
6
+ require 'uploadr'
7
+ require 'uploadr/command'
8
+
9
+ Uploadr::Command.run
@@ -0,0 +1,20 @@
1
+ require 'flickraw'
2
+ require 'parseconfig'
3
+ require 'celluloid'
4
+
5
+ require 'uploadr/version'
6
+
7
+ require 'uploadr/queue'
8
+ require 'uploadr/worker'
9
+ require 'uploadr/config'
10
+ require 'uploadr/bar'
11
+ require 'uploadr/log'
12
+
13
+ module Uploadr
14
+ extend Uploadr::Config
15
+
16
+ FlickRaw.api_key = ENV['FLICKR_API_KEY'] || "3863ad4bbc95758077ee8709de72752f"
17
+ FlickRaw.shared_secret = ENV['FLICKR_SHARED_SECRET'] || "3ce6eaa025d9a699"
18
+
19
+ # Your code goes here...
20
+ end
@@ -0,0 +1,10 @@
1
+ require 'flickraw'
2
+
3
+ module Uploadr
4
+ module Authentication
5
+
6
+ def authentication
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ require 'progress_bar'
2
+
3
+ module Uploadr
4
+ class Bar
5
+ include Celluloid
6
+
7
+ def initialize
8
+ @progress_bar = ProgressBar.new(Actor[:queue].files.length)
9
+ end
10
+
11
+ def increment
12
+ @progress_bar.increment!
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,69 @@
1
+ require 'clamp'
2
+ require 'progress_bar'
3
+
4
+ require 'uploadr/log'
5
+ require 'uploadr/queue'
6
+ require 'uploadr/worker'
7
+ require 'uploadr/bar'
8
+
9
+ module Uploadr
10
+ class Command < Clamp::Command
11
+
12
+ option [ '-v', '--version' ], :flag, 'print version and exit' do
13
+ puts Uploadr::VERSION
14
+ exit 0
15
+ end
16
+
17
+ subcommand 'upload', 'upload a directory of files' do
18
+ option [ '-n', '--concurrency' ], 'NUM', 'The number of concurrent uploaders', default: 4 do |x|
19
+ x.to_i
20
+ end
21
+
22
+ option [ '-d', '--directory'], 'DIR', 'The directory to upload',
23
+ multivalued: true, default: [], attribute_name: :directories
24
+
25
+ option [ '-c', '--config'], 'CONFIG', 'The config file to use', default: "#{ENV['HOME']}/.uploadrc"
26
+
27
+ def execute
28
+ self_read, self_write = IO.pipe
29
+
30
+ %w( INT TERM ).each do |signal|
31
+ trap signal do
32
+ raise Interrupt
33
+ end
34
+ end
35
+
36
+ begin
37
+
38
+ Uploadr.worker_count = concurrency
39
+ Uploadr.directories = directories
40
+ Uploadr.config_file = config
41
+
42
+ Uploadr::Queue.supervise_as(:queue)
43
+ Uploadr::Log.supervise_as(:log)
44
+ Uploadr::Bar.supervise_as(:bar)
45
+
46
+ pool = Uploadr::Worker.pool(size: Uploadr.worker_count) #, args: [ queue ])
47
+
48
+ Celluloid::Actor[:queue].wait_completion
49
+
50
+ rescue Interrupt
51
+ pool.terminate
52
+
53
+ Celluloid::Actor[:bar].terminate
54
+ Celluloid::Actor[:log].terminate
55
+ Celluloid::Actor[:queue].terminate
56
+
57
+ exit 0
58
+ end
59
+
60
+ # worker = Uploadr::Worker.new(queue, config)
61
+ # puts client.connection.test.login
62
+ # get list of files inside directories
63
+ # work off queue 'til done
64
+ # profit?
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,38 @@
1
+ require 'parseconfig'
2
+
3
+ module Uploadr
4
+ module Config
5
+ VALID_OPTIONS_KEYS = [
6
+ :worker_count,
7
+ :directories,
8
+ :config,
9
+ :config_file
10
+ ]
11
+
12
+ attr_accessor(*VALID_OPTIONS_KEYS)
13
+
14
+ def self.extended(base)
15
+ base.reset
16
+ end
17
+
18
+ def configure
19
+ yield self
20
+ end
21
+
22
+ def options
23
+ VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
24
+ end
25
+
26
+ def config
27
+ @config ||= ParseConfig.new(File.expand_path(config_file))
28
+ end
29
+
30
+ def reset
31
+ self.config = nil
32
+ self.config_file = nil
33
+ self.worker_count = nil
34
+ self.directories = nil
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,55 @@
1
+ require 'flickraw'
2
+
3
+ module Uploadr
4
+ class Connection
5
+
6
+ attr_accessor :config
7
+
8
+ def initialize
9
+ @config = Uploadr.config
10
+ end
11
+
12
+ def upload(photo)
13
+ connection.upload_photo photo,
14
+ is_public: 0,
15
+ is_friend: 0,
16
+ is_family: 0,
17
+ safety_level: 1,
18
+ content_type: 1,
19
+ hidden: 2
20
+ end
21
+
22
+ private
23
+
24
+ def connection
25
+ connection = FlickRaw::Flickr.new
26
+
27
+ if config['access_token'] && config['access_secret']
28
+ connection.access_token = config['access_token']
29
+ connection.access_secret = config['access_secret']
30
+ else
31
+ token = connection.get_request_token
32
+ auth_url = connection.get_authorize_url(token['oauth_token'], :perms => 'write')
33
+
34
+ puts "Open this URL, follow the instructions, and paste the number here:"
35
+ puts auth_url
36
+ verification_token = STDIN.gets.strip
37
+
38
+ connection.get_access_token token['oauth_token'], token['oauth_token_secret'], verification_token
39
+
40
+ login = connection.test.login
41
+
42
+ config.params['access_token'] = connection.access_token
43
+ config.params['access_secret'] = connection.access_secret
44
+ config.write(config.config_file)
45
+
46
+ File.open(config.config_file, 'w') do |file|
47
+ config.write(file)
48
+ end
49
+ end
50
+
51
+ connection
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,12 @@
1
+ require 'celluloid'
2
+
3
+ module Uploadr
4
+ class Log
5
+ include Celluloid
6
+
7
+ def puts(msg)
8
+ Kernel.puts(msg)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ require 'celluloid'
2
+
3
+ module Uploadr
4
+ class Queue
5
+ include Celluloid
6
+
7
+ attr_accessor :files
8
+
9
+ def initialize
10
+ @worker_count = Uploadr.worker_count
11
+ @files = []
12
+ Uploadr.directories.each do |dir|
13
+ @files << Dir.glob("#{File.expand_path(dir)}/**/*.jpg", File::FNM_CASEFOLD)
14
+ end
15
+ @files.flatten!
16
+ end
17
+
18
+ def shift
19
+ @files.shift
20
+ end
21
+
22
+ def completed
23
+ @worker_count -= 1
24
+ if @worker_count == 0
25
+ signal(:all_completed)
26
+ end
27
+ end
28
+
29
+ def wait_completion
30
+ wait(:all_completed)
31
+ Actor[:log].puts "Shutting down..."
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Uploadr
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,40 @@
1
+ require 'uploadr/connection'
2
+
3
+ module Uploadr
4
+ class Worker
5
+ include Celluloid
6
+
7
+ attr_accessor :connection
8
+
9
+ def initialize
10
+ @connection = Uploadr::Connection.new
11
+ async.run
12
+ # @connection = get_connection
13
+ end
14
+
15
+ def run
16
+ loop do
17
+ file = Actor[:queue].shift
18
+ break unless file
19
+ # Actor[:out].puts "[#{thread_id}] Uploading file: #{file}"
20
+ upload(file)
21
+ # Actor[:out].puts "[#{thread_id}] Finished uploading file: #{file}"
22
+ # Actor[:out].puts "#{queue.files.length} photos remaining"
23
+ Actor[:bar].increment
24
+ end
25
+
26
+ Actor[:queue].async.completed
27
+ end
28
+
29
+ private
30
+
31
+ def thread_id
32
+ '%x' % Thread.current.object_id
33
+ end
34
+
35
+ def upload(photo)
36
+ connection.upload(photo)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,30 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :rspec
6
+ config.use_transactional_fixtures = false
7
+ config.infer_base_class_for_anonymous_controllers = false
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.order = "random"
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run focus: true
12
+ config.filter_run_excluding external: true
13
+ end
14
+
15
+ def fixture_path
16
+ File.expand_path("../support/fixtures", __FILE__)
17
+ end
18
+
19
+ def fixture
20
+ File.new(fixture_path + '/' + file)
21
+ end
22
+
23
+ def json_response(file)
24
+ {
25
+ body: fixture(file),
26
+ headers: {
27
+ content_type: 'application/json; charset=utf-8'
28
+ }
29
+ }
30
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'uploadr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "uploadr"
8
+ spec.version = Uploadr::VERSION
9
+ spec.authors = ["Dan Ryan"]
10
+ spec.email = ["dan@appliedawesome.com"]
11
+ spec.description = %q{A fast Flickr bulk upload utility}
12
+ spec.summary = %q{A fast Flickr bulk upload utility}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.files = %w[ LICENSE.txt CONTRIBUTING.md CHANGELOG.md README.md Rakefile uploadr.gemspec ]
18
+ %w[ lib bin spec ].each do |dir|
19
+ spec.files += Dir["#{dir}/**/*"]
20
+ end
21
+
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.required_ruby_version = '>= 1.9.2'
27
+ spec.required_rubygems_version = '>= 1.3.6'
28
+
29
+ spec.add_dependency 'clamp', '~> 0.6'
30
+ spec.add_dependency 'flickraw'
31
+ spec.add_dependency 'celluloid'
32
+ spec.add_dependency 'parseconfig'
33
+ spec.add_dependency 'progress_bar'
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.3"
36
+ spec.add_development_dependency 'guard-rspec', '>= 3.0.2'
37
+ spec.add_development_dependency 'pry'
38
+ spec.add_development_dependency 'rake'
39
+ spec.add_development_dependency 'rspec', '>= 2.13.0'
40
+ spec.add_development_dependency 'webmock', '>= 1.13.0'
41
+ spec.add_development_dependency "rake"
42
+ end
metadata ADDED
@@ -0,0 +1,258 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uploadr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dan Ryan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: clamp
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.6'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: flickraw
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: celluloid
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: parseconfig
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: progress_bar
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: bundler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.3'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.3'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 3.0.2
126
+ - !ruby/object:Gem::Dependency
127
+ name: pry
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rake
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: rspec
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: 2.13.0
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: 2.13.0
174
+ - !ruby/object:Gem::Dependency
175
+ name: webmock
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: 1.13.0
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: 1.13.0
190
+ - !ruby/object:Gem::Dependency
191
+ name: rake
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ description: A fast Flickr bulk upload utility
207
+ email:
208
+ - dan@appliedawesome.com
209
+ executables:
210
+ - uploadr
211
+ extensions: []
212
+ extra_rdoc_files: []
213
+ files:
214
+ - LICENSE.txt
215
+ - CONTRIBUTING.md
216
+ - CHANGELOG.md
217
+ - README.md
218
+ - Rakefile
219
+ - uploadr.gemspec
220
+ - lib/uploadr/authentication.rb
221
+ - lib/uploadr/bar.rb
222
+ - lib/uploadr/command.rb
223
+ - lib/uploadr/config.rb
224
+ - lib/uploadr/connection.rb
225
+ - lib/uploadr/log.rb
226
+ - lib/uploadr/queue.rb
227
+ - lib/uploadr/version.rb
228
+ - lib/uploadr/worker.rb
229
+ - lib/uploadr.rb
230
+ - bin/uploadr
231
+ - spec/spec_helper.rb
232
+ homepage: ''
233
+ licenses:
234
+ - MIT
235
+ post_install_message:
236
+ rdoc_options: []
237
+ require_paths:
238
+ - lib
239
+ required_ruby_version: !ruby/object:Gem::Requirement
240
+ none: false
241
+ requirements:
242
+ - - ! '>='
243
+ - !ruby/object:Gem::Version
244
+ version: 1.9.2
245
+ required_rubygems_version: !ruby/object:Gem::Requirement
246
+ none: false
247
+ requirements:
248
+ - - ! '>='
249
+ - !ruby/object:Gem::Version
250
+ version: 1.3.6
251
+ requirements: []
252
+ rubyforge_project:
253
+ rubygems_version: 1.8.23
254
+ signing_key:
255
+ specification_version: 3
256
+ summary: A fast Flickr bulk upload utility
257
+ test_files:
258
+ - spec/spec_helper.rb