flickrup 0.0.14 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,9 @@ class MachineTags
3
3
  @config = config
4
4
  end
5
5
 
6
- def preupload(image, meta, config)
6
+ def preupload(ctx)
7
7
 
8
- tags = config[:tags]
8
+ tags = ctx.image.tags
9
9
 
10
10
  remapped = tags.map do |x|
11
11
  x.sub(/^([^:]+):([^:]+)::/,"\\1:\\2=")
@@ -14,11 +14,11 @@ class MachineTags
14
14
 
15
15
 
16
16
  unless tags == remapped #write back to file
17
- meta['Keywords'] = remapped
18
- meta['Subject'] = remapped #also write Subject XMP tag
17
+ ctx.image['Keywords'] = remapped
18
+ ctx.image['Subject'] = remapped #also write Subject XMP tag
19
19
  end
20
20
 
21
- config.merge({:tags => TagSet.new(remapped)})
21
+ ctx
22
22
 
23
23
  end
24
24
  end
@@ -3,8 +3,8 @@ class PrefixedExtension
3
3
  @config = config
4
4
  end
5
5
 
6
- def values(prefix_key, config)
7
- all_tags = config[:tags]
6
+ def values(prefix_key, ctx)
7
+ all_tags = ctx.image.tags
8
8
 
9
9
  prefix = @config[prefix_key]
10
10
 
@@ -3,23 +3,23 @@ class ReplacementTags
3
3
  @config = config
4
4
  end
5
5
 
6
- def preupload(image, meta, config)
6
+ def preupload(ctx)
7
7
 
8
8
  replacements = @config[:tag_replacements]
9
9
 
10
10
  if replacements != nil
11
11
  replacements.each do |tag_name, tag_value_replacements|
12
- existing = meta[tag_name]
12
+ existing = ctx.image[tag_name]
13
13
 
14
14
  tag_value_replacements.each do |key, value|
15
15
  if existing == key
16
- meta[tag_name] = value
16
+ ctx.image[tag_name] = value
17
17
  break
18
18
  end
19
19
  end
20
20
  end
21
21
  end
22
22
 
23
- config
23
+ ctx
24
24
  end
25
25
  end
@@ -7,10 +7,10 @@ class TagSets < PrefixedExtension
7
7
  @flickr = context[:flickr_client]
8
8
  end
9
9
 
10
- def upload(image, meta, config)
11
- sets = values(:tagsetprefix, config)
10
+ def upload(ctx)
11
+ sets = values(:tagsetprefix, ctx)
12
12
 
13
- uploaded = @delegate.upload(image, meta, config)
13
+ uploaded = @delegate.upload(ctx)
14
14
 
15
15
  sets.each do |set|
16
16
  @flickr.add_to_set(uploaded, set)
@@ -8,8 +8,8 @@ class Visibility < PrefixedExtension
8
8
  @delegate = delegate
9
9
  end
10
10
 
11
- def upload(image, meta, config)
12
- visibility = values(:visibilityprefix, config)
11
+ def upload(ctx)
12
+ visibility = values(:visibilityprefix, ctx)
13
13
 
14
14
  config_override = if visibility.length == 0
15
15
  logger.debug("No visibility specified for #{image}.")
@@ -21,7 +21,7 @@ class Visibility < PrefixedExtension
21
21
  config_for_visibility(visibility[0])
22
22
  end
23
23
 
24
- @delegate.upload(image, meta, config.merge(config_override))
24
+ @delegate.upload(ctx.with_properties(config_override))
25
25
  end
26
26
 
27
27
  def config_for_visibility(visibility)
@@ -0,0 +1,13 @@
1
+ class ProcessingContext
2
+ attr_reader :image
3
+ attr_reader :upload_properties
4
+
5
+ def initialize(image, props = {})
6
+ @image = image
7
+ @upload_properties = props
8
+ end
9
+
10
+ def with_properties(props)
11
+ ProcessingContext.new(self.image, self.upload_properties.merge(props))
12
+ end
13
+ end
@@ -39,12 +39,12 @@ class Processor
39
39
  sleep 5
40
40
  else
41
41
  tagged.each { |x|
42
- logger.debug("Beginning upload for #{x.file}...")
42
+ logger.debug("Beginning upload for #{x.filename}...")
43
43
  x.doUpload(get_preupload_handlers, uploader)
44
- logger.debug("Upload complete for #{x.file}")
45
- logger.debug("Beginning archive for #{x.file}...")
44
+ logger.debug("Upload complete for #{x.filename}")
45
+ logger.debug("Beginning archive for #{x.filename}...")
46
46
  x.archive(@config[:archive_dir])
47
- logger.debug("Processing complete for #{x.file}")
47
+ logger.debug("Processing complete for #{x.filename}")
48
48
  }
