2010-10-01 06:42:59 +04:00
#!/usr/bin/python
# Ship a local branch to a remote host (sn-104?) over ssh and run autobuild in it.
# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
# Published under the GPL, v3 or later
import optparse
2010-10-03 04:16:11 +04:00
import os
2010-10-01 06:42:59 +04:00
import subprocess
import sys
2010-10-03 04:16:11 +04:00
samba_master = os . getenv ( ' SAMBA_MASTER ' , ' git://git.samba.org/samba.git ' )
2010-10-03 02:04:59 +04:00
parser = optparse . OptionParser ( " autoland-remote [options] [trees...] " )
2010-10-01 06:42:59 +04:00
parser . add_option ( " --remote-repo " , help = " Location of remote repository (default: temporary repository) " , type = str , default = None )
parser . add_option ( " --host " , help = " Host to land on (SSH connection string) " , type = str , default = " sn-devel-104.sn.samba.org " )
parser . add_option ( " --foreground " , help = " Don ' t daemonize " , action = " store_true " , default = False )
parser . add_option ( " --email " , help = " Email address to send build/test output to " , type = str , default = None , metavar = " EMAIL " )
2010-10-01 23:34:31 +04:00
parser . add_option ( " --always-email " , help = " always send email, even on success " , action = " store_true " )
2010-10-01 06:42:59 +04:00
parser . add_option ( " --rebase-master " , help = " rebase on master before testing " , default = False , action = ' store_true ' )
2010-10-03 04:16:11 +04:00
parser . add_option ( " --push-master " , help = " push to samba.org master on success " ,
default = False , action = ' store_true ' )
parser . add_option ( " --pushto " , help = " push to a git url on success " ,
default = None , type = ' str ' )
2010-10-01 06:42:59 +04:00
parser . add_option ( " --rebase " , help = " rebase on the given tree before testing " , default = None , type = ' str ' )
parser . add_option ( " --passcmd " , help = " command to run on success " , default = None )
parser . add_option ( " --tail " , help = " show output while running " , default = False , action = " store_true " )
parser . add_option ( " --keeplogs " , help = " keep logs " , default = False , action = " store_true " )
parser . add_option ( " --nocleanup " , help = " don ' t remove test tree " , default = False , action = " store_true " )
2010-10-03 02:50:53 +04:00
parser . add_option ( " --revision " , help = " revision to compile if not HEAD " , default = None , type = str )
2010-10-02 00:10:13 +04:00
parser . add_option ( " --fix-whitespace " , help = " fix whitespace on rebase " ,
2010-10-01 06:42:59 +04:00
default = False , action = " store_true " )
2010-10-02 00:10:13 +04:00
parser . add_option ( " --fail-slowly " , help = " continue running tests even after one has already failed " ,
action = " store_true " )
2010-10-01 06:42:59 +04:00
2010-10-03 02:04:59 +04:00
( opts , extra_args ) = parser . parse_args ( )
2010-10-01 06:42:59 +04:00
2010-10-03 17:06:51 +04:00
if opts . email is None and os . getenv ( " EMAIL " ) is not None :
opts . email = os . getenv ( " EMAIL " )
2010-10-04 15:51:34 +04:00
if opts . email :
print " Sending email to %s " % opts . email
2010-10-01 06:42:59 +04:00
if not opts . foreground and not opts . email :
print " Not running in foreground and --email not specified. "
sys . exit ( 1 )
2010-10-03 04:16:11 +04:00
if not opts . foreground and opts . push_master :
2010-10-04 15:53:02 +04:00
print " Pushing to master, forcing run in foreground. "
opts . foreground = True
2010-10-03 04:16:11 +04:00
2010-10-01 06:42:59 +04:00
if not opts . remote_repo :
print " %s $ mktemp -d " % opts . host
f = subprocess . Popen ( [ " ssh " , opts . host , " mktemp " , " -d " ] , stdout = subprocess . PIPE )
( stdout , stderr ) = f . communicate ( )
if f . returncode != 0 :
sys . exit ( 1 )
remote_repo = stdout . rstrip ( )
print " Remote tempdir: %s " % remote_repo
2010-10-03 06:24:46 +04:00
# Bootstrap, git.samba.org is usually more easily accessible.
#remote_args = ["git", "clone", samba_master, remote_repo]
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 ) ]
2010-10-01 06:42:59 +04:00
#remote_args = ["git", "init", remote_repo]
print " %s $ %s " % ( opts . host , " " . join ( remote_args ) )
subprocess . check_call ( [ " ssh " , opts . host ] + remote_args )
else :
remote_repo = opts . remote_repo
print " Pushing local branch "
2010-10-03 02:50:53 +04:00
if opts . revision is not None :
revision = opts . revision
else :
revision = " HEAD "
args = [ " git " , " push " , " --force " , " git+ssh:// %s / %s " % ( opts . host , remote_repo ) , " %s :land " % revision ]
2010-10-01 06:42:59 +04:00
print " $ " + " " . join ( args )
subprocess . check_call ( args )
2010-10-03 02:50:53 +04:00
remote_args = [ " cd " , remote_repo , " ; " , " git " , " checkout " , " land " , " ; " , " python " , " -u " , " ./script/land.py " , " --repository= %s " % remote_repo ]
2010-10-03 06:24:46 +04:00
if ( opts . email and not ( opts . foreground or opts . pushto or opts . push_master ) ) :
# Force always emailing if there's nothing else to do
opts . always_email = True
2010-10-01 06:42:59 +04:00
if opts . email :
remote_args . append ( " --email= %s " % opts . email )
2010-10-01 23:34:31 +04:00
if opts . always_email :
remote_args . append ( " --always-email " )
2010-10-01 06:42:59 +04:00
if not opts . foreground :
remote_args . append ( " --daemon " )
if opts . nocleanup :
remote_args . append ( " --nocleanup " )
if opts . fix_whitespace :
remote_args . append ( " --fix-whitespace " )
if opts . tail :
remote_args . append ( " --tail " )
if opts . keeplogs :
remote_args . append ( " --keeplogs " )
if opts . rebase_master :
remote_args . append ( " --rebase-master " )
if opts . rebase :
remote_args . append ( " --rebase= %s " % opts . rebase )
if opts . passcmd :
remote_args . append ( " --passcmd= %s " % opts . passcmd )
2010-10-03 04:16:11 +04:00
if opts . pushto :
remote_args . append ( " --pushto= %s " % opts . pushto )
if opts . push_master :
remote_args . append ( " --push-master " )
2010-10-11 17:42:14 +04:00
if opts . fail_slowly :
remote_args . append ( " --fail-slowly " )
2010-10-03 02:50:53 +04:00
2010-10-03 02:04:59 +04:00
remote_args + = extra_args
2010-10-01 06:42:59 +04:00
print " %s $ %s " % ( opts . host , " " . join ( remote_args ) )
args = [ " ssh " , " -A " , opts . host ] + remote_args
sys . exit ( subprocess . call ( args ) )