# Path: servi/command.py
# class Command(object):
#     def __init__(self):
#         self.special = {
#             "skip_init": False,
#             "parse_known_args": False
#         }
# 
#     def register_command_line(self, sub_parser):
#         pass
# 
#     def run(self, args, extra_args):
#         pass
# 
# Path: servi/utils.py
# def pathfor(fname, source):
#     if source is c.MASTER and fname == c.SERVIFILE_GLOBAL:
#         return c.SERVIFILE_GLOBAL_FULL
#     else:
#         return c.pathfor(fname, source, c.TEMPLATE, c.MASTER, c.TMPL_DIR_SITE,
#                          c.MASTER_DIR)
# 
# @contextmanager
# def reset_cwd():
#     origdir = os.getcwd()
#     yield
#     os.chdir(origdir)
# 
# Path: servi/exceptions.py
# class ServiError(Exception):
#     # Expected errrors. Handle gracefully (ie: no stack dump)
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             '{0}\n'
#             '\n**Servi Aborting**'.format(self.msg))


import subprocess
import os
import servi.config as c
from logging import info
from pprint import pformat
from servi.command import Command
from servi.utils import pathfor, reset_cwd
from servi.exceptions import ServiError

    def run(self, args, extra_args):
        hostdict = c.HOSTS
        if args.host_alias not in hostdict:
            raise ServiError('Given host alias ({0}) not found in '
                             'Servifile.yml HOSTS: \n{1}'
                             .format(args.host_alias, pformat(c.HOSTS)))

        if args.dir:
            src_dir = args.dir
        else:
            src_dir = pathfor(c.LOCAL_DIR, c.MASTER)

        alias = args.host_alias
        host = hostdict[alias]['hosts'][0]

        ssh_cmd = '"ssh -q -l {0} -i {1}"'.format(c.MAIN_USERNAME,
                                                  c.MAIN_RSA_KEY_FILE)

        dest_base = '{1}'.format(c.MAIN_USERNAME, host)

        # -O - problem setting dir times 
        # --no-perms - similar
        default_cmd = ['rsync', '-izhav', '-O', '--no-perms', '--stats',
                       '--exclude=".DS_Store"', '--recursive', '-e', ssh_cmd]

        if args.dry_run:
            default_cmd += ['--dry-run']

        apache_cmd = [

# Path: servi/command.py
# class Command(object):
#     def __init__(self):
#         self.special = {
#             "skip_init": False,
#             "parse_known_args": False
#         }
# 
#     def register_command_line(self, sub_parser):
#         pass
# 
#     def run(self, args, extra_args):
#         pass
# 
# Path: servi/utils.py
# def pathfor(fname, source):
#     if source is c.MASTER and fname == c.SERVIFILE_GLOBAL:
#         return c.SERVIFILE_GLOBAL_FULL
#     else:
#         return c.pathfor(fname, source, c.TEMPLATE, c.MASTER, c.TMPL_DIR_SITE,
#                          c.MASTER_DIR)
# 
# @contextmanager
# def reset_cwd():
#     origdir = os.getcwd()
#     yield
#     os.chdir(origdir)
# 
# Path: servi/exceptions.py
# class ServiError(Exception):
#     # Expected errrors. Handle gracefully (ie: no stack dump)
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             '{0}\n'
#             '\n**Servi Aborting**'.format(self.msg))


# Path: servi/commands/pushto.py
import subprocess
import os
import servi.config as c
from logging import info
from pprint import pformat
from servi.command import Command
from servi.utils import pathfor, reset_cwd
from servi.exceptions import ServiError


    def run(self, args, extra_args):
        hostdict = c.HOSTS
        if args.host_alias not in hostdict:
            raise ServiError('Given host alias ({0}) not found in '
                             'Servifile.yml HOSTS: \n{1}'
                             .format(args.host_alias, pformat(c.HOSTS)))

        if args.dir:
            src_dir = args.dir
        else:
            src_dir = pathfor(c.LOCAL_DIR, c.MASTER)

        alias = args.host_alias
        host = hostdict[alias]['hosts'][0]

        ssh_cmd = '"ssh -q -l {0} -i {1}"'.format(c.MAIN_USERNAME,
                                                  c.MAIN_RSA_KEY_FILE)

        dest_base = '{1}'.format(c.MAIN_USERNAME, host)

        # -O - problem setting dir times 
        # --no-perms - similar
        default_cmd = ['rsync', '-izhav', '-O', '--no-perms', '--stats',
                       '--exclude=".DS_Store"', '--recursive', '-e', ssh_cmd]

        if args.dry_run:
            default_cmd += ['--dry-run']

        apache_cmd = [

            addslash(pathfor('apache_config/sites-available/', c.MASTER)),