Exemple #1
0
 def test_build_ex_23(self):
     cdm = ChangeDumpManifest()
     cdm.up = "http://example.com/dataset1/capabilitylist.xml"
     cdm.md_from = "2013-01-02T00:00:00Z"
     cdm.md_until = "2013-01-03T00:00:00Z"
     cdm.add( Resource(uri="http://example.com/res7.html",
                       lastmod="2013-01-02T12:00:00Z",
                       change="created",
                       md5="1c1b0e264fa9b7e1e9aa6f9db8d6362b",
                       length=4339,
                       mime_type="text/html",
                       path="/changes/res7.html") )
     cdm.add( Resource(uri="http://example.com/res9.pdf",
                       lastmod="2013-01-02T13:00:00Z",
                       change="updated",
                       md5="f906610c3d4aa745cb2b986f25b37c5a",
                       length=38297,
                       mime_type="application/pdf",
                       path="/changes/res9.pdf") )
     cdm.add( Resource(uri="http://example.com/res5.tiff",
                       lastmod="2013-01-02T19:00:00Z",
                       change="deleted") )
     cdm.add( Resource(uri="http://example.com/res7.html",
                       lastmod="2013-01-02T20:00:00Z",
                       change="updated",
                       md5="0988647082c8bc51778894a48ec3b576",
                       length="5426", #should also take string
                       mime_type="text/html",
                       path="/changes/res7-v2.html") )
     self._assert_xml_equal_ex( cdm.as_xml(), 'resourcesync_ex_23' )
Exemple #2
0
    def get_change_dump_manifest_xml(self, record_id):
        """Get change dump manifest xml.

        :param record_id: Identifier of record
        :return xml
        """
        if not self._is_record_in_index(record_id) or not self._validation():
            return None
        cdm = ChangeDumpManifest()
        cdm.up = '{}resync/{}/changedump.xml'.format(request.url_root,
                                                     self.repository_id)
        if self.change_dump_manifest:
            prev_id, prev_ver_id = record_id.split(".")
            current_record = WekoRecord.get_record_by_pid(record_id)
            from .utils import get_pid
            prev_record_pid = get_pid('{}.{}'.format(prev_id,
                                                     str(int(prev_ver_id) -
                                                         1)))
            if prev_record_pid:
                prev_record = WekoRecord.get_record(
                    id_=prev_record_pid.object_uuid)
            else:
                prev_record = None
            if current_record:
                list_file = [file for file in current_record.files]
                current_checksum = [
                    file.info().get('checksum')
                    for file in current_record.files
                ]
                prev_checksum = []
                if prev_record:
                    list_file.extend([file for file in prev_record.files])
                    prev_checksum = [
                        file.info().get('checksum')
                        for file in prev_record.files
                    ]
                for file in list_file:
                    file_info = file.info()
                    change = None
                    if file_info.get('checksum') in prev_checksum:
                        if file_info.get('checksum') in current_checksum:
                            change = None
                        if file_info.get('checksum') not in current_checksum:
                            change = 'deleted'
                    else:
                        if file_info.get('checksum') in current_checksum:
                            change = 'created'
                    path = 'recid_{}/{}'.format(current_record.get('recid'),
                                                file_info.get('key'))
                    lastmod = str(datetime.datetime.utcnow().replace(
                        tzinfo=datetime.timezone.utc).isoformat())
                    if change:
                        re = Resource(
                            '{}record/{}/files/{}'.format(
                                request.url_root, current_record.get('recid'),
                                file_info.get('key')),
                            lastmod=lastmod,
                            sha256=file_info.get('checksum').split(':')[1],
                            length=str(file_info.get('size')),
                            path=path if change != 'delete' else '',
                            change=change)
                        cdm.add(re)
        return cdm.as_xml()