# 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
        LOGGER.info('Site Install done.')
        return True

    def run_update(self, template_name=None, service_dir=None):
        " Run update scripts. "

        LOGGER.info('Site Update start.')
        print_header('Update %s' % self.get_name())
        map(call, self._gen_scripts(
            'update', template_name=template_name, service_dir=service_dir))
        LOGGER.info('Site Update done.')
        return True

    def run_remove(self, template_name=None, service_dir=None):
        " Run remove scripts. "

        print_header('Uninstall %s' % self.get_name())
        map(call, self._gen_scripts(
            'remove', template_name=template_name, service_dir=service_dir))
        LOGGER.info('Site Remove done.')
        return True

    def paste_template(self, template_name, template=None, deploy_dir=None):
        " Paste template. "

        LOGGER.debug("Paste template: %s" % template_name)
        deploy_dir = deploy_dir or self.deploy_dir
        template = template or self._get_template_path(template_name)
        self.read([op.join(template, settings.CFGNAME)], extending=True)


# 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

        LOGGER.info('Site Install done.')
        return True

    def run_update(self, template_name=None, service_dir=None):
        " Run update scripts. "

        LOGGER.info('Site Update start.')
        print_header('Update %s' % self.get_name())
        map(call, self._gen_scripts(
            'update', template_name=template_name, service_dir=service_dir))
        LOGGER.info('Site Update done.')
        return True

    def run_remove(self, template_name=None, service_dir=None):
        " Run remove scripts. "

        print_header('Uninstall %s' % self.get_name())
        map(call, self._gen_scripts(
            'remove', template_name=template_name, service_dir=service_dir))
        LOGGER.info('Site Remove done.')
        return True

    def paste_template(self, template_name, template=None, deploy_dir=None):
        " Paste template. "

        LOGGER.debug("Paste template: %s" % template_name)
        deploy_dir = deploy_dir or self.deploy_dir
        template = template or self._get_template_path(template_name)
        self.read([op.join(template, settings.CFGNAME)], extending=True)


        for fname in gen_template_files(template):