# Path: locksmith/common.py
# def enum(name, **enums):
#     def __iter__(self):
# def get_signature(params, signkey):
# def apicall(url, signkey, **params):
# def cache(seconds = 900):
#     def doCache(f):
#         def x(*args, **kwargs):
#     E = type(name or 'Enum', (), enums)
# API_OPERATING_STATUSES = (
#     (1, 'Normal'),
#     (2, 'Degraded Service'),
#     (3, 'Service Disruption'),
#     (4, 'Undergoing Maintenance')
# )
# API_STATUSES = enum('ApiStatuses',
#                     Stealth=0,
#                     Active=1,
#                     Deprecated=2,
#                     Disabled=3)
# KEY_STATUSES = (
#     ('U', 'Unactivated'),
#     ('A', 'Active'),
#     ('S', 'Suspended')
# )
# UNPUBLISHED, PUBLISHED, NEEDS_UPDATE = range(3)
# PUB_STATUSES = (
#     (UNPUBLISHED, 'Unpublished'),
#     (PUBLISHED, 'Published'),
#     (NEEDS_UPDATE, 'Needs Update'),
# )


import urllib2
from urlparse import urljoin
from locksmith.common import apicall, UNPUBLISHED, PUBLISHED, NEEDS_UPDATE
from celery.task import task
from django.conf import settings



ReplicatedApiNames = getattr(settings, 'LOCKSMITH_REPLICATED_APIS', [])

@task(max_retries=5)
def push_key(key, replicate_too=True):
    if replicate_too:
        for kps in key.pub_statuses.filter(api__push_enabled=True):
            if kps.api.name in ReplicatedApiNames:

# Path: locksmith/common.py
# def enum(name, **enums):
#     def __iter__(self):
# def get_signature(params, signkey):
# def apicall(url, signkey, **params):
# def cache(seconds = 900):
#     def doCache(f):
#         def x(*args, **kwargs):
#     E = type(name or 'Enum', (), enums)
# API_OPERATING_STATUSES = (
#     (1, 'Normal'),
#     (2, 'Degraded Service'),
#     (3, 'Service Disruption'),
#     (4, 'Undergoing Maintenance')
# )
# API_STATUSES = enum('ApiStatuses',
#                     Stealth=0,
#                     Active=1,
#                     Deprecated=2,
#                     Disabled=3)
# KEY_STATUSES = (
#     ('U', 'Unactivated'),
#     ('A', 'Active'),
#     ('S', 'Suspended')
# )
# UNPUBLISHED, PUBLISHED, NEEDS_UPDATE = range(3)
# PUB_STATUSES = (
#     (UNPUBLISHED, 'Unpublished'),
#     (PUBLISHED, 'Published'),
#     (NEEDS_UPDATE, 'Needs Update'),
# )


# Path: locksmith/hub/tasks.py
import urllib2
from urlparse import urljoin
from locksmith.common import apicall, UNPUBLISHED, PUBLISHED, NEEDS_UPDATE
from celery.task import task
from django.conf import settings




ReplicatedApiNames = getattr(settings, 'LOCKSMITH_REPLICATED_APIS', [])

@task(max_retries=5)
def push_key(key, replicate_too=True):
    if replicate_too:
        for kps in key.pub_statuses.filter(api__push_enabled=True):
            if kps.api.name in ReplicatedApiNames:

                replicate_key.delay(key, kps.api)