# Path: folivora/utils/pypi.py
# DEFAULT_SERVER = 'http://pypi.python.org/pypi/'
# 
# class CheeseShop(object):
# 
#     def __init__(self, server=DEFAULT_SERVER):
#         self.xmlrpc = xmlrpclib.Server(server)
# 
#     def get_package_versions(self, package_name):
#         """Fetch list of available versions for a package.
# 
#         :param package_name: Name of the package to query.
#         """
#         return self.xmlrpc.package_releases(package_name)
# 
#     def get_package_list(self):
#         """Fetch the master list of package names."""
#         return self.xmlrpc.list_packages()
# 
#     def search(self, spec, operator):
#         """Query using search spec."""
#         return self.xmlrpc.search(spec, operator.lower())
# 
#     def get_changelog(self, hours, force_seconds=False):
#         """Query the changelog.
# 
#         :param hours: Hours from now to specify the changelog size.
#         :param force_seconds: Force that `hours` are the seconds to use.
#         """
#         seconds = get_seconds(hours) if not force_seconds else hours
#         return self.xmlrpc.changelog(seconds)
# 
#     def get_updated_releases(self, hours, force_seconds):
#         """Query all updated releases within `hours`.
# 
#         :param hours: Specify the number of hours to find updated releases.
#         :param force_seconds: Force that `hours` are the seconds to use.
#         """
#         seconds = get_seconds(hours) if not force_seconds else hours
#         return self.xmlrpc.updated_releases(seconds)
# 
#     def get_release_urls(self, package_name, version):
#         """Query for all available release urls of `package_name`.
# 
#         :param package_name: Name of the package.
#         :param version: Version of the package.
#         """
#         return self.xmlrpc.release_urls(package_name, version)
# 
#     def get_release_data(self, package_name, version=None):
#         """Query for specific release data.
# 
#         :param package_name: Name of the package.
#         :param version: Version to query the data. If `None`, it's latest
#                         version will be used.
#         """
#         if version is None:
#             versions = self.get_package_versions(package_name)
#             if not versions:
#                 return {}
#             version = versions[-1]
#         return self.xmlrpc.release_data(package_name, version)
# 
# def normalize_name(name):
#     return pkg_resources.safe_name(name).lower()


import time
import urlparse
import datetime
import pytz
from django.conf import settings
from django.db import models
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import make_aware, now
from django.contrib.auth.models import User
from django_orm.postgresql import hstore
from .utils.pypi import DEFAULT_SERVER, CheeseShop, normalize_name
        from .tasks import sync_project

    def create_logentry(self, type, action, user=None, **kwargs):
        Log.objects.create(project=self, type=type,
                           action=action, data=kwargs, user=user)

    @property
    def requirements(self):
        query = ProjectDependency.objects.filter(project=self) \
                                         .select_related('package') \
                                         .order_by('package__name')
        return "\n".join([d.dependency_string for d in query])

    @property
    def requirement_dict(self):
        query = ProjectDependency.objects.filter(project=self) \
                                         .select_related('package')
        return dict((d.package.name, d.version) for d in query)

    def process_changes(self, user, remove=None, change=None, add=None):
        log_entries = []

        remove = remove if remove else []
        change = change if change else []
        add = add if add else []

        for package_id, version in add:
            log_entries.append(Log(type='project_dependency', action='add',
                                   project_id=self.pk, package_id=package_id,
                                   user=user, data={'version': version}))
        for package_id, version in remove:

# Path: folivora/utils/pypi.py
# DEFAULT_SERVER = 'http://pypi.python.org/pypi/'
# 
# class CheeseShop(object):
# 
#     def __init__(self, server=DEFAULT_SERVER):
#         self.xmlrpc = xmlrpclib.Server(server)
# 
#     def get_package_versions(self, package_name):
#         """Fetch list of available versions for a package.
# 
#         :param package_name: Name of the package to query.
#         """
#         return self.xmlrpc.package_releases(package_name)
# 
#     def get_package_list(self):
#         """Fetch the master list of package names."""
#         return self.xmlrpc.list_packages()
# 
#     def search(self, spec, operator):
#         """Query using search spec."""
#         return self.xmlrpc.search(spec, operator.lower())
# 
#     def get_changelog(self, hours, force_seconds=False):
#         """Query the changelog.
# 
#         :param hours: Hours from now to specify the changelog size.
#         :param force_seconds: Force that `hours` are the seconds to use.
#         """
#         seconds = get_seconds(hours) if not force_seconds else hours
#         return self.xmlrpc.changelog(seconds)
# 
#     def get_updated_releases(self, hours, force_seconds):
#         """Query all updated releases within `hours`.
# 
#         :param hours: Specify the number of hours to find updated releases.
#         :param force_seconds: Force that `hours` are the seconds to use.
#         """
#         seconds = get_seconds(hours) if not force_seconds else hours
#         return self.xmlrpc.updated_releases(seconds)
# 
#     def get_release_urls(self, package_name, version):
#         """Query for all available release urls of `package_name`.
# 
#         :param package_name: Name of the package.
#         :param version: Version of the package.
#         """
#         return self.xmlrpc.release_urls(package_name, version)
# 
#     def get_release_data(self, package_name, version=None):
#         """Query for specific release data.
# 
#         :param package_name: Name of the package.
#         :param version: Version to query the data. If `None`, it's latest
#                         version will be used.
#         """
#         if version is None:
#             versions = self.get_package_versions(package_name)
#             if not versions:
#                 return {}
#             version = versions[-1]
#         return self.xmlrpc.release_data(package_name, version)
# 
# def normalize_name(name):
#     return pkg_resources.safe_name(name).lower()


# Path: folivora/models.py
import time
import urlparse
import datetime
import pytz
from django.conf import settings
from django.db import models
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import make_aware, now
from django.contrib.auth.models import User
from django_orm.postgresql import hstore
from .utils.pypi import DEFAULT_SERVER, CheeseShop, normalize_name
        from .tasks import sync_project


    def create_logentry(self, type, action, user=None, **kwargs):
        Log.objects.create(project=self, type=type,
                           action=action, data=kwargs, user=user)

    @property
    def requirements(self):
        query = ProjectDependency.objects.filter(project=self) \
                                         .select_related('package') \
                                         .order_by('package__name')
        return "\n".join([d.dependency_string for d in query])

    @property
    def requirement_dict(self):
        query = ProjectDependency.objects.filter(project=self) \
                                         .select_related('package')
        return dict((d.package.name, d.version) for d in query)

    def process_changes(self, user, remove=None, change=None, add=None):
        log_entries = []

        remove = remove if remove else []
        change = change if change else []
        add = add if add else []

        for package_id, version in add:
            log_entries.append(Log(type='project_dependency', action='add',
                                   project_id=self.pk, package_id=package_id,
                                   user=user, data={'version': version}))
        for package_id, version in remove:

            log_entries.append(Log(type='project_dependency', action='remove',