def _copyoneto(self, src, convert=None): """Copy the file `srcto a server. Return 0 or >0 if it failed. `convert` is the function used to compute basename = f(convert). """ bname = osp.basename(src) if convert is not None: bname = convert(src) dst = osp.join(self.proxy_dir, bname) #peter.zhang for remote connection src = src.replace('\\', '/') dst = dst.replace('\\', '/') dst_file = dst dst_server = self.user + "@" + self.host dst = dst_server + ":" + dst_file cmd = [ "scp", "-rBCq", "-o StrictHostKeyChecking=no", src, dst] magic.log.info(_(u"copy %s to %s"), src, dst) res = local_shell(cmd) magic.log.info(_(u"returns %s"), res[0]) cmd = [ "ssh", dst_server, "chmod 0755", dst_file] magic.log.info(_(u"chmod %s to 0755"), dst_file) res_chmod = local_shell(cmd) magic.log.info(_(u"chmod returns %s"), res_chmod[0]) if res[2]: magic.log.error(res[2]) return res[0]
def _copyonefrom(self, dst, convert=None): """Copy the file `dstfrom a server. Return 0 or >0 if it failed. `convert` is the function used to compute basename = f(convert). Example : dst=/home/user/dir/fname => rcp -r log@mach:`self.proxy_dir`/fname /home/user/fname Warning: to avoid to create /home/user/dir/fname/fname when fname is a directory, we execute: => rcp -r log@mach:`self.proxy_dir`/fname /home/user/dir/ """ bname = osp.basename(dst) if convert is not None: bname = convert(dst) src = osp.join(self.proxy_dir, bname) #peter.zhang for remote connection src = src.replace('\\', '/') dst = dst.replace('\\', '/') fsrc = self.user + "@" + self.host + ":" + src cmd = [ "rcp", "-r", fsrc, dst] magic.log.info(_(u"copy %s to %s"), fsrc, dst) res = local_shell(cmd) magic.log.info(_(u"returns %s"), res[0]) if res[2]: magic.log.error(res[2]) return res[0]
def delete_proxy_dir(self): """Erase the proxy_dir directory on the server.""" magic.log.info(_(u"delete remote directory %s..."), self.proxy_dir) cmdargs = self.prepare_curl_command("PROPFIND", address=self.proxy_dir +"/", header={"Depth":"1"}) res = local_shell(cmdargs) iret=res[0] if iret == 0: tree = xml.fromstring(res[1]) files = [elem.find('.//{DAV:}href').text \ for elem in tree.findall('{DAV:}response')] for afile in files: cmdargs = self.prepare_curl_command("DELETE", address=afile) local_shell(cmdargs) cmdargs = self.prepare_curl_command("DELETE", address=self.proxy_dir) local_shell(cmdargs) magic.log.info(_(u"returns %s"), iret) return iret
def _exec_command(self, command, display_forwarding=False, **opts): """Execute a command line on the server.""" #XXX append command as string and enclosed by ' or " (escape ' or " in command) if type(command) not in (list, tuple): command = [ command, ] for commanditem in command: cmdargs = self.prepare_sftp_command(commanditem) output = local_shell(cmdargs) return output
def _exec_command(self, command, display_forwarding=False, **opts): """Execute a command line on the server.""" cmd = [ "rsh", "-n", "-l", self.user, self.host ] #XXX append command as string and enclosed by ' or " (escape ' or " in command) if type(command) not in (list, tuple): command = [command, ] cmd.extend(command) res = local_shell(cmd) return res
def _copyonefrom(self, dst, convert=None): """Copy the file `dstfrom a server. Return 0 or >0 if it failed. `convert` is the function used to compute basename = f(convert). """ bname = osp.basename(dst) if convert is not None: bname = convert(dst) src = self.proxy_dir + '/' + bname cmdargs = self.prepare_curl_command("GET", address=src, output=dst) res = local_shell(cmdargs) magic.log.info(_(u"copy %s to %s"), src, dst) magic.log.info(_(u"returns %s"), res) return res[0]
def _copyoneto(self, src, convert=None): """Copy the file `srcto a server. Return 0 or >0 if it failed. `convert` is the function used to compute basename = f(convert). """ bname = osp.basename(src) if convert is not None: bname = convert(src) dst = self.proxy_dir + '/' + bname cmdargs = self.prepare_curl_command("PUT", address=dst, input=src) res = local_shell(cmdargs) magic.log.info(_(u"copy %s to %s"), src, dst) magic.log.info(_(u"returns %s"), res) return res[0] # WORKAROUND default.py line 75 : if iret != 0:
def _create_dir(self, directory): """Create a directory on the server.""" magic.log.info(_(u"create remote directory %s...") % directory) dirs = [d for d in directory.split('/') if d] if not dirs: return cwd = "/" for dir in dirs: cmdargs = self.prepare_curl_command("MKCOL", address=cwd + dir) res = local_shell(cmdargs) magic.log.info(_(u"creating folder %s"), dir) cwd += dir + "/" magic.log.info(_(u"returns %s"), res) return res
def _exec_command(self, command, display_forwarding=False, **opts): """Execute a command line on the server.""" # XXX append command as string and enclosed by ' or " (escape ' or " in command) if type(command) not in (list, tuple): cmdargs = self.prepare_curl_command("POST", address=self.aster_root) else: address = command[0] args = command[1:] magic.log.debug("Calling a post url %s command : %s" % (address, args)) cmdargs = self.prepare_curl_command("POST", address=address, form={"args" : " ".join(args)}) try: output = local_shell(cmdargs) except: magic.log.debug("Command failed : %s" % cmdargs) return output
def _exec_command(self, command, display_forwarding=False, **opts): """Execute a command line on the server.""" cmd = [ "ssh", "-n", "-o", "StrictHostKeyChecking=no", "-o", "BatchMode=yes" ] if display_forwarding: cmd.append("-X") if opts.get('timeout'): cmd.extend(["-o", "'ConnectTimeout=%s'" % opts["timeout"]]) cmd.append(self.user + "@" + self.host) #XXX append command as string and enclosed by ' or " (escape ' or " in command) if type(command) not in (list, tuple): command = [command, ] cmd.extend(command) res = local_shell(cmd) return res
def _copyoneto(self, src, convert=None): """Copy the file `srcto a server. Return 0 or >0 if it failed. `convert` is the function used to compute basename = f(convert). """ bname = osp.basename(src) if convert is not None: bname = convert(src) dst = osp.join(self.proxy_dir, bname) #peter.zhang for remote connection src = src.replace('\\', '/') dst = dst.replace('\\', '/') dst = self.user + "@" + self.host + ":" + dst cmd = [ "rcp", "-r", src, dst] magic.log.info(_(u"copy %s to %s"), src, dst) res = local_shell(cmd) magic.log.info(_(u"returns %s"), res[0]) if res[2]: magic.log.error(res[2]) return res[0]
def _copyonefrom(self, dst, convert=None): """Copy the file `dstfrom a server. Return 0 or >0 if it failed. `convert` is the function used to compute basename = f(convert). Example : dst=/home/user/dir/fname => scp -r log@mach:`self.proxy_dir`/f(fname) /home/user/fname Warning: to avoid to create /home/user/dir/fname/f(fname) when fname exists and is a directory, we execute: => scp -r log@mach:`self.proxy_dir`/f(fname) /home/user/dir/fname => mv /home/user/dir/fname/f(fname)/* /home/user/dir/fname/ => rmdir /home/user/dir/fname/f(fname) """ to_rename = osp.isdir(dst) bname = osp.basename(dst) if convert is not None: bname = convert(dst) src = osp.join(self.proxy_dir, bname) #peter.zhang for remote connection src = src.replace('\\', '/') dst = dst.replace('\\', '/') fsrc = self.user + "@" + self.host + ":" + src cmd = [ "scp", "-rBCq", fsrc, dst] magic.log.info(_(u"copy %s to %s"), fsrc, dst) res = local_shell(cmd) iret = res[0] magic.log.info(_(u"returns %s"), iret) if res[2]: magic.log.error(res[2]) if to_rename: try: iret = 0 renametree(osp.join(dst, bname), dst) except OSError, err: iret = 1 magic.log.error(str(err))