# Path: fabdeploy/containers.py
# class DefaultConf(BaseConf):
#     address = '%s@localhost' % os.environ['USER']
#     instance_name = '%(user)s'
# 
#     time_format = '%Y.%m.%d-%H.%M.%S'
# 
#     # directory name that contains project
#     # this is useful if your project is not in git/hg repo root dir
#     project_dir = ''
#     # directory name that contains manage.py file (django project root)
#     django_dir = ''
#     home_path = conf(lambda self: home_path(self.user))
#     releases_path = ['%(home_path)s', 'releases']
#     release_path = ['%(releases_path)s', '%(release)s']
#     release_data_file = ['%(release_path)s', '.fabdeploy']
#     project_path = ['%(release_path)s', '%(project_dir)s']
#     django_path = ['%(project_path)s', '%(django_dir)s']
#     env_path = ['%(release_path)s', 'env']
#     shared_path = ['%(home_path)s', 'shared']
#     media_path = ['%(shared_path)s', 'media']
#     etc_path = ['%(shared_path)s', 'etc']
#     var_path = ['%(shared_path)s', 'var']
#     log_path = ['%(var_path)s', 'log']
#     backup_path = ['%(var_path)s', 'backup']
# 
#     project_ldir = ''
#     django_ldir = ['%(project_ldir)s', '%(django_dir)s']
#     home_lpath = sys.path[0]
#     src_lpath = '%(home_lpath)s'
#     project_lpath = ['%(src_lpath)s', '%(project_ldir)s']
#     django_lpath = ['%(src_lpath)s', '%(django_ldir)s']
# 
#     # user that have sudo right
#     # this is useful, because usually deploy user don't have sudo right
#     sudo_user = 'root'
#     server_name = '%(host)s'
#     server_admin = 'admin@%(host)s'
# 
#     apache_processes = 1
#     # conf decorator is used to achieve lazy evaluation
#     apache_threads = conf(lambda self: self.cpu_count * 2 + 1)
#     uwsgi_processes = conf(lambda self: self.cpu_count * 2 + 1)
# 
#     config_templates_lpathes = [
#         'config_templates/%(conf_name)s',
#         'config_templates',
#     ]
# 
#     # django settings: manage.py --settings=%(settings)s
#     settings = 'settings'
#     # env specific settings file, that is imported in %(settings)s
#     local_settings_file = 'local_settings.py'
#     # %(local_settings_file)s will be replaced with this file
#     remote_settings_lfile = 'prod_settings.py'
#     loglevel = 'INFO'
# 
#     db_name = '%(instance_name)s'
#     db_user = '%(user)s'
#     db_password = '%(user)s'
#     db_host = 'localhost'
#     mysql__db_root_user = 'root'
#     mysql__db_root_password = 'mysql'
#     mysql__db_port = 3306
#     postgres__db_root_user = 'postgres'
#     postgres__db_root_password = 'postgres'
#     postgres__db_port = 5432
# 
#     pip_cache_path = '/var/run/pip-download-cache'
#     pip_req_lpath = '%(project_ldir)s'
#     pip_req_file = 'requirements.txt'
# 
#     # prefix for supervisor programs/groups
#     # useful when there are several projects deployed on one server
#     supervisor_prefix = ''
#     supervisor_config_path = ['%(etc_path)s', 'supervisor']
#     supervisord_config_lfile = 'supervisord.conf'
#     supervisord_config_file = '/etc/supervisord.conf'
#     supervisord_log_path = '/var/log/supervisor'
# 
#     @conf
#     def user(self):
#         username, _, _ = network.normalize(self.address)
#         return username
# 
#     @conf
#     def host(self):
#         _, host, _ = network.normalize(self.address)
#         return host
# 
#     @conf
#     def current_time(self):
#         return datetime.datetime.utcnow().strftime(self.time_format)
# 
#     @conf
#     def release(self):
#         self.set_globally('release', self.current_time)
#         return self.release
# 
#     @conf
#     def os(self):
#         from fabdeploy import system
#         with system.os_codename.tmp_conf():
#             self.set_globally('os', system.os_codename.os_codename())
#         return self.os
# 
#     @conf
#     def cpu_count(self):
#         from fabdeploy import system
#         with system.cpu_count.tmp_conf():
#             self.set_globally('cpu_count', system.cpu_count.cpu_count())
#         return self.cpu_count
# 
#     def config_template_lpath(self, name):
#         for dir in self.config_templates_lpathes:
#             path = os.path.join(dir, name)
#             if os.path.exists(path):
#                 return path
# 
# Path: fabdeploy/api.py



from nose.tools import with_setup
from fabric.api import env
from fabdeploy.containers import DefaultConf
from fabdeploy.api import Task, conf
    env.conf = DefaultConf()


def teardown():
    env.conf = DefaultConf()


@with_setup(setup, teardown)
def test_task_has_access_to_env_conf():
    class MyTask(Task):
        pass
    my_task = MyTask()

    env.conf.foo = 'env'
    with my_task.tmp_conf():
        assert my_task.conf.foo == 'env'


@with_setup(setup, teardown)
def test_task_has_access_to_kwargs():
    class MyTask(Task):
        pass
    my_task = MyTask()

    with my_task.tmp_conf(task_kwargs={'foo': 'kwarg'}):
        assert my_task.conf.foo == 'kwarg'


@with_setup(setup, teardown)
def test_task_called_with_conf_of_another_task():

