4abc8749ac2f804107478c634b93106c9463ca50
[sfrench/samba-autobuild/.git] / script / land-remote.py
1 #!/usr/bin/python
2 # Ship a local branch to a remote host (sn-104?) over ssh and run autobuild in it.
3 # Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GPL, v3 or later
5
6 import optparse
7 import subprocess
8 import sys
9
10 parser = optparse.OptionParser("autoland-remote [options]")
11 parser.add_option("--remote-repo", help="Location of remote repository (default: temporary repository)", type=str, default=None)
12 parser.add_option("--host", help="Host to land on (SSH connection string)", type=str, default="sn-devel-104.sn.samba.org")
13 parser.add_option("--foreground", help="Don't daemonize", action="store_true", default=False)
14 parser.add_option("--email", help="Email address to send build/test output to", type=str, default=None, metavar="EMAIL")
15 parser.add_option("--rebase-master", help="rebase on master before testing", default=False, action='store_true')
16 parser.add_option("--rebase", help="rebase on the given tree before testing", default=None, type='str')
17 parser.add_option("--passcmd", help="command to run on success", default=None)
18 parser.add_option("--tail", help="show output while running", default=False, action="store_true")
19 parser.add_option("--keeplogs", help="keep logs", default=False, action="store_true")
20 parser.add_option("--nocleanup", help="don't remove test tree", default=False, action="store_true")
21 parser.add_option("", "--fix-whitespace", help="fix whitespace on rebase",
22                   default=False, action="store_true")
23
24 (opts, args) = parser.parse_args()
25
26 if not opts.foreground and not opts.email:
27     print "Not running in foreground and --email not specified."
28     sys.exit(1)
29
30 if not opts.remote_repo:
31     print "%s$ mktemp -d" % opts.host
32     f = subprocess.Popen(["ssh", opts.host, "mktemp", "-d"], stdout=subprocess.PIPE)
33     (stdout, stderr) = f.communicate()
34     if f.returncode != 0:
35         sys.exit(1)
36     remote_repo = stdout.rstrip()
37     print "Remote tempdir: %s" % remote_repo
38     remote_args = ["git", "clone", "git://git.samba.org/samba.git", remote_repo]
39     #remote_args = ["git", "init", remote_repo]
40     print "%s$ %s" % (opts.host, " ".join(remote_args))
41     subprocess.check_call(["ssh", opts.host] + remote_args)
42 else:
43     remote_repo = opts.remote_repo
44
45 print "Pushing local branch"
46 args = ["git", "push", "--force", "git+ssh://%s/%s" % (opts.host, remote_repo), "HEAD:HEAD"]
47 print "$ " + " ".join(args)
48 subprocess.check_call(args)
49 remote_args = ["cd", remote_repo, "&&", "python", "./script/autobuild.py"]
50 if opts.email:
51     remote_args.append("--email=%s" % opts.email)
52 if not opts.foreground:
53     remote_args.append("--daemon")
54 if opts.nocleanup:
55     remote_args.append("--nocleanup")
56 if opts.fix_whitespace:
57     remote_args.append("--fix-whitespace")
58 if opts.tail:
59     remote_args.append("--tail")
60 if opts.keeplogs:
61     remote_args.append("--keeplogs")
62 if opts.rebase_master:
63     remote_args.append("--rebase-master")
64 if opts.rebase:
65     remote_args.append("--rebase=%s" % opts.rebase)
66 if opts.passcmd:
67     remote_args.append("--passcmd=%s" % opts.passcmd)
68 print "%s$ %s" % (opts.host, " ".join(remote_args))
69 args = ["ssh", "-A", opts.host] + remote_args
70 sys.exit(subprocess.call(args))