def execute(self, target, structure): # you need to setup .sitecopyrc host = target.getHost() rcfile = CLIENT_HOME + '/.sitecopyrc' storepath = CLIENT_HOME + '/.sitecopy' command = 'sitecopy --rcfile=%s --storepath=%s' % ( target._rcfile, target._storepath) rendered_command = '%s %s %s' % (command, '-uk', host) log = StringIO() conn = pexpect.spawn(rendered_command) conn.setlog(log) conn.expect(pexpect.EOF, 30) # 30 s timeout if conn.isalive(): conn.kill(1) if conn.exitstatus != 0: log.seek(0) raise ProtocolError, log.read()
def execute(self, target, structure): host = target.getHost() user = target.getUser() pass_ = target._password local_directory = structure.getMountPoint() remote_directory = target.getDirectory() ################################# command = "rsync" short_noarg_options = [ "a", # archive mode "z", # compress "t", # preserve mod times "q", # quiet "C", # ignore cvs files #"r", # recurse #"p", # preserve permissions #"u", # update, don't overwrite new files, i don't need this ] short_arg_options = [("e", "ssh")] # mainly aggressive deletion options # for retraction. Also some partial options long_options = [ "--delete", # delete files which don't exist on the sender #"--ignore-existing", #ignore files that already exist on the reciever #"--existing", # only update files that already exist #"--delete-after", # delete after transferring files #"--ignore-errors" # delete even if errors in transfer #"--force", # force deletion of non empty dirs ] short = "-%s"%''.join(short_noarg_options) short_arg_list = [] for k, v in short_arg_options: short_arg_list.append('-%s %s' % (k, v)) short_arg = ' '.join(short_arg_list) long_options = "%s"%' '.join(long_options) all_options = ' '.join( (short, short_arg, long_options) ) ################################# rendered_command = "%s %s %s %s"%( command, all_options, local_directory, "%s@%s:%s"%( user, host, remote_directory) ) log = StringIO() conn = pexpect.spawn(rendered_command) conn.setlog(log) try: conn.expect_exact(['password:'******'Enter passphrase', 'Password:']) except pexpect.EOF: conn.kill(1) log.seek(0) raise ProtocolError, log.read() conn.sendline(pass_) conn.expect(pexpect.EOF, 30) # 30 s timeout if conn.isalive(): conn.kill(1) if conn.exitstatus != 0: log.seek(0) raise ProtocolError, log.read()