flickrup 1.1.4 → 1.1.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.
@@ -0,0 +1,27 @@
1
+ require "fileutils"
2
+
3
+ class Archiver
4
+
5
+ def archive(ctx)
6
+ archive_file_by_date(ctx.properties[:filename], ctx.properties[:archive_dir], ctx.properties[:date_taken], ctx.properties[:subdir])
7
+ end
8
+
9
+ private
10
+
11
+ def archive_file_by_date(file, to_dir, date, subdir = nil)
12
+ target_dir = File.join(
13
+ to_dir,
14
+ date.strftime("%Y"),
15
+ date.strftime("%b")
16
+ )
17
+
18
+ if subdir
19
+ target_dir = "#{target_dir}/#{subdir}"
20
+ end
21
+
22
+ FileUtils.mkdir_p(target_dir)
23
+ FileUtils.mv(file, File.join(target_dir, File.basename(file)))
24
+ logger.info("Archived #{File.basename(file)} to #{target_dir}")
25
+ end
26
+
27
+ end
@@ -15,9 +15,20 @@ class TagSets < PrefixedExtension
15
15
 
16
16
  uploaded = @delegate.upload(ctx)
17
17
 
18
- sets.each do |set|
19
- logger.debug("Adding #{ctx.file.filename} to set: #{set}")
20
- @flickr.add_to_set(uploaded, set)
18
+ unless ctx.properties[UploaderConstants::NO_UPLOAD] == true
19
+ sets.each do |set|
20
+ logger.debug("Adding #{ctx.file.filename} to set: #{set}")
21
+ @flickr.add_to_set(uploaded, set)
22
+ end
21
23
  end
22
24
  end
25
+
26
+ def archive(ctx)
27
+ sets = values(:tagsetprefix, ctx).uniq
28
+
29
+ if sets.length == 1
30
+ ctx.properties[:subdir] = sets[0]
31
+ end
32
+ @delegate.archive(ctx)
33
+ end
23
34
  end
@@ -44,9 +44,12 @@ class TaggedFile
44
44
  end)
45
45
  end
46
46
 
47
- def archive(to_dir)
48
- date_taken = @parsed.date_time_original || @parsed.modifydate
49
- archive_by_date(to_dir, date_taken)
47
+ def archive(archive_handlers, to_dir)
48
+ archive_handlers.archive(ProcessingContext.new(self, {
49
+ :archive_dir => to_dir,
50
+ :date_taken => @parsed.date_time_original || @parsed.modifydate,
51
+ :filename => @filename
52
+ }))
50
53
  end
51
54
 
52
55
  def pre_upload
@@ -56,25 +59,6 @@ class TaggedFile
56
59
  def post_upload
57
60
 
58
61
  end
59
-
60
- private
61
-
62
- def archive_by_date(to_dir, date)
63
- archive_file_by_date(@filename, to_dir, date)
64
- end
65
-
66
- def archive_file_by_date(file, to_dir, date)
67
- target_dir = File.join(
68
- to_dir,
69
- date.strftime("%Y"),
70
- date.strftime("%b")
71
- )
72
-
73
- FileUtils.mkdir_p(target_dir)
74
- FileUtils.mv(file, File.join(target_dir, File.basename(file)))
75
- logger.info("Archived #{File.basename(file)} to #{target_dir}")
76
- end
77
-
78
62
  end
79
63
 
80
64
  require 'flickrup/filetype/tagged_image'
@@ -1,13 +1,13 @@
1
1
  class ProcessingContext
2
2
  attr_reader :file
3
- attr_reader :upload_properties
3
+ attr_reader :properties
4
4
 
5
5
  def initialize(file, props = {})
6
6
  @file = file
7
- @upload_properties = props
7
+ @properties = props
8
8
  end
9
9
 
10
10
  def with_properties(props)
11
- ProcessingContext.new(self.file, self.upload_properties.merge(props))
11
+ ProcessingContext.new(self.file, self.properties.merge(props))
12
12
  end
13
13
  end
@@ -5,6 +5,7 @@ require "flickrup/ext/tag_sets"
5
5
  require "flickrup/ext/replacement_tags"
6
6
  require "flickrup/ext/machine_tags"
7
7
  require "flickrup/ext/visibility"
8
+ require "flickrup/archiver"
8
9
 
9
10
  class Processor
10
11
  include Logging
@@ -55,7 +56,7 @@ class Processor
55
56
  x.doUpload(get_preupload_handlers, uploader)
56
57
  logger.debug("Upload complete for #{x.filename}")
57
58
  logger.debug("Beginning archive for #{x.filename}...")
58
- x.archive(@config[:archive_dir])
59
+ x.archive(get_archiver, @config[:archive_dir])
59
60
  logger.debug("Processing complete for #{x.filename}")
60
61
  rescue => e
61
62
  logger.error("Failed to process #{x.filename} due to exception: #{e}")
@@ -82,13 +83,23 @@ class Processor
82
83
  end
83
84
  end
84
85
 
86
+ def get_archiver
87
+ archive_handlers.reduce(Archiver.new) do |result, clazz|
88
+ clazz.new(@config, result, {})
89
+ end
90
+ end
91
+
85
92
  def get_preupload_handlers
86
93
  [MachineTags.new(@config, {}), ReplacementTags.new(@config)]
87
94
  end
88
95
 
89
- def upload_handlers()
96
+ def upload_handlers
90
97
  [TagSets, Visibility]
91
98
  end
92
99
 
100
+ def archive_handlers
101
+ [TagSets]
102
+ end
103
+
93
104
  end
94
105
 
@@ -16,7 +16,7 @@ class Uploader
16
16
 
17
17
  def upload(ctx)
18
18
 
19
- if ctx.upload_properties[UploaderConstants::NO_UPLOAD]
19
+ if ctx.properties[UploaderConstants::NO_UPLOAD]
20
20
  logger.info("Skipping upload of #{ctx.file.filename} as marked as NO_UPLOAD")
21
21
  else
22
22
  logger.debug("Uploading #{ctx.file.filename} with tags #{ctx.file.tags}")
@@ -33,7 +33,7 @@ class Uploader
33
33
  end
34
34
 
35
35
  def prepare_upload_properties(ctx)
36
- {:tags => ctx.file.tags.to_s}.merge(ctx.upload_properties)
36
+ {:tags => ctx.file.tags.to_s}.merge(ctx.properties)
37
37
  end
38
38
 
39
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 4
10
- version: 1.1.4
9
+ - 5
10
+ version: 1.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan Gilbert
@@ -154,6 +154,7 @@ extensions: []
154
154
  extra_rdoc_files: []
155
155
 
156
156
  files:
157
+ - lib/flickrup/archiver.rb
157
158
  - lib/flickrup/ext/machine_tags.rb
158
159
  - lib/flickrup/ext/prefixed_extension.rb
159
160
  - lib/flickrup/ext/replacement_tags.rb