Exemple #1
0
 def test5_add_changed_resources(self):
     added = Inventory()
     added.add( Resource('a',timestamp=1) )
     added.add( Resource('d',timestamp=4))
     self.assertEqual(len(added), 2, "2 things in added inventory")
     changes = ChangeSet()
     changes.add_changed_resources( added, changetype='created' )
     self.assertEqual(len(changes), 2, "2 things added")
     i = iter(changes)
     first = i.next()
     self.assertEqual(first.uri, 'a', "changes[0].uri=a")
     self.assertEqual(first.timestamp, 1, "changes[0].timestamp=1")
     self.assertEqual(first.changetype, 'created', "changes[0].changetype=created")
     second = i.next()
     self.assertEqual(second.timestamp, 4, "changes[1].timestamp=4")
     self.assertEqual(second.changetype, 'created', "changes[1].changetype=created")
     # Now add some with updated (one same, one diff)
     updated = Inventory()
     updated.add( Resource('a',timestamp=5) )
     updated.add( Resource('b',timestamp=6))
     self.assertEqual(len(updated), 2, "2 things in updated inventory")
     changes.add_changed_resources( updated, changetype='updated' )
     self.assertEqual(len(changes), 4, "4 = 2 old + 2 things updated")
     # Make new inventory from the changes which should not have dupes
     dst = Inventory()
     dst.add( changes, replace=True )
     self.assertEqual(len(dst), 3, "3 unique resources")
     self.assertEqual(dst.resources['a'].timestamp, 5 ) # 5 was later in last the 1
     self.assertEqual(dst.resources['a'].changetype, 'updated')
     self.assertEqual(dst.resources['b'].timestamp, 6)
     self.assertEqual(dst.resources['b'].changetype, 'updated')
     self.assertEqual(dst.resources['d'].timestamp, 4)
     self.assertEqual(dst.resources['d'].changetype, 'created')
Exemple #2
0
 def changeset_sitemap(
     self, outfile=None, ref_sitemap=None, newref_sitemap=None, empty=None, capabilities=None, dump=None
 ):
     changeset = ChangeSet()
     changeset.capabilities = capabilities
     if not empty:
         # 1. Get and parse reference sitemap
         old_inv = self.read_reference_sitemap(ref_sitemap)
         # 2. Depending on whether a newref_sitemap was specified, either read that
         # or build inventory from files on disk
         if newref_sitemap is None:
             # Get inventory from disk
             new_inv = self.inventory
         else:
             new_inv = self.read_reference_sitemap(newref_sitemap, name="new reference")
         # 3. Calculate changeset
         (same, updated, deleted, created) = old_inv.compare(new_inv)
         changeset.add_changed_resources(updated, changetype="UPDATED")
         changeset.add_changed_resources(deleted, changetype="DELETED")
         changeset.add_changed_resources(created, changetype="CREATED")
     # 4. Write out changeset
     s = Sitemap(pretty_xml=True, allow_multifile=self.allow_multifile, mapper=self.mapper)
     if self.max_sitemap_entries is not None:
         s.max_sitemap_entries = self.max_sitemap_entries
     if outfile is None:
         print s.resources_as_xml(changeset, changeset=True)
     else:
         s.write(changeset, basename=outfile, changeset=True)
     self.write_dump_if_requested(changeset, dump)
Exemple #3
0
 def changeset_sitemap(self,
                       outfile=None,
                       ref_sitemap=None,
                       newref_sitemap=None,
                       empty=None,
                       capabilities=None,
                       dump=None):
     changeset = ChangeSet()
     changeset.capabilities = capabilities
     if (not empty):
         # 1. Get and parse reference sitemap
         old_inv = self.read_reference_sitemap(ref_sitemap)
         # 2. Depending on whether a newref_sitemap was specified, either read that
         # or build inventory from files on disk
         if (newref_sitemap is None):
             # Get inventory from disk
             new_inv = self.inventory
         else:
             new_inv = self.read_reference_sitemap(newref_sitemap,
                                                   name='new reference')
         # 3. Calculate changeset
         (same, updated, deleted, created) = old_inv.compare(new_inv)
         changeset.add_changed_resources(updated, changetype='UPDATED')
         changeset.add_changed_resources(deleted, changetype='DELETED')
         changeset.add_changed_resources(created, changetype='CREATED')
     # 4. Write out changeset
     s = Sitemap(pretty_xml=True,
                 allow_multifile=self.allow_multifile,
                 mapper=self.mapper)
     if (self.max_sitemap_entries is not None):
         s.max_sitemap_entries = self.max_sitemap_entries
     if (outfile is None):
         print s.resources_as_xml(changeset, changeset=True)
     else:
         s.write(changeset, basename=outfile, changeset=True)
     self.write_dump_if_requested(changeset, dump)