s3-auth: Rename to init_system_session_info().
[Samba/gbeck.git] / script / land-remote.py
blob1009e6bd02bc3ee20143990057181936eb48f4d4
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
6 import optparse
7 import os
8 import subprocess
9 import sys
11 samba_master = os.getenv('SAMBA_MASTER', 'git://git.samba.org/samba.git')
13 parser = optparse.OptionParser("autoland-remote [options] [trees...]")
14 parser.add_option("--remote-repo", help="Location of remote repository (default: temporary repository)", type=str, default=None)
15 parser.add_option("--host", help="Host to land on (SSH connection string)", type=str, default="sn-devel-104.sn.samba.org")
16 parser.add_option("--foreground", help="Don't daemonize", action="store_true", default=False)
17 parser.add_option("--email", help="Email address to send build/test output to", type=str, default=None, metavar="EMAIL")
18 parser.add_option("--always-email", help="always send email, even on success", action="store_true")
19 parser.add_option("--rebase-master", help="rebase on master before testing", default=False, action='store_true')
20 parser.add_option("--push-master", help="push to samba.org master on success",
21 default=False, action='store_true')
22 parser.add_option("--pushto", help="push to a git url on success",
23 default=None, type='str')
24 parser.add_option("--rebase", help="rebase on the given tree before testing", default=None, type='str')
25 parser.add_option("--passcmd", help="command to run on success", default=None)
26 parser.add_option("--tail", help="show output while running", default=False, action="store_true")
27 parser.add_option("--keeplogs", help="keep logs", default=False, action="store_true")
28 parser.add_option("--nocleanup", help="don't remove test tree", default=False, action="store_true")
29 parser.add_option("--revision", help="revision to compile if not HEAD", default=None, type=str)
30 parser.add_option("--fix-whitespace", help="fix whitespace on rebase",
31 default=False, action="store_true")
32 parser.add_option("--fail-slowly", help="continue running tests even after one has already failed",
33 action="store_true")
35 (opts, extra_args) = parser.parse_args()
37 if opts.email is None and os.getenv("EMAIL") is not None:
38 opts.email = os.getenv("EMAIL")
40 if opts.email:
41 print "Sending email to %s" % opts.email
43 if not opts.foreground and not opts.email:
44 print "Not running in foreground and --email not specified."
45 sys.exit(1)
47 if not opts.foreground and opts.push_master:
48 print "Pushing to master, forcing run in foreground."
49 opts.foreground = True
51 if not opts.remote_repo:
52 print "%s$ mktemp -d" % opts.host
53 f = subprocess.Popen(["ssh", opts.host, "mktemp", "-d"], stdout=subprocess.PIPE)
54 (stdout, stderr) = f.communicate()
55 if f.returncode != 0:
56 sys.exit(1)
57 remote_repo = stdout.rstrip()
58 print "Remote tempdir: %s" % remote_repo
59 # Bootstrap, git.samba.org is usually more easily accessible.
60 #remote_args = ["git", "clone", samba_master, remote_repo]
61 remote_args = ["if [ -d /data/git/samba.git ]; then git clone --shared /data/git/samba.git %s; else git clone --shared %s %s; fi" % (remote_repo, samba_master, remote_repo)]
62 #remote_args = ["git", "init", remote_repo]
63 print "%s$ %s" % (opts.host, " ".join(remote_args))
64 subprocess.check_call(["ssh", opts.host] + remote_args)
65 else:
66 remote_repo = opts.remote_repo
68 print "Pushing local branch"
70 if opts.revision is not None:
71 revision = opts.revision
72 else:
73 revision = "HEAD"
74 args = ["git", "push", "--force", "git+ssh://%s/%s" % (opts.host, remote_repo), "%s:land" % revision]
75 print "$ " + " ".join(args)
76 subprocess.check_call(args)
77 remote_args = ["cd", remote_repo, ";", "git", "checkout", "land", ";", "python", "-u", "./script/land.py", "--repository=%s" % remote_repo]
79 if (opts.email and not (opts.foreground or opts.pushto or opts.push_master)):
80 # Force always emailing if there's nothing else to do
81 opts.always_email = True
83 if opts.email:
84 remote_args.append("--email=%s" % opts.email)
85 if opts.always_email:
86 remote_args.append("--always-email")
87 if not opts.foreground:
88 remote_args.append("--daemon")
89 if opts.nocleanup:
90 remote_args.append("--nocleanup")
91 if opts.fix_whitespace:
92 remote_args.append("--fix-whitespace")
93 if opts.tail:
94 remote_args.append("--tail")
95 if opts.keeplogs:
96 remote_args.append("--keeplogs")
97 if opts.rebase_master:
98 remote_args.append("--rebase-master")
99 if opts.rebase:
100 remote_args.append("--rebase=%s" % opts.rebase)
101 if opts.passcmd:
102 remote_args.append("--passcmd=%s" % opts.passcmd)
103 if opts.pushto:
104 remote_args.append("--pushto=%s" % opts.pushto)
105 if opts.push_master:
106 remote_args.append("--push-master")
107 if opts.fail_slowly:
108 remote_args.append("--fail-slowly")
110 remote_args += extra_args
111 print "%s$ %s" % (opts.host, " ".join(remote_args))
112 args = ["ssh", "-A", opts.host] + remote_args
113 sys.exit(subprocess.call(args))