def test20_as_xml(self): rl = ResourceList() rl.add( Resource('a',timestamp=1) ) rl.add( Resource('b',timestamp=2) ) xml = rl.as_xml() self.assertTrue( re.search(r'<rs:md .*capability="resourcelist"', xml), 'XML has capability' ) self.assertTrue( re.search(r'<url><loc>a</loc><lastmod>1970-01-01T00:00:01Z</lastmod></url>', xml), 'XML has resource a' )
def test_build_ex_01(self): """Simple Resource List document """ rl = ResourceList() rl.md_at = '2013-01-03T09:00:00Z' rl.add( Resource('http://example.com/res1') ) rl.add( Resource('http://example.com/res2') ) ex_xml = self._open_ex('resourcesync_ex_1').read() self._assert_xml_equal( rl.as_xml(), ex_xml )
def test20_as_xml(self): rl = ResourceList() rl.add( Resource('a',timestamp=1) ) rl.add( Resource('b',timestamp=2) ) xml = rl.as_xml() print xml self.assertTrue( re.search(r'<rs:md .*capability="resourcelist"', xml), 'XML has capability' ) self.assertTrue( re.search(r'<url><loc>a</loc><lastmod>1970-01-01T00:00:01Z</lastmod></url>', xml), 'XML has resource a' )
def test20_as_xml(self): rl = ResourceList() rl.add( Resource('a',timestamp=1) ) rl.add( Resource('b',timestamp=2) ) xml = rl.as_xml() print xml self.assertTrue( re.search(r'<rs:md .*capability="resourcelist"', xml), 'XML has capability' ) self.assertTrue( re.search(r'<rs:md .*modified="\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\dZ"', xml), 'XML has modified to seconds precision (and not more)' ) self.assertTrue( re.search(r'<url><loc>a</loc><lastmod>1970-01-01T00:00:01Z</lastmod></url>', xml), 'XML has resource a' )
def test_build_ex_02(self): """Slightly more complex Resource List document """ rl = ResourceList() rl.md_at = '2013-01-03T09:00:00Z' rl.add( Resource(uri='http://example.com/res1', lastmod='2013-01-02T13:00:00Z', md5='1584abdf8ebdc9802ac0c6a7402c03b6') ) r2 = Resource(uri='http://example.com/res2', lastmod='2013-01-02T14:00:00Z', md5='1e0d5cb8ef6ba40c99b14c0237be735e') r2.link_set(rel="duplicate",href="http://mirror.example.com/res2") rl.add( r2 ) ex_xml = self._open_ex('resourcesync_ex_2').read() self._assert_xml_equal( rl.as_xml(), ex_xml )
def test_build_ex_15(self): """Resource List Index with metadata""" rl = ResourceList(resources_class=ResourceListOrdered) #order in example is non-canonical rl.sitemapindex=True rl.up='http://example.com/dataset1/capabilitylist.xml' rl.md_at="2013-01-03T09:00:00Z" rl.md_completed="2013-01-03T09:10:00Z" rl.add( Resource( uri='http://example.com/resourcelist1.xml', md_at='2013-01-03T09:00:00Z' )) rl.add( Resource( uri='http://example.com/resourcelist2.xml', md_at='2013-01-03T09:03:00Z' )) rl.add( Resource( uri='http://example.com/resourcelist3.xml', md_at='2013-01-03T09:07:00Z' )) ex_xml = self._open_ex('resourcesync_ex_15').read() self._assert_xml_equal( rl.as_xml(), ex_xml )
def test_build_ex_08(self): """Simple Resource List Index document This is not something that would usually be created directly but instead would be created as part of the process of writing a large Resource List in multiple files. However, it is possible to create manually. """ rli = ResourceList() rli.sitemapindex=True rli.md_at = '2013-01-03T09:00:00Z' rli.add( Resource(uri='http://example.com/resourcelist-part1.xml') ) rli.add( Resource(uri='http://example.com/resourcelist-part2.xml') ) ex_xml = self._open_ex('resourcesync_ex_8').read() self._assert_xml_equal( rli.as_xml(), ex_xml )
def test_build_ex_16(self): rl = ResourceList() rl.up = 'http://example.com/dataset1/capabilitylist.xml' rl.index = 'http://example.com/dataset1/resourcelist-index.xml' rl.md_at="2013-01-03T09:00:00Z" rl.add( Resource( uri='http://example.com/res3', lastmod='2013-01-02T13:00:00Z', md5='1584abdf8ebdc9802ac0c6a7402c8753', length=4385, mime_type="application/pdf" )) rl.add( Resource( uri='http://example.com/res4', lastmod='2013-01-02T14:00:00Z', md5='4556abdf8ebdc9802ac0c6a7402c9881', length=883, mime_type="image/png" )) ex_xml = self._open_ex('resourcesync_ex_16').read() self._assert_xml_equal( rl.as_xml(), ex_xml )
def test_build_ex_14(self): """Resource List with 2 entries and some metadata""" rl = ResourceList() rl.up='http://example.com/dataset1/capabilitylist.xml' rl.md_at="2013-01-03T09:00:00Z" rl.md_completed="2013-01-03T09:01:00Z" rl.add( Resource( uri='http://example.com/res1', lastmod='2013-01-02T13:00:00Z', md5='1584abdf8ebdc9802ac0c6a7402c03b6', length=8876, mime_type="text/html" )) rl.add( Resource( uri='http://example.com/res2', lastmod='2013-01-02T14:00:00Z', md5='1e0d5cb8ef6ba40c99b14c0237be735e', sha256='854f61290e2e197a11bc91063afce22e43f8ccc655237050ace766adc68dc784', length=14599, mime_type="application/pdf" )) ex_xml = self._open_ex('resourcesync_ex_14').read() self._assert_xml_equal( rl.as_xml(), ex_xml )
continue _, raw_ts = filename.split("-") ts = ( raw_ts[:4] + "-" + raw_ts[4:6] + "-" + raw_ts[6:8] + "T" + raw_ts[8:10] + ":" + raw_ts[10:12] + ":" + raw_ts[12:14] + "Z" ) timestamps.append(ts) rl.add(Resource(args.resource_url + filename, lastmod=ts)) # Print to file at args.resource_dir + "/resource-list.xml" resource_list_file = open(args.resource_dir + "/resource-list.xml", "w") resource_list_file.write(rl.as_xml()) resource_list_file.close() print "Wrote resource list to: " + args.resource_dir + "/resource-list.xml" timestamps.sort() caps = CapabilityList() caps.add_capability(rl, args.resource_url + "resource-list.xml") if len(timestamps) > 0: caps.md['from'] = timestamps[0] # Print to file at args.resource_dir + "/capability-list.xml" capability_list_file = open(args.resource_dir + "/capability-list.xml", "w") capability_list_file.write(caps.as_xml()) capability_list_file.close()
from resync.resource_list import ResourceList from resync.resource import Resource from resync.sitemap import Sitemap rl = ResourceList() rl.add(Resource('http://example.com/res1', lastmod='2013-01-01')) rl.add(Resource('http://example.com/res2', lastmod='2013-01-02')) print rl.as_xml(pretty_xml=True)
raise IOError(args.resource_dir + " is not a directory") rl = ResourceList() timestamps = [] for filename in listdir(args.resource_dir): if filename[:len("rdfpatch-")] != "rdfpatch-": continue _, raw_ts = filename.split("-") ts = (raw_ts[:4] + "-" + raw_ts[4:6] + "-" + raw_ts[6:8] + "T" + raw_ts[8:10] + ":" + raw_ts[10:12] + ":" + raw_ts[12:14] + "Z") timestamps.append(ts) rl.add(Resource(args.resource_url + filename, lastmod=ts)) # Print to file at args.resource_dir + "/resource-list.xml" resource_list_file = open(args.resource_dir + "/resource-list.xml", "w") resource_list_file.write(rl.as_xml()) resource_list_file.close() print "Wrote resource list to: " + args.resource_dir + "/resource-list.xml" timestamps.sort() caps = CapabilityList() caps.add_capability(rl, args.resource_url + "resource-list.xml") if len(timestamps) > 0: caps.md['from'] = timestamps[0] # Print to file at args.resource_dir + "/capability-list.xml" capability_list_file = open(args.resource_dir + "/capability-list.xml", "w") capability_list_file.write(caps.as_xml()) capability_list_file.close()
from resync.resource_list import ResourceList from resync.resource import Resource from resync.sitemap import Sitemap rl = ResourceList() rl.add( Resource('http://example.com/res1', lastmod='2013-01-01') ) rl.add( Resource('http://example.com/res2', lastmod='2013-01-02') ) print rl.as_xml(pretty_xml=True)