@@ -0,0 +1,1873 @@
+%22%22%22%0AGeneral utils for Git deploy%0A%22%22%22%0A%0A__date__ = '2013-12-13'%0A__license__ = 'GPL v2.0 (or later)'%0A%0A%0Aimport paramiko%0Aimport socket%0Aimport os%0A%0A%0Adef scp_file(%0A        url,%0A        source_path,%0A        target_path,%0A        user,%0A        key_path,%0A        port=22):%0A    %22%22%22%0A    SCP files via paramiko.%0A    %22%22%22%0A%0A    # Socket connection to remote host%0A    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)%0A    sock.connect((url, port))%0A%0A    # Build a SSH transport%0A    t = paramiko.Transport(sock)%0A    t.start_client()%0A%0A    rsa_key = paramiko.RSAKey.from_private_key_file(key_path)%0A    t.auth_publickey(user, rsa_key)%0A%0A    # Start a scp channel%0A    scp_channel = t.open_session()%0A%0A    f = file(source_path, 'rb')%0A    scp_channel.exec_command('scp -v -t %25s%5Cn'%0A                             %25 '/'.join(target_path.split('/')%5B:-1%5D))%0A    scp_channel.send('C%25s %25d %25s%5Cn'%0A                     %25 (oct(os.stat(source_path).st_mode)%5B-4:%5D,%0A                        os.stat(source_path)%5B6%5D,%0A                        target_path.split('/')%5B-1%5D))%0A    scp_channel.sendall(f.read())%0A%0A    # Cleanup%0A    f.close()%0A    scp_channel.close()%0A    t.close()%0A    sock.close()%0A%0A%0Adef ssh_command_target(%0A        cmd,%0A        url,%0A        user,%0A        key_path,%0A        ssh_port=22):%0A    %22%22%22%0A    Talk to the target via SSHClient%0A%0A    Params:%0A%0A        cmd         - The command to issue on SSH connection%0A        ssh_port    - SSH port on remote, defaults to 22%0A    %22%22%22%0A%0A    ssh = paramiko.SSHClient()%0A    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())%0A    ssh.connect(%0A        url, username=user, key_filename=key_path, port=ssh_port)%0A    stdin, stdout, stderr = ssh.exec_command(cmd)%0A%0A    stdout = %5Bline.strip() for line in stdout.readlines()%5D%0A    stderr = %5Bline.strip() for line in stderr.readlines()%5D%0A%0A    ssh.close()%0A%0A    return %7B%0A        'stdout': stdout,%0A        'stderr': stderr,%0A    %7D

add - module for general methods.