2 # Compile a Samba 4 branch from scratch and land it onto master.
3 # (C) 2010 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GPL, v3 or later.
6 from email.mime.text import MIMEText
15 parser = optparse.OptionParser("land [options] <repo>")
16 parser.add_option("--branch", help="Branch to land", type=str, default=None, metavar="BRANCH")
17 parser.add_option("--dry-run", help="Dry run (don't actually land)", action="store_true", default=False)
18 parser.add_option("--daemon", help="Daemonize", action="store_true", default=False)
19 parser.add_option("--mail-to", help="Email address to send build/test output to", type=str, default=None, metavar="MAIL-TO")
21 (opts, args) = parser.parse_args()
24 from_addr = opts.mail_to
32 tmpdir = tempfile.mkdtemp()
33 rootpath = os.path.join(tmpdir, "repo")
35 if subprocess.call(["git", "clone", repo, rootpath]) != 0:
36 print "Unable to clone repository at %s" % repo
40 if subprocess.call(["git", "checkout", opts.branch], cwd=rootpath) != 0:
42 if subprocess.call(["git", "remote", "add", "upstream", "git://git.samba.org/samba.git"], cwd=rootpath) != 0:
44 if subprocess.call(["git", "fetch", "upstream"], cwd=rootpath) != 0:
46 if subprocess.call(["git", "rebase", "upstream/master"], cwd=rootpath) != 0:
54 if pid != 0: # Actual daemon
59 import resource # Resource usage information.
60 maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
61 if maxfd == resource.RLIM_INFINITY:
62 maxfd = 1024 # Rough guess at maximum number of open file descriptors.
63 for fd in range(0, maxfd):
68 os.open(os.devnull, os.O_RDWR)
73 (outfd, name) = tempfile.mkstemp()
74 outf = os.fdopen(outfd, 'w')
82 msg = MIMEText(f.read())
84 msg["Subject"] = "Failure for %s during %s" % (repo, stage)
85 msg["To"] = opts.mail_to
86 msg["From"] = from_addr
88 smtp.sendmail(from_addr, [opts.mail_to], msg.as_string())
93 s4path = os.path.join(rootpath, "source4")
95 if subprocess.call(["./autogen.sh"], cwd=s4path, stdout=outf, stderr=outf) != 0:
96 fail("Generating configure")
97 if subprocess.call(["./configure.developer"], cwd=s4path, stdout=outf, stderr=outf) != 0:
98 fail("Running configure")
99 if subprocess.call(["make"], cwd=s4path, stderr=outf, stdout=outf) != 0:
101 if subprocess.call(["make", "check"], cwd=s4path, stderr=outf, stdout=outf) != 0:
102 fail("Running testsuite")
104 if subprocess.call(["git", "push", "git+ssh://git.samba.org/data/git/samba.git", "HEAD:master"], cwd=rootpath, stderr=outf, stdout=outf) != 0:
105 fail("Pushing to master")
106 shutil.rmtree(tmpdir)
111 msg = MIMEText(f.read())
113 msg["Subject"] = "Success landing %s" % repo
114 msg["To"] = opts.mail_to
115 msg["From"] = from_addr
117 smtp.sendmail(from_addr, [opts.mail_to], msg.as_string())