Changeset 572
- Timestamp:
- 07/01/08 09:07:04 (2 months ago)
- Files:
-
- thingfish/trunk/lib/thingfish/daemon.rb (modified) (1 diff)
- thingfish/trunk/lib/thingfish/metastore.rb (modified) (2 diffs)
- thingfish/trunk/plugins/thingfish-filter-mp3/lib/thingfish/filter/mp3.rb (modified) (3 diffs)
- thingfish/trunk/plugins/thingfish-filter-mp3/spec/thingfish/filter/mp3_spec.rb (modified) (4 diffs)
- thingfish/trunk/plugins/thingfish-handler-formupload/lib/thingfish/handler/formupload.rb (modified) (1 diff)
- thingfish/trunk/plugins/thingfish-handler-formupload/spec/thingfish/handler/formupload_spec.rb (modified) (1 diff)
- thingfish/trunk/spec/thingfish/daemon_spec.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
thingfish/trunk/lib/thingfish/daemon.rb
r568 r572 258 258 259 259 260 ### Remove any resources that have a +related_to+ of the given UUID, and a +relation+ of 261 ### 'appended'. 262 def purge_related_resources( uuid ) 263 uuids = @metastore.find_by_exact_properties( :related_to => uuid.to_s, :relation => 'appended' ) 260 ### Remove any resources that have a +related_to+ of the given UUID, and 261 ### the given +relation+ (or any relation if none is specified) 262 def purge_related_resources( uuid, relation=nil ) 263 uuids = @metastore.find_by_exact_properties( :related_to => uuid.to_s, :relation => relation ) 264 self.log.debug "Found UUIDS for purging: %p" % [ uuids ] 264 265 uuids.each do |subuuid| 265 266 self.log.debug "purging appended resource %s for %s" % [ subuuid, uuid ] thingfish/trunk/lib/thingfish/metastore.rb
r548 r572 374 374 ### intersected, and any UUIDs common to all matched tuples are returned. 375 375 def intersect_each_tuple( hash ) 376 377 # Trim nil values out of the hash then make a search pair for each key/value combination. 378 # { 'format' => ['image/png', 'image/jpeg' ], 'extent' => 3400 } 379 # becomes: 380 # [ ['format', 'image/png'], ['format', 'image/jpeg'], ['extent', 3400] ] 376 381 tuples = hash.reject {|k,v| v.nil? }.inject([]) do |ary, pair| 377 382 key,vals = *pair … … 382 387 ary 383 388 end 384 389 390 # Iterate over each search pair, searching for matches, then narrowing the results by 391 # intersecting the previous resultset with the current one. 385 392 uuids = tuples.inject(nil) do |ary, pair| 386 393 key, value = *pair thingfish/trunk/plugins/thingfish-filter-mp3/lib/thingfish/filter/mp3.rb
r568 r572 108 108 # Append any album images as related resources 109 109 self.extract_images( id3 ).each do |io, metadata| 110 metadata[:title] = "Album art for %s - %s" % mp3_metadata.values_at( :mp3_artist, :mp3_title ) 110 111 request.append_related_resource( body, io, metadata ) 111 112 end … … 210 211 blob, mime = img.unpack( APIC_FORMAT ).values_at( 4, 1 ) 211 212 data[ StringIO.new(blob) ] = { 212 :format => mime,213 :extent => blob.length,214 : title=> 'album-art'213 :format => mime, 214 :extent => blob.length, 215 :relation => 'album-art' 215 216 } 216 217 end … … 222 223 mime = MIMETYPE_MAP[ ".#{type.downcase}" ] or next 223 224 data[ StringIO.new(blob) ] = { 224 :format => mime,225 :extent => blob.length,226 : title=> 'album-art'225 :format => mime, 226 :extent => blob.length, 227 :relation => 'album-art' 227 228 } 228 229 end thingfish/trunk/plugins/thingfish-filter-mp3/spec/thingfish/filter/mp3_spec.rb
r568 r572 211 211 :format => 'image/jpeg', 212 212 :extent => 7369, 213 :title => 'album-art' 213 :title => 'Album art for Tim Reilly - (unknown)', 214 :relation => 'album-art' 214 215 } 215 216 … … 229 230 :format => 'image/jpeg', 230 231 :extent => 7369, 231 :title => 'album-art' 232 :title => 'Album art for Tim Reilly - (unknown)', 233 :relation => 'album-art' 232 234 } 233 235 png_art_hash = { 234 236 :format => 'image/png', 235 237 :extent => 18031, 236 :title => 'album-art' 238 :title => 'Album art for Tim Reilly - (unknown)', 239 :relation => 'album-art' 237 240 } 238 241 … … 256 259 :format => 'image/jpeg', 257 260 :extent => 7369, 258 :title => 'album-art' 261 :title => 'Album art for Tim Reilly - (unknown)', 262 :relation => 'album-art' 259 263 } 260 264 … … 274 278 :format => 'image/jpeg', 275 279 :extent => 7369, 276 :title => 'album-art' 280 :title => 'Album art for Tim Reilly - (unknown)', 281 :relation => 'album-art' 277 282 } 278 283 png_art_hash = { 279 284 :format => 'image/png', 280 285 :extent => 18031, 281 :title => 'album-art' 286 :title => 'Album art for Tim Reilly - (unknown)', 287 :relation => 'album-art' 282 288 } 283 289 thingfish/trunk/plugins/thingfish-handler-formupload/lib/thingfish/handler/formupload.rb
r499 r572 122 122 123 123 files = [] 124 request.each_body( true ) do |body, metadata| 124 request.each_body do |body, metadata| 125 126 # Store each primary resource 125 127 uuid = self.daemon.store_resource( body, metadata ) 126 128 metadata[:uuid] = uuid 129 130 # Store any related resources, linked to the primary 131 self.daemon.store_related_resources( body, uuid, request ) 132 127 133 files << [ uuid, metadata ] 128 134 end thingfish/trunk/plugins/thingfish-handler-formupload/spec/thingfish/handler/formupload_spec.rb
r493 r572 177 177 and_return( TEST_UUID ) 178 178 179 mockdaemon.should_receive( :store_related_resources ). 180 with( upload1, TEST_UUID, @request ) 181 179 182 @response.should_receive( :status= ).with( HTTP::OK ) 180 183 @response.should_receive( :body= ).with( [ [TEST_UUID, metadata] ] ) thingfish/trunk/spec/thingfish/daemon_spec.rb
r568 r572 51 51 include ThingFish::SpecHelpers 52 52 53 before(:all) do54 setup_logging( :fatal )55 end56 57 58 53 before( :each ) do 59 54 # Have to set up logging each time, 'cause Daemon alters it in some examples … … 720 715 721 716 722 it "knows how to purge related resources" do717 it "knows how to purge specific related resources" do 723 718 filestore = mock( "filestore", :null_object => true ) 724 719 @daemon.instance_variable_set( :@filestore, filestore ) … … 728 723 search_criteria = { 729 724 :related_to => TEST_UUID, 730 :relation => ' appended'725 :relation => 'thumbnail' 731 726 } 732 727 metastore.should_receive( :find_by_exact_properties ). … … 739 734 filestore.should_receive( :delete ).with( TEST_UUID3 ) 740 735 741 @daemon.purge_related_resources( TEST_UUID ) 742 end 743 744 736 @daemon.purge_related_resources( TEST_UUID, 'thumbnail' ) 737 end 738 739 740 it "knows how to purge all related resources" do 741 filestore = mock( "filestore" ) 742 @daemon.instance_variable_set( :@filestore, filestore ) 743 metastore = mock( "metastore" ) 744 @daemon.instance_variable_set( :@metastore, metastore ) 745 746 search_criteria = { 747 :related_to => TEST_UUID, 748 :relation => nil 749 } 750 metastore.should_receive( :find_by_exact_properties ). 751 with( search_criteria ). 752 and_return( [ TEST_UUID2, TEST_UUID3 ]) 753 754 metastore.should_receive( :delete_resource ).with( TEST_UUID2 ) 755 metastore.should_receive( :delete_resource ).with( TEST_UUID3 ) 756 filestore.should_receive( :delete ).with( TEST_UUID2 ) 757 filestore.should_receive( :delete ).with( TEST_UUID3 ) 758 759 @daemon.purge_related_resources( TEST_UUID ) 760 end 761 762 745 763 it "doesn't propagate errors that occur while storing a related resource" do 746 764 related_body = mock( "related body IO" )