49
49
  end
50
50
 
@@ -2,15 +2,16 @@ require 'mini_exiftool'
2
2
  require 'fileutils'
3
3
  require "flickrup/logging"
4
4
  require "flickrup/tag_set"
5
+ require "flickrup/processing_context"
5
6
 
6
7
  class TaggedImage
7
8
  include Logging
8
9
 
9
- attr_reader :file
10
+ attr_reader :filename
10
11
 
11
- def initialize(file)
12
- @file = file
13
- @parsed = MiniExiftool.new @file
12
+ def initialize(filename)
13
+ @filename = filename
14
+ @parsed = MiniExiftool.new filename
14
15
  end
15
16
 
16
17
  def tags
@@ -25,8 +26,8 @@ class TaggedImage
25
26
 
26
27
  def doUpload(preupload_handlers, uploader)
27
28
 
28
- config = preupload_handlers.reduce({:tags => tags}) do |config, handler|
29
- handler.preupload(file, self, config)
29
+ context = preupload_handlers.reduce(ProcessingContext.new(self)) do |ctx, handler|
30
+ handler.preupload(ctx)
30
31
  end
31
32
 
32
33
  #maybe save afterwards
@@ -34,7 +35,7 @@ class TaggedImage
34
35
  @parsed.save!
35
36
  end
36
37
 
37
- uploader.upload(file, self, config)
38
+ uploader.upload(context)
38
39
 
39
40
  #maybe save afterwards
40
41
  if @parsed.changed?
@@ -52,8 +53,8 @@ class TaggedImage
52
53
  )
53
54
 
54
55
  FileUtils.mkdir_p(target_dir)
55
- FileUtils.mv(@file, File.join(target_dir, File.basename(@file)))
56
- logger.info("Archived #{File.basename(@file)} to #{target_dir}")
56
+ FileUtils.mv(@filename, File.join(target_dir, File.basename(@filename)))
57
+ logger.info("Archived #{File.basename(@filename)} to #{target_dir}")
57
58
  end
58
59
 
59
60
  # Returns the value of a tag.
@@ -14,22 +14,26 @@ class Uploader
14
14
  @flickr = flickr_client
15
15
  end
16
16
 
17
- def upload(image, meta, config)
17
+ def upload(ctx)
18
18
 
19
- if config[UploaderConstants::NO_UPLOAD]
20
- logger.info("Skipping upload of #{image} as marked as NO_UPLOAD")
19
+ if ctx.upload_properties[UploaderConstants::NO_UPLOAD]
20
+ logger.info("Skipping upload of #{ctx.image.filename} as marked as NO_UPLOAD")
21
21
  else
22
- logger.debug("Uploading #{image} with tags #{config[:tags]}")
22
+ logger.debug("Uploading #{ctx.image.filename} with tags #{ctx.image.tags}")
23
23
 
24
24
  begin
25
- rv = @flickr.upload_photo(image, config)
26
- logger.debug("Uploaded #{image}")
25
+ rv = @flickr.upload_photo(ctx.image.filename, prepare_upload_properties(ctx))
26
+ logger.debug("Uploaded #{ctx.image.filename}")
27
27
  rescue StandardError => err
28
- logger.error("Failed to upload #{image}: #{err}")
28
+ logger.error("Failed to upload #{ctx.image.filename}: #{err}")
29
29
  end
30
30
  end
31
31
 
32
32
  rv
33
33
  end
34
34
 
35
+ def prepare_upload_properties(ctx)
36
+ {:tags => ctx.image.tags.to_s}.merge(ctx.upload_properties)
37
+ end
38
+
35
39
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickrup
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
- - 14
10
- version: 0.0.14
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan Gilbert
@@ -145,6 +145,7 @@ files:
145
145
  - lib/flickrup/ext/visibility.rb
146
146
  - lib/flickrup/flickr_client.rb
147
147
  - lib/flickrup/logging.rb
148
+ - lib/flickrup/processing_context.rb
148
149
  - lib/flickrup/processor.rb
149
150
  - lib/flickrup/quick_listener.rb
150
151
  - lib/flickrup/slow_listener.rb