Пример #1
0
    def test_smart_merge(self, mock):
        from papaye.proxy import PyPiProxy
        from papaye.factories import repository_root_factory
        from papaye.models import Package, Release, ReleaseFile
        mock.return_value = self.pypi_response
        root = repository_root_factory(self.request)

        # Existing releases
        root['pyramid'] = Package(name='pyramid')
        root['pyramid']['1.4'] = Release(name='1.4', version='1.4', metadata={})
        root['pyramid']['1.4']['pyramid-1.4.tar.gz'] = ReleaseFile(
            filename='pyramid-1.4.tar.gz',
            content=b'',
            md5_digest='12345'
        )

        package = Package(name='pyramid')
        package['1.5'] = Release(name='1.5', version='1.5', metadata={})
        package['1.5']['pyramid-1.5.tar.gz'] = ReleaseFile(
            filename='pyramid-1.5.tar.gz',
            content=b'',
            md5_digest='12345'
        )

        proxy = PyPiProxy(self.request, 'pyramid')
        result = proxy.smart_merge(root, package)

        self.assertEqual([key for key in result.releases.keys()], ['1.4', '1.5'])
Пример #2
0
    def test_smart_merge_with_existing_release(self, mock):
        from papaye.proxy import PyPiProxy
        from papaye.factories import repository_root_factory
        from papaye.models import Package, Release, ReleaseFile
        mock.return_value = self.pypi_response
        root = repository_root_factory(self.request)

        # Existing releases
        package = Package(name='pyramid')
        package['1.5'] = Release(name='1.5', version='1.5', metadata={})
        package['1.5']['pyramid-1.5.tar.gz'] = ReleaseFile(
            filename='pyramid-1.5.tar.gz', content=b'', md5_digest='12345')

        package = Package(name='pyramid')
        package['1.5'] = Release(name='1.5', version='1.5', metadata={})
        package['1.5']['pyramid-1.5.tar.gz'] = ReleaseFile(
            filename='pyramid-1.5.tar.gz', content=b'', md5_digest='12345')

        proxy = PyPiProxy(self.request, 'pyramid')
        result = proxy.smart_merge(root, package)

        self.assertEqual([key for key in result.releases.keys()], [
            '1.5',
        ])
        self.assertEqual(result['1.5']['pyramid-1.5.tar.gz'].md5_digest,
                         '12345')
Пример #3
0
def download_release_from_pypi(config, package_name, release_name):
    try:
        repository_is_updated = False
        conn = get_connection(config)
        proxy = PyPiProxy(conn, package_name)
        root = repository_root_factory(conn)
        package = proxy.build_repository(release_name=release_name,
                                         with_metadata=True)
        if not package:
            logger.error('Package {} not found on PYPI'.format(package_name))
        for release_file in package[release_name].release_files.values():
            logger.info('Download file "{}"'.format(release_file.filename))
            release_file.set_content(
                requests.get(release_file.pypi_url).content)
            with release_file.content.open() as content:
                binary_content = content.read()
                if hashlib.md5(
                        binary_content).hexdigest() != release_file.md5_digest:
                    continue
            release_file.size = len(binary_content)
            repository_is_updated = True

        package = proxy.smart_merge(root, package)
        if repository_is_updated:
            root[package.name] = package
            for release in package:
                release.__parent__ = package
                for release_file in release:
                    release_file.__parent__ = release

        transaction.commit()
    except:
        transaction.abort()