# Path: statik/deploy/base.py
# class DeploymentMethod(object):
#     """An abstract method for handling deployment."""
# 
#     def __init__(self, config, error_context=None):
#         """Must validate the given configuration for this deployment method and raise an exception
#         if it's invalid."""
#         raise NotImplementedError
# 
#     def execute(self, source_path):
#         """Must actually execute the implemented deployment method."""
#         raise NotImplementedError
# 
# Path: statik/errors.py
# class ProjectConfigurationError(StatikError):
#     """For generic project configuration-related errors."""
#     error_kind = "Project configuration error"
#     exit_code = 2
# 
# class DeploymentError(StatikError):
#     """For errors relating to deployment of built projects."""
#     error_kind = "Deployment-related error"
#     exit_code = 9


import os
import os.path
import getpass
import paramiko
import logging
from .base import DeploymentMethod
from ..errors import ProjectConfigurationError, DeploymentError
            sftp_mkdir_p(sftp, remote_dir)
            for f in files:
                local_full_path = os.path.join(root, f)
                remote_full_path = remote_dir + "/" + f
                logger.info("Copying %s to %s..." % (local_full_path,
                    remote_full_path))
                sftp.put(local_full_path, remote_full_path)

        logger.info("Transfer complete!")


def sftp_mkdir_p(sftp, remote_directory):
    """Ensures that the given path exists on the target server.
    Adapted from: https://stackoverflow.com/a/14819803"""
    if remote_directory == '/':
        # absolute path so change directory to root
        sftp.chdir('/')
        return
    if remote_directory == '':
        # top-level relative directory must exist
        return
    try:
        sftp.chdir(remote_directory) # sub-directory exists
    except IOError:
        path_parts = remote_directory.rstrip("/").split("/")
        dirname = "/".join(path_parts[:-1])
        basename = path_parts[-1]
        sftp_mkdir_p(sftp, dirname) # make parent directories
        logger.debug("Creating remote folder: %s" % remote_directory)
        sftp.mkdir(basename) # sub-directory missing, so created it

# Path: statik/deploy/base.py
# class DeploymentMethod(object):
#     """An abstract method for handling deployment."""
# 
#     def __init__(self, config, error_context=None):
#         """Must validate the given configuration for this deployment method and raise an exception
#         if it's invalid."""
#         raise NotImplementedError
# 
#     def execute(self, source_path):
#         """Must actually execute the implemented deployment method."""
#         raise NotImplementedError
# 
# Path: statik/errors.py
# class ProjectConfigurationError(StatikError):
#     """For generic project configuration-related errors."""
#     error_kind = "Project configuration error"
#     exit_code = 2
# 
# class DeploymentError(StatikError):
#     """For errors relating to deployment of built projects."""
#     error_kind = "Deployment-related error"
#     exit_code = 9


# Path: statik/deploy/sftp.py
import os
import os.path
import getpass
import paramiko
import logging
from .base import DeploymentMethod
from ..errors import ProjectConfigurationError, DeploymentError

            sftp_mkdir_p(sftp, remote_dir)
            for f in files:
                local_full_path = os.path.join(root, f)
                remote_full_path = remote_dir + "/" + f
                logger.info("Copying %s to %s..." % (local_full_path,
                    remote_full_path))
                sftp.put(local_full_path, remote_full_path)

        logger.info("Transfer complete!")


def sftp_mkdir_p(sftp, remote_directory):
    """Ensures that the given path exists on the target server.
    Adapted from: https://stackoverflow.com/a/14819803"""
    if remote_directory == '/':
        # absolute path so change directory to root
        sftp.chdir('/')
        return
    if remote_directory == '':
        # top-level relative directory must exist
        return
    try:
        sftp.chdir(remote_directory) # sub-directory exists
    except IOError:
        path_parts = remote_directory.rstrip("/").split("/")
        dirname = "/".join(path_parts[:-1])
        basename = path_parts[-1]
        sftp_mkdir_p(sftp, dirname) # make parent directories
        logger.debug("Creating remote folder: %s" % remote_directory)
        sftp.mkdir(basename) # sub-directory missing, so created it

        sftp.chdir(basename)