land: Add --revision argument.
[mat/samba.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] [trees...]")
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("--always-email", help="always send email, even on success", action="store_true")
16 parser.add_option("--rebase-master", help="rebase on master before testing", default=False, action='store_true')
17 parser.add_option("--rebase", help="rebase on the given tree before testing", default=None, type='str')
18 parser.add_option("--passcmd", help="command to run on success", default=None)
19 parser.add_option("--tail", help="show output while running", default=False, action="store_true")
20 parser.add_option("--keeplogs", help="keep logs", default=False, action="store_true")
21 parser.add_option("--nocleanup", help="don't remove test tree", default=False, action="store_true")
22 parser.add_option("--revision", help="revision to compile if not HEAD", default=None, type=str)
23 parser.add_option("--fix-whitespace", help="fix whitespace on rebase",
24                   default=False, action="store_true")
25 parser.add_option("--fail-slowly", help="continue running tests even after one has already failed",
26                   action="store_true")
27
28 (opts, extra_args) = parser.parse_args()
29
30 if not opts.foreground and not opts.email:
31     print "Not running in foreground and --email not specified."
32     sys.exit(1)
33
34 if not opts.remote_repo:
35     print "%s$ mktemp -d" % opts.host
36     f = subprocess.Popen(["ssh", opts.host, "mktemp", "-d"], stdout=subprocess.PIPE)
37     (stdout, stderr) = f.communicate()
38     if f.returncode != 0:
39         sys.exit(1)
40     remote_repo = stdout.rstrip()
41     print "Remote tempdir: %s" % remote_repo
42     # Bootstrap, git.samba.org is close to sn-devel
43     remote_args = ["git", "clone", "git://git.samba.org/samba.git", remote_repo]
44     #remote_args = ["git", "init", remote_repo]
45     print "%s$ %s" % (opts.host, " ".join(remote_args))
46     subprocess.check_call(["ssh", opts.host] + remote_args)
47 else:
48     remote_repo = opts.remote_repo
49
50 print "Pushing local branch"
51
52 if opts.revision is not None:
53     revision = opts.revision
54 else:
55     revision = "HEAD"
56 args = ["git", "push", "--force", "git+ssh://%s/%s" % (opts.host, remote_repo), "%s:land" % revision]
57 print "$ " + " ".join(args)
58 subprocess.check_call(args)
59 remote_args = ["cd", remote_repo, ";", "git", "checkout", "land", ";", "python", "-u", "./script/land.py", "--repository=%s" % remote_repo]
60 if opts.email:
61     remote_args.append("--email=%s" % opts.email)
62 if opts.always_email:
63     remote_args.append("--always-email")
64 if not opts.foreground:
65     remote_args.append("--daemon")
66 if opts.nocleanup:
67     remote_args.append("--nocleanup")
68 if opts.fix_whitespace:
69     remote_args.append("--fix-whitespace")
70 if opts.tail:
71     remote_args.append("--tail")
72 if opts.keeplogs:
73     remote_args.append("--keeplogs")
74 if opts.rebase_master:
75     remote_args.append("--rebase-master")
76 if opts.rebase:
77     remote_args.append("--rebase=%s" % opts.rebase)
78 if opts.passcmd:
79     remote_args.append("--passcmd=%s" % opts.passcmd)
80
81 remote_args += extra_args
82 print "%s$ %s" % (opts.host, " ".join(remote_args))
83 args = ["ssh", "-A", opts.host] + remote_args
84 sys.exit(subprocess.call(args))