def testUpdateDescriptors_partialPool(self):
        provider = MetadataSourceAggregator(sources, map)

        # Init newId just with some attributes of id1
        attributeIds = [
            "Song::Artist",
            "Song::Title",
        ]
        poolToCopy = provider.QueryDescriptors('id1', attributeIds)
        provider.UpdateDescriptors('newId', poolToCopy)
        # Merge them with some others from id2
        poolToCopy = provider.QueryDescriptors('id2', attributeIds)
        attributeIds = [
            "Song::Artist",
        ]
        provider.UpdateDescriptors('newId', poolToCopy, attributeIds)

        attributeIds = [
            "Song::Artist",
            "Song::Title",
        ]
        descriptors = provider.QueryDescriptors('newId', attributeIds)
        self.assertEquals(
            "<?xml version='1.0' encoding='UTF-8'?>\n" +
            "<DescriptorsPool>\n" + "  <ScopePool name='Song' size='1'>\n" +
            "    <AttributePool name='Artist'>Artist 2</AttributePool>\n" +
            "    <AttributePool name='Title'>Title 1</AttributePool>\n" +
            "  </ScopePool>\n" + "</DescriptorsPool>\n" + "",
            self.dumpXml(descriptors))
    def testUpdateDescriptors_noDescriptor(self):
        provider = MetadataSourceAggregator(sources, map)
        descriptors = provider.QueryDescriptors('id1', [])
        provider.UpdateDescriptors('newId', descriptors)

        descriptors = provider.QueryDescriptors('newId', [])
        self.assertEquals(
            "<?xml version='1.0' encoding='UTF-8'?>\n" +
            "<DescriptorsPool/>\n" + "", self.dumpXml(descriptors))
 def testUpdateDescriptors_singleDescriptor(self):
     attributeIds = ["Song::Artist"]
     provider = MetadataSourceAggregator(sources, map)
     poolToCopy = provider.QueryDescriptors('id1', attributeIds)
     provider.UpdateDescriptors('newId', poolToCopy)
     descriptors = provider.QueryDescriptors('newId', attributeIds)
     self.assertEquals(
         "<?xml version='1.0' encoding='UTF-8'?>\n" +
         "<DescriptorsPool>\n" + "  <ScopePool name='Song' size='1'>\n" +
         "    <AttributePool name='Artist'>Artist 1</AttributePool>\n" +
         "  </ScopePool>\n" + "</DescriptorsPool>\n" + "",
         self.dumpXml(descriptors))
 def testQueryDescriptors_multipleDescriptors(self):
     provider = MetadataSourceAggregator(sources, map)
     descriptors = provider.QueryDescriptors('id1', [
         "Song::Artist",
         "Song::Title",
         "Song::DynamicComplexity",
     ])
     self.assertEquals(
         "<?xml version='1.0' encoding='UTF-8'?>\n" +
         "<DescriptorsPool>\n" + "  <ScopePool name='Song' size='1'>\n" +
         "    <AttributePool name='Artist'>Artist 1</AttributePool>\n" +
         "    <AttributePool name='Title'>Title 1</AttributePool>\n" +
         "    <AttributePool name='DynamicComplexity'>8.1</AttributePool>\n"
         + "  </ScopePool>\n" + "</DescriptorsPool>\n" + "",
         self.dumpXml(descriptors))
            sys.exit(-1)

        execfile(options.ConfigurationFile)


provider = MetadataSourceAggregator(config.sources,
                                    config.map,
                                    verbose=config.verbose)

if options.printSchema is not None:
    target = sys.stdout if options.printSchema == "-" else open(
        options.printSchema, 'w')
    provider.QuerySchema(provider.AvailableDescriptors()).Dump(target)
    sys.exit()

if not args:
    parser.print_help()
    sys.exit()

#if options.writeback: sys.exit()

for audiofile in args:
    print "Processing %s..." % audiofile
    target = open(audiofile + options.suffix, 'w')
    poolToCopy = provider.QueryDescriptors(audiofile,
                                           provider.AvailableDescriptors())
    poolToCopy.Dump(target)
    if options.writeback:
        provider.UpdateDescriptors(audiofile, poolToCopy)
    target.close()