# Path: papaye/factories/root.py
# def user_root_factory(request_or_connection):
#     if isinstance(request_or_connection, (Request, DummyRequest)):
#         conn = get_connection(request_or_connection)
#     else:
#         conn = request_or_connection
#     zodb_root = conn.root()
#     if not '{}_root'.format(APP_NAME) in zodb_root:
#         return None
#     return zodb_root[APP_ROOT_NAME]['user']
# 
# def repository_root_factory(request_or_connection):
#     if isinstance(request_or_connection, (Request, DummyRequest)):
#         conn = get_connection(request_or_connection)
#     else:
#         conn = request_or_connection
#     zodb_root = conn.root()
#     if not '{}_root'.format(APP_NAME) in zodb_root:
#         return None
#     return zodb_root[APP_ROOT_NAME]['repository']
# 
# APP_ROOT_NAME = '{}_root'.format(APP_NAME)
# 
# Path: papaye/schemas.py
# class Metadata(colander.MappingSchema):
#     version = colander.SchemaNode(String(), missing=None)
#     author = colander.SchemaNode(String(), missing=None)
#     author_email = colander.SchemaNode(String(), missing=None)
#     home_page = colander.SchemaNode(String(), missing=None)
#     keywords = colander.SchemaNode(Tags(), default=[])
#     license = colander.SchemaNode(String(), missing=None)
#     summary = colander.SchemaNode(String(), missing=None)
#     maintainer = colander.SchemaNode(String(), missing=None)
#     maintainer_email = colander.SchemaNode(String(), missing=None)
#     description = colander.SchemaNode(Description(), default=None)
#     platform = colander.SchemaNode(String(), missing=None)
#     classifiers = colander.SchemaNode(Classifiers(), default=[])
#     name = colander.SchemaNode(String(), missing=None)


import datetime
import hashlib
import io
import json
import logging
import magic
import pkg_resources
import requests
from BTrees.OOBTree import OOBTree
from ZODB.blob import Blob
from beaker.cache import cache_region
from persistent import Persistent
from pkg_resources import parse_version
from pyramid.security import Allow, ALL_PERMISSIONS, Everyone
from pyramid.threadlocal import get_current_registry
from pyramid_zodbconn import db_from_uri
from repoze.evolution import ZODBEvolutionManager
from requests.exceptions import ConnectionError
from pytz import utc
from papaye.factories.root import user_root_factory, repository_root_factory, APP_ROOT_NAME
from papaye.schemas import Metadata
    def repository_is_up_to_date(self, last_remote_release):
        if not last_remote_release:
            return True
        remote_version = parse_version(last_remote_release)

        local_versions = [release.version for release in self.releases.values()]
        for version in local_versions:
            if parse_version(version) >= remote_version:
                return True
        return False

    @classmethod
    def by_name(cls, name, request):
        root = repository_root_factory(request)
        return root[name] if name in root else None

    def get_last_release(self):
        max_version = max([parse_version(version) for version in self.releases.keys()])
        for version, release in self.releases.items():
            if parse_version(version) == max_version:
                return release


class Release(Persistent):

    def __init__(self, name, version, metadata):
        self.__name__ = name
        self.release_files = OOBTree()
        self.version = version
        self.original_metadata = metadata

# Path: papaye/factories/root.py
# def user_root_factory(request_or_connection):
#     if isinstance(request_or_connection, (Request, DummyRequest)):
#         conn = get_connection(request_or_connection)
#     else:
#         conn = request_or_connection
#     zodb_root = conn.root()
#     if not '{}_root'.format(APP_NAME) in zodb_root:
#         return None
#     return zodb_root[APP_ROOT_NAME]['user']
# 
# def repository_root_factory(request_or_connection):
#     if isinstance(request_or_connection, (Request, DummyRequest)):
#         conn = get_connection(request_or_connection)
#     else:
#         conn = request_or_connection
#     zodb_root = conn.root()
#     if not '{}_root'.format(APP_NAME) in zodb_root:
#         return None
#     return zodb_root[APP_ROOT_NAME]['repository']
# 
# APP_ROOT_NAME = '{}_root'.format(APP_NAME)
# 
# Path: papaye/schemas.py
# class Metadata(colander.MappingSchema):
#     version = colander.SchemaNode(String(), missing=None)
#     author = colander.SchemaNode(String(), missing=None)
#     author_email = colander.SchemaNode(String(), missing=None)
#     home_page = colander.SchemaNode(String(), missing=None)
#     keywords = colander.SchemaNode(Tags(), default=[])
#     license = colander.SchemaNode(String(), missing=None)
#     summary = colander.SchemaNode(String(), missing=None)
#     maintainer = colander.SchemaNode(String(), missing=None)
#     maintainer_email = colander.SchemaNode(String(), missing=None)
#     description = colander.SchemaNode(Description(), default=None)
#     platform = colander.SchemaNode(String(), missing=None)
#     classifiers = colander.SchemaNode(Classifiers(), default=[])
#     name = colander.SchemaNode(String(), missing=None)


# Path: papaye/evolve/models/snapshot1.py
import datetime
import hashlib
import io
import json
import logging
import magic
import pkg_resources
import requests
from BTrees.OOBTree import OOBTree
from ZODB.blob import Blob
from beaker.cache import cache_region
from persistent import Persistent
from pkg_resources import parse_version
from pyramid.security import Allow, ALL_PERMISSIONS, Everyone
from pyramid.threadlocal import get_current_registry
from pyramid_zodbconn import db_from_uri
from repoze.evolution import ZODBEvolutionManager
from requests.exceptions import ConnectionError
from pytz import utc
from papaye.factories.root import user_root_factory, repository_root_factory, APP_ROOT_NAME
from papaye.schemas import Metadata

    def repository_is_up_to_date(self, last_remote_release):
        if not last_remote_release:
            return True
        remote_version = parse_version(last_remote_release)

        local_versions = [release.version for release in self.releases.values()]
        for version in local_versions:
            if parse_version(version) >= remote_version:
                return True
        return False

    @classmethod
    def by_name(cls, name, request):
        root = repository_root_factory(request)
        return root[name] if name in root else None

    def get_last_release(self):
        max_version = max([parse_version(version) for version in self.releases.keys()])
        for version, release in self.releases.items():
            if parse_version(version) == max_version:
                return release


class Release(Persistent):

    def __init__(self, name, version, metadata):
        self.__name__ = name
        self.release_files = OOBTree()
        self.version = version
        self.original_metadata = metadata

        self.metadata = Metadata().deserialize(metadata)