# Path: makesite/settings.py
# BASEDIR = op.abspath(op.dirname(__file__))
# TPL_DIR = op.join(BASEDIR, 'templates')
# MOD_DIR = op.join(BASEDIR, 'modules')
# TPLNAME = '.makesite'
# CFGNAME = 'makesite.ini'
# BASECONFIG = op.join(BASEDIR, CFGNAME)
# HOMECONFIG = op.join(getenv('HOME', '~'), CFGNAME)
# MAKESITE_HOME = environ.get('MAKESITE_HOME')
# USER = environ.get('USER', 'roor')
# SRC_CLONE = (
#     ('svn', 'svn checkout %(src)s %(source_dir)s'),
#     ('git', 'git clone %(src)s %(source_dir)s -b %(branch)s'),
#     ('hg', 'hg clone %(src)s %(source_dir)s'),
# )
# class MakesiteParser(ConfigParser):
#     def __init__(self, *args, **kwargs):
#     def defaults(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value, section='Main'):
#     def __getattr__(self, name):
#     def as_dict(self, section='Main', **kwargs):
#     def read(self, filenames, extending=False, map_sections=None):
# 
# Path: makesite/core.py
# def walklevel(dirpath, level=1):
#     dirpath = dirpath.rstrip(op.sep)
#     assert op.isdir(dirpath)
#     start = dirpath.count(op.sep)
#     for root, dirs, files in walk(dirpath):
#         yield root, dirs, files
#         if start + level <= root.count(op.sep):
#             del dirs[:]
# 
# def call(cmd, shell=True, **kwargs):
#     " Run shell command. "
# 
#     LOGGER.debug("Cmd: %s" % cmd)
#     check_call(cmd, shell=shell, stdout=LOGFILE_HANDLER.stream, **kwargs)
# 
# def print_header(msg, sep='='):
#     " More strong message "
# 
#     LOGGER.info("\n%s\n%s" % (msg, ''.join(sep for _ in msg)))
# 
# def is_exe(path):
#     return op.exists(path) and access(path, X_OK)
# 
# def gen_template_files(path):
#     " Generate relative template pathes. "
# 
#     path = path.rstrip(op.sep)
#     for root, _, files in walk(path):
#         for f in filter(lambda x: not x in (TPLNAME, CFGNAME), files):
#             yield op.relpath(op.join(root, f), path)
# 
# LOGGER = logging.getLogger('Makesite')


from os import path as op, listdir, makedirs, remove
from shutil import copy2
from tempfile import mkdtemp
from tempita import Template
from makesite import settings
from makesite.core import walklevel, call, print_header, is_exe, gen_template_files, LOGGER
class Site(settings.MakesiteParser):
    " Operations with site instance. "

    def __init__(self, deploy_dir):
        " Init site options. "

        super(Site, self).__init__()

        self.deploy_dir = deploy_dir.rstrip(op.sep)
        self.read([op.join(self.deploy_dir, settings.CFGNAME)])
        assert self.project and self.branch, "Invalid site: %s" % self.deploy_dir
        self.templates = self.template.split(',')

    def get_info(self, full=False):
        " Return printable information about current site. "

        if full:
            context = self.as_dict()
            return "".join("{0:<25} = {1}\n".format(
                           key, context[key]) for key in sorted(context.iterkeys()))
        return "%s [%s]" % (self.get_name(), self.template)

    def get_name(self):
        " Return name of site in format: 'project.branch'. "

        return "%s.%s" % (self.project, self.safe_branch or self.branch)

    def run_check(self, template_name=None, service_dir=None):
        " Run checking scripts. "


# Path: makesite/settings.py
# BASEDIR = op.abspath(op.dirname(__file__))
# TPL_DIR = op.join(BASEDIR, 'templates')
# MOD_DIR = op.join(BASEDIR, 'modules')
# TPLNAME = '.makesite'
# CFGNAME = 'makesite.ini'
# BASECONFIG = op.join(BASEDIR, CFGNAME)
# HOMECONFIG = op.join(getenv('HOME', '~'), CFGNAME)
# MAKESITE_HOME = environ.get('MAKESITE_HOME')
# USER = environ.get('USER', 'roor')
# SRC_CLONE = (
#     ('svn', 'svn checkout %(src)s %(source_dir)s'),
#     ('git', 'git clone %(src)s %(source_dir)s -b %(branch)s'),
#     ('hg', 'hg clone %(src)s %(source_dir)s'),
# )
# class MakesiteParser(ConfigParser):
#     def __init__(self, *args, **kwargs):
#     def defaults(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value, section='Main'):
#     def __getattr__(self, name):
#     def as_dict(self, section='Main', **kwargs):
#     def read(self, filenames, extending=False, map_sections=None):
# 
# Path: makesite/core.py
# def walklevel(dirpath, level=1):
#     dirpath = dirpath.rstrip(op.sep)
#     assert op.isdir(dirpath)
#     start = dirpath.count(op.sep)
#     for root, dirs, files in walk(dirpath):
#         yield root, dirs, files
#         if start + level <= root.count(op.sep):
#             del dirs[:]
# 
# def call(cmd, shell=True, **kwargs):
#     " Run shell command. "
# 
#     LOGGER.debug("Cmd: %s" % cmd)
#     check_call(cmd, shell=shell, stdout=LOGFILE_HANDLER.stream, **kwargs)
# 
# def print_header(msg, sep='='):
#     " More strong message "
# 
#     LOGGER.info("\n%s\n%s" % (msg, ''.join(sep for _ in msg)))
# 
# def is_exe(path):
#     return op.exists(path) and access(path, X_OK)
# 
# def gen_template_files(path):
#     " Generate relative template pathes. "
# 
#     path = path.rstrip(op.sep)
#     for root, _, files in walk(path):
#         for f in filter(lambda x: not x in (TPLNAME, CFGNAME), files):
#             yield op.relpath(op.join(root, f), path)
# 
# LOGGER = logging.getLogger('Makesite')


# Path: makesite/site.py
from os import path as op, listdir, makedirs, remove
from shutil import copy2
from tempfile import mkdtemp
from tempita import Template
from makesite import settings
from makesite.core import walklevel, call, print_header, is_exe, gen_template_files, LOGGER

class Site(settings.MakesiteParser):
    " Operations with site instance. "

    def __init__(self, deploy_dir):
        " Init site options. "

        super(Site, self).__init__()

        self.deploy_dir = deploy_dir.rstrip(op.sep)
        self.read([op.join(self.deploy_dir, settings.CFGNAME)])
        assert self.project and self.branch, "Invalid site: %s" % self.deploy_dir
        self.templates = self.template.split(',')

    def get_info(self, full=False):
        " Return printable information about current site. "

        if full:
            context = self.as_dict()
            return "".join("{0:<25} = {1}\n".format(
                           key, context[key]) for key in sorted(context.iterkeys()))
        return "%s [%s]" % (self.get_name(), self.template)

    def get_name(self):
        " Return name of site in format: 'project.branch'. "

        return "%s.%s" % (self.project, self.safe_branch or self.branch)

    def run_check(self, template_name=None, service_dir=None):
        " Run checking scripts. "


        print_header('Check requirements', sep='-')