# Path: mmc/defaults.py
# def get_settings(key, default):
# SUBJECT = get_settings('MMC_SUBJECT', '[MMC] Error: %(host)s: %(script)s')
# SUBJECT_LIMIT = get_settings(
#     'MMC_SUBJECT_LIMIT', '[MMC] Limit exceeded: %(host)s: %(script)s')
# REDIS_CONFIG = get_settings('MMC_REDIS_CONFIG', {
#     'host': 'localhost', 'port': 6379,
#     'db': 0, 'password': None
# })
# MEMCACHED_CONFIG = get_settings('MMC_MEMCACHED_CONFIG', {
#     'servers': ['127.0.0.1:11211'], 'debug': 0
# })
# LOCK_TYPE = get_settings('MMC_LOCK_TYPE', 'FileLock')
# SENTRY_NOTIFICATION = get_settings('MMC_SENTRY_NOTIFICATION', True)
# EMAIL_NOTIFICATION = get_settings('MMC_EMAIL_NOTIFICATION', True)
# DEFAULT_LOCK_TIME = get_settings('MMC_DEFAULT_LOCK_TIME', 3600)
# CLEANUP_IGNORED = get_settings('MMC_CLEANUP_IGNORED', True)
# FORCE_IGNORE = get_settings('MMC_FORCE_IGNORE', ['shell'])
# READ_STDOUT = get_settings('MMC_READ_STDOUT', False)
# MAIL_MODULE = get_settings('MMC_MAIL_MODULE', 'django.core.mail')
# EMAIL_FROM = get_settings('MMC_EMAIL_FROM', settings.DEFAULT_FROM_EMAIL)
# REAL_TIME_UPDATE = get_settings('MMC_REAL_TIME_UPDATE', 3)
# HOSTNAME = get_settings('MMC_HOSTNAME', gethostname())
# DEFAULT_ONE_COPY = get_settings('MMC_DEFAULT_ONE_COPY', False)
# NOTIFICATION_LIMIT = get_settings('MMC_NOTIFICATION_LIMIT', 50)
# NEW_SCRIPT_NOTIFICATION = get_settings('MMC_NEW_SCRIPT_NOTIFICATION', True)


import tempfile
import datetime
import random
import time
import sys
import os
from mmc import defaults
            from mmc.models import MMCLog
        from redis import StrictRedis
            from memcache import Client
            from pylibmc import Client
    @staticmethod
    def random_wait():
        random.seed()
        time.sleep(random.choice([random.uniform(0, 3) for i in range(10)]))


class FileLock(AbstractLock):
    def unlock(self):
        if self.is_run():
            os.unlink(self.get_lock_file())

    def lock(self):
        open(self.get_lock_file(), 'w').close()

    def _cleanup_lock(self):
        if os.path.exists(self.get_lock_file()):
            created = datetime.datetime.fromtimestamp(
                os.path.getctime(self.get_lock_file()))
            seconds = (datetime.datetime.now() - created).seconds
            if seconds > self._lock_time:
                os.unlink(self.get_lock_file())

    def is_run(self):
        self._cleanup_lock()
        return os.path.exists(self.get_lock_file())


class RedisLock(AbstractLock):
    def __init__(self, script):


# Path: mmc/defaults.py
# def get_settings(key, default):
# SUBJECT = get_settings('MMC_SUBJECT', '[MMC] Error: %(host)s: %(script)s')
# SUBJECT_LIMIT = get_settings(
#     'MMC_SUBJECT_LIMIT', '[MMC] Limit exceeded: %(host)s: %(script)s')
# REDIS_CONFIG = get_settings('MMC_REDIS_CONFIG', {
#     'host': 'localhost', 'port': 6379,
#     'db': 0, 'password': None
# })
# MEMCACHED_CONFIG = get_settings('MMC_MEMCACHED_CONFIG', {
#     'servers': ['127.0.0.1:11211'], 'debug': 0
# })
# LOCK_TYPE = get_settings('MMC_LOCK_TYPE', 'FileLock')
# SENTRY_NOTIFICATION = get_settings('MMC_SENTRY_NOTIFICATION', True)
# EMAIL_NOTIFICATION = get_settings('MMC_EMAIL_NOTIFICATION', True)
# DEFAULT_LOCK_TIME = get_settings('MMC_DEFAULT_LOCK_TIME', 3600)
# CLEANUP_IGNORED = get_settings('MMC_CLEANUP_IGNORED', True)
# FORCE_IGNORE = get_settings('MMC_FORCE_IGNORE', ['shell'])
# READ_STDOUT = get_settings('MMC_READ_STDOUT', False)
# MAIL_MODULE = get_settings('MMC_MAIL_MODULE', 'django.core.mail')
# EMAIL_FROM = get_settings('MMC_EMAIL_FROM', settings.DEFAULT_FROM_EMAIL)
# REAL_TIME_UPDATE = get_settings('MMC_REAL_TIME_UPDATE', 3)
# HOSTNAME = get_settings('MMC_HOSTNAME', gethostname())
# DEFAULT_ONE_COPY = get_settings('MMC_DEFAULT_ONE_COPY', False)
# NOTIFICATION_LIMIT = get_settings('MMC_NOTIFICATION_LIMIT', 50)
# NEW_SCRIPT_NOTIFICATION = get_settings('MMC_NEW_SCRIPT_NOTIFICATION', True)


# Path: mmc/lock.py
import tempfile
import datetime
import random
import time
import sys
import os
from mmc import defaults
            from mmc.models import MMCLog
        from redis import StrictRedis
            from memcache import Client
            from pylibmc import Client

    @staticmethod
    def random_wait():
        random.seed()
        time.sleep(random.choice([random.uniform(0, 3) for i in range(10)]))


class FileLock(AbstractLock):
    def unlock(self):
        if self.is_run():
            os.unlink(self.get_lock_file())

    def lock(self):
        open(self.get_lock_file(), 'w').close()

    def _cleanup_lock(self):
        if os.path.exists(self.get_lock_file()):
            created = datetime.datetime.fromtimestamp(
                os.path.getctime(self.get_lock_file()))
            seconds = (datetime.datetime.now() - created).seconds
            if seconds > self._lock_time:
                os.unlink(self.get_lock_file())

    def is_run(self):
        self._cleanup_lock()
        return os.path.exists(self.get_lock_file())


class RedisLock(AbstractLock):
    def __init__(self, script):


        self._cli = StrictRedis(**defaults.REDIS_CONFIG)