Changeset 572

Show
Ignore:
Timestamp:
07/01/08 09:07:04 (2 months ago)
Author:
mahlon
Message:
  • Add more informational goodies with album-art extracted from mp3s.
  • Have the formupload handler be "resource append" aware.
  • Alter ThingFish::Daemon#purge_related_resources() to allow for selective deleting.
  • Add some comments to the metastore intersect_each_tuple() method.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • thingfish/trunk/lib/thingfish/daemon.rb

    r568 r572  
    258258     
    259259     
    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 ] 
    264265        uuids.each do |subuuid| 
    265266            self.log.debug "purging appended resource %s for %s" % [ subuuid, uuid ] 
  • thingfish/trunk/lib/thingfish/metastore.rb

    r548 r572  
    374374    ### intersected, and any UUIDs common to all matched tuples are returned. 
    375375    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] ] 
    376381        tuples = hash.reject {|k,v| v.nil? }.inject([]) do |ary, pair| 
    377382            key,vals = *pair 
     
    382387            ary 
    383388        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. 
    385392        uuids = tuples.inject(nil) do |ary, pair| 
    386393            key, value = *pair 
  • thingfish/trunk/plugins/thingfish-filter-mp3/lib/thingfish/filter/mp3.rb

    r568 r572  
    108108                # Append any album images as related resources 
    109109                self.extract_images( id3 ).each do |io, metadata| 
     110                    metadata[:title] = "Album art for %s - %s" % mp3_metadata.values_at( :mp3_artist, :mp3_title ) 
    110111                    request.append_related_resource( body, io, metadata ) 
    111112                end 
     
    210211                blob, mime = img.unpack( APIC_FORMAT ).values_at( 4, 1 ) 
    211212                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' 
    215216                } 
    216217            end 
     
    222223                mime = MIMETYPE_MAP[ ".#{type.downcase}" ] or next 
    223224                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' 
    227228                } 
    228229            end 
  • thingfish/trunk/plugins/thingfish-filter-mp3/spec/thingfish/filter/mp3_spec.rb

    r568 r572  
    211211                :format => 'image/jpeg', 
    212212                :extent => 7369, 
    213                 :title  => 'album-art' 
     213                :title  => 'Album art for Tim Reilly - (unknown)', 
     214                :relation => 'album-art' 
    214215            } 
    215216 
     
    229230                :format => 'image/jpeg', 
    230231                :extent => 7369, 
    231                 :title  => 'album-art' 
     232                :title  => 'Album art for Tim Reilly - (unknown)', 
     233                :relation => 'album-art' 
    232234            } 
    233235            png_art_hash = {  
    234236                :format => 'image/png', 
    235237                :extent => 18031, 
    236                 :title  => 'album-art' 
     238                :title  => 'Album art for Tim Reilly - (unknown)', 
     239                :relation => 'album-art' 
    237240            } 
    238241 
     
    256259                :format => 'image/jpeg', 
    257260                :extent => 7369, 
    258                 :title  => 'album-art' 
     261                :title  => 'Album art for Tim Reilly - (unknown)', 
     262                :relation => 'album-art' 
    259263            } 
    260264 
     
    274278                :format => 'image/jpeg', 
    275279                :extent => 7369, 
    276                 :title  => 'album-art' 
     280                :title  => 'Album art for Tim Reilly - (unknown)', 
     281                :relation => 'album-art' 
    277282            } 
    278283            png_art_hash = {  
    279284                :format => 'image/png', 
    280285                :extent => 18031, 
    281                 :title  => 'album-art' 
     286                :title  => 'Album art for Tim Reilly - (unknown)', 
     287                :relation => 'album-art' 
    282288            } 
    283289 
  • thingfish/trunk/plugins/thingfish-handler-formupload/lib/thingfish/handler/formupload.rb

    r499 r572  
    122122 
    123123        files = [] 
    124         request.each_body( true ) do |body, metadata| 
     124        request.each_body do |body, metadata| 
     125 
     126            # Store each primary resource 
    125127            uuid = self.daemon.store_resource( body, metadata ) 
    126128            metadata[:uuid] = uuid 
     129 
     130            # Store any related resources, linked to the primary 
     131            self.daemon.store_related_resources( body, uuid, request ) 
     132 
    127133            files << [ uuid, metadata ] 
    128134        end 
  • thingfish/trunk/plugins/thingfish-handler-formupload/spec/thingfish/handler/formupload_spec.rb

    r493 r572  
    177177            and_return( TEST_UUID ) 
    178178 
     179        mockdaemon.should_receive( :store_related_resources ). 
     180            with( upload1, TEST_UUID, @request ) 
     181 
    179182        @response.should_receive( :status= ).with( HTTP::OK ) 
    180183        @response.should_receive( :body= ).with( [ [TEST_UUID, metadata] ] ) 
  • thingfish/trunk/spec/thingfish/daemon_spec.rb

    r568 r572  
    5151    include ThingFish::SpecHelpers 
    5252     
    53     before(:all) do 
    54         setup_logging( :fatal ) 
    55     end 
    56      
    57  
    5853    before( :each ) do 
    5954        # Have to set up logging each time, 'cause Daemon alters it in some examples 
     
    720715 
    721716     
    722             it "knows how to purge related resources" do 
     717            it "knows how to purge specific related resources" do 
    723718                filestore = mock( "filestore", :null_object => true ) 
    724719                @daemon.instance_variable_set( :@filestore, filestore ) 
     
    728723                search_criteria = { 
    729724                    :related_to => TEST_UUID, 
    730                     :relation   => 'appended
     725                    :relation   => 'thumbnail
    731726                } 
    732727                metastore.should_receive( :find_by_exact_properties ). 
     
    739734                filestore.should_receive( :delete ).with( TEST_UUID3 ) 
    740735                 
    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 
    745763            it "doesn't propagate errors that occur while storing a related resource" do 
    746764                related_body = mock( "related body IO" )