land-remote: Use --repository option.
[kai/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]")
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("", "--fix-whitespace", help="fix whitespace on rebase",
23                   default=False, action="store_true")
24
25 (opts, args) = parser.parse_args()
26
27 if not opts.foreground and not opts.email:
28     print "Not running in foreground and --email not specified."
29     sys.exit(1)
30
31 if not opts.remote_repo:
32     print "%s$ mktemp -d" % opts.host
33     f = subprocess.Popen(["ssh", opts.host, "mktemp", "-d"], stdout=subprocess.PIPE)
34     (stdout, stderr) = f.communicate()
35     if f.returncode != 0:
36         sys.exit(1)
37     remote_repo = stdout.rstrip()
38     print "Remote tempdir: %s" % remote_repo
39     remote_args = ["git", "clone", "git://git.samba.org/samba.git", remote_repo]
40     #remote_args = ["git", "init", remote_repo]
41     print "%s$ %s" % (opts.host, " ".join(remote_args))
42     subprocess.check_call(["ssh", opts.host] + remote_args)
43 else:
44     remote_repo = opts.remote_repo
45
46 print "Pushing local branch"
47 args = ["git", "push", "--force", "git+ssh://%s/%s" % (opts.host, remote_repo), "HEAD:HEAD"]
48 print "$ " + " ".join(args)
49 subprocess.check_call(args)
50 remote_args = ["python", "%s/script/land.py" % remote_repo, "--repository=%s" % remote_repo]
51 if opts.email:
52     remote_args.append("--email=%s" % opts.email)
53 if opts.always_email:
54     remote_args.append("--always-email")
55 if not opts.foreground:
56     remote_args.append("--daemon")
57 if opts.nocleanup:
58     remote_args.append("--nocleanup")
59 if opts.fix_whitespace:
60     remote_args.append("--fix-whitespace")
61 if opts.tail:
62     remote_args.append("--tail")
63 if opts.keeplogs:
64     remote_args.append("--keeplogs")
65 if opts.rebase_master:
66     remote_args.append("--rebase-master")
67 if opts.rebase:
68     remote_args.append("--rebase=%s" % opts.rebase)
69 if opts.passcmd:
70     remote_args.append("--passcmd=%s" % opts.passcmd)
71 print "%s$ %s" % (opts.host, " ".join(remote_args))
72 args = ["ssh", "-A", opts.host] + remote_args
73 sys.exit(subprocess.call(args))