# 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
            help='Only print out the rsync command line, but do not execute')

        parser.add_argument(
            'host_alias',
            help='alias of host.'
                 'This is the key part of the HOSTS field in'
                 'Servifile_globals.yml or Servifile.yml ')

        parser.set_defaults(command_func=self.run)

    @staticmethod
    def do_rsync(*args, print_only=False):
        cmd = []
        for arg in args:
            cmd.extend(arg)

        info('rsync command line: {0}\n'.format(' '.join(cmd)))
        if not print_only:
            retval = subprocess.call(' '.join(cmd), shell=True)
        else:
            retval = False

        if retval:
            raise ServiError('Rsync failed. Error code: {0}\n'
                             'rsync cmd: {1}'.format(retval, ' '.join(cmd)))
        return retval

    def run(self, args, extra_args):
        hostdict = c.HOSTS
        if args.host_alias not in hostdict:

# 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

            help='Only print out the rsync command line, but do not execute')

        parser.add_argument(
            'host_alias',
            help='alias of host.'
                 'This is the key part of the HOSTS field in'
                 'Servifile_globals.yml or Servifile.yml ')

        parser.set_defaults(command_func=self.run)

    @staticmethod
    def do_rsync(*args, print_only=False):
        cmd = []
        for arg in args:
            cmd.extend(arg)

        info('rsync command line: {0}\n'.format(' '.join(cmd)))
        if not print_only:
            retval = subprocess.call(' '.join(cmd), shell=True)
        else:
            retval = False

        if retval:
            raise ServiError('Rsync failed. Error code: {0}\n'
                             'rsync cmd: {1}'.format(retval, ' '.join(cmd)))
        return retval

    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 '