コード例 #1
0
 def test3_changeset(self):
     src = ChangeSet()
     src.add( ResourceChange('a',timestamp=1) )
     src.add( ResourceChange('b',timestamp=2) )
     src.add( ResourceChange('c',timestamp=3) )
     src.add( ResourceChange('d',timestamp=4)) 
     src.add( ResourceChange('e',timestamp=5) )
     self.assertEqual(len(src), 5, "5 things in src")
コード例 #2
0
 def generate(self):
     """Generates an inventory of changes"""
     changeset = ChangeSet()
     for change in self.changes:
         changeset.add(change)
     changeset.capabilities[self.current_changeset_uri()] = {
             "rel": "current http://www.openarchives.org/rs/changeset"}
     if self.previous_changeset_uri() is not None:
         changeset.capabilities[self.previous_changeset_uri()] = {
             "rel": "previous http://www.openarchives.org/rs/changeset"}
     return changeset
コード例 #3
0
 def generate(self, from_changeid=None):
     """Generates an inventory of changes"""
     if from_changeid==None:
         from_changeid=self.first_change_id
     from_changeid = int(from_changeid)
     changeset = ChangeSet()
     for change in self.changes_from(from_changeid):
         changeset.add(change)
     changeset.capabilities[self.next_changeset_uri()] = {
             "rel": "next http://www.openarchives.org/rs/changeset"}
     changeset.capabilities[self.current_changeset_uri(from_changeid)] = {
             "rel": "current http://www.openarchives.org/rs/changeset"}
     return changeset
コード例 #4
0
 def test1_set_with_repeats(self):
     src = ChangeSet()
     src.add( ResourceChange('a',timestamp=1) )
     src.add( ResourceChange('b',timestamp=1) )
     src.add( ResourceChange('c',timestamp=1) )
     src.add( ResourceChange('a',timestamp=2) )
     src.add( ResourceChange('b',timestamp=2) )
     self.assertEqual(len(src), 5, "5 changes in changeset")
コード例 #5
0
ファイル: client.py プロジェクト: pedak/sync-oai
 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)
コード例 #6
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')
コード例 #7
0
 def test2_with_repeats_again(self):
     r1 = ResourceChange(uri='a',size=1)
     r2 = ResourceChange(uri='b',size=2)
     i = ChangeSet()
     i.add(r1)
     i.add(r2)
     self.assertEqual( len(i), 2 )
     # Can add another ResourceChange with same URI
     r1d = ResourceChange(uri='a',size=10)
     i.add(r1d)
     self.assertEqual( len(i), 3 )
コード例 #8
0
 def test4_iter(self):
     i = ChangeSet()
     i.add( ResourceChange('a',timestamp=1) )
     i.add( ResourceChange('b',timestamp=2) )
     i.add( ResourceChange('c',timestamp=3) )
     i.add( ResourceChange('d',timestamp=4) )
     resources=[]
     for r in i:
         resources.append(r)
     self.assertEqual(len(resources), 4)
     self.assertEqual( resources[0].uri, 'a')
     self.assertEqual( resources[3].uri, 'd')
コード例 #9
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)