# Path: fabdeploy/containers.py
# class DefaultConf(BaseConf):
#     address = '%s@localhost' % os.environ['USER']
#     instance_name = '%(user)s'
# 
#     time_format = '%Y.%m.%d-%H.%M.%S'
# 
#     # directory name that contains project
#     # this is useful if your project is not in git/hg repo root dir
#     project_dir = ''
#     # directory name that contains manage.py file (django project root)
#     django_dir = ''
#     home_path = conf(lambda self: home_path(self.user))
#     releases_path = ['%(home_path)s', 'releases']
#     release_path = ['%(releases_path)s', '%(release)s']
#     release_data_file = ['%(release_path)s', '.fabdeploy']
#     project_path = ['%(release_path)s', '%(project_dir)s']
#     django_path = ['%(project_path)s', '%(django_dir)s']
#     env_path = ['%(release_path)s', 'env']
#     shared_path = ['%(home_path)s', 'shared']
#     media_path = ['%(shared_path)s', 'media']
#     etc_path = ['%(shared_path)s', 'etc']
#     var_path = ['%(shared_path)s', 'var']
#     log_path = ['%(var_path)s', 'log']
#     backup_path = ['%(var_path)s', 'backup']
# 
#     project_ldir = ''
#     django_ldir = ['%(project_ldir)s', '%(django_dir)s']
#     home_lpath = sys.path[0]
#     src_lpath = '%(home_lpath)s'
#     project_lpath = ['%(src_lpath)s', '%(project_ldir)s']
#     django_lpath = ['%(src_lpath)s', '%(django_ldir)s']
# 
#     # user that have sudo right
#     # this is useful, because usually deploy user don't have sudo right
#     sudo_user = 'root'
#     server_name = '%(host)s'
#     server_admin = 'admin@%(host)s'
# 
#     apache_processes = 1
#     # conf decorator is used to achieve lazy evaluation
#     apache_threads = conf(lambda self: self.cpu_count * 2 + 1)
#     uwsgi_processes = conf(lambda self: self.cpu_count * 2 + 1)
# 
#     config_templates_lpathes = [
#         'config_templates/%(conf_name)s',
#         'config_templates',
#     ]
# 
#     # django settings: manage.py --settings=%(settings)s
#     settings = 'settings'
#     # env specific settings file, that is imported in %(settings)s
#     local_settings_file = 'local_settings.py'
#     # %(local_settings_file)s will be replaced with this file
#     remote_settings_lfile = 'prod_settings.py'
#     loglevel = 'INFO'
# 
#     db_name = '%(instance_name)s'
#     db_user = '%(user)s'
#     db_password = '%(user)s'
#     db_host = 'localhost'
#     mysql__db_root_user = 'root'
#     mysql__db_root_password = 'mysql'
#     mysql__db_port = 3306
#     postgres__db_root_user = 'postgres'
#     postgres__db_root_password = 'postgres'
#     postgres__db_port = 5432
# 
#     pip_cache_path = '/var/run/pip-download-cache'
#     pip_req_lpath = '%(project_ldir)s'
#     pip_req_file = 'requirements.txt'
# 
#     # prefix for supervisor programs/groups
#     # useful when there are several projects deployed on one server
#     supervisor_prefix = ''
#     supervisor_config_path = ['%(etc_path)s', 'supervisor']
#     supervisord_config_lfile = 'supervisord.conf'
#     supervisord_config_file = '/etc/supervisord.conf'
#     supervisord_log_path = '/var/log/supervisor'
# 
#     @conf
#     def user(self):
#         username, _, _ = network.normalize(self.address)
#         return username
# 
#     @conf
#     def host(self):
#         _, host, _ = network.normalize(self.address)
#         return host
# 
#     @conf
#     def current_time(self):
#         return datetime.datetime.utcnow().strftime(self.time_format)
# 
#     @conf
#     def release(self):
#         self.set_globally('release', self.current_time)
#         return self.release
# 
#     @conf
#     def os(self):
#         from fabdeploy import system
#         with system.os_codename.tmp_conf():
#             self.set_globally('os', system.os_codename.os_codename())
#         return self.os
# 
#     @conf
#     def cpu_count(self):
#         from fabdeploy import system
#         with system.cpu_count.tmp_conf():
#             self.set_globally('cpu_count', system.cpu_count.cpu_count())
#         return self.cpu_count
# 
#     def config_template_lpath(self, name):
#         for dir in self.config_templates_lpathes:
#             path = os.path.join(dir, name)
#             if os.path.exists(path):
#                 return path
# 
# Path: fabdeploy/api.py



# Path: tests/test_task.py
from nose.tools import with_setup
from fabric.api import env
from fabdeploy.containers import DefaultConf
from fabdeploy.api import Task, conf

    env.conf = DefaultConf()


def teardown():
    env.conf = DefaultConf()


@with_setup(setup, teardown)
def test_task_has_access_to_env_conf():
    class MyTask(Task):
        pass
    my_task = MyTask()

    env.conf.foo = 'env'
    with my_task.tmp_conf():
        assert my_task.conf.foo == 'env'


@with_setup(setup, teardown)
def test_task_has_access_to_kwargs():
    class MyTask(Task):
        pass
    my_task = MyTask()

    with my_task.tmp_conf(task_kwargs={'foo': 'kwarg'}):
        assert my_task.conf.foo == 'kwarg'


@with_setup(setup, teardown)
def test_task_called_with_conf_of_another_task():

    class Task1(Task):