def copy(self, source_url, destination_url, execution_mode=''): try: logger.debug("Running copy function from %s" % self.parent_module) if not self.conn: self.connect() with self._sem: if 'file://' in source_url: from_dir = urlparse(source_url).path to_dir = self._set_dir(urlparse(destination_url).path) self.conn.scp([from_dir], target=to_dir) if execution_mode == 'X': stdout, stderr = self.execCommand("chmod +x %s" % to_dir) if stderr: logger.warning( "Could not change access permissions of %s file: %s" % (to_dir, stderr)) else: from_dir = self._set_dir(urlparse(source_url).path) to_dir = urlparse(destination_url).path self.remote_scp([from_dir], target=to_dir) logger.debug("Ending copy function from %s" % self.parent_module) except Exception as excep: if "disabling multiplexing" in str(excep): logger.debug( "Mux isn't working from the copy function. Eliminating " + self.parent_module + "'s socket file.") self._delete_socket() self.copy(source_url, destination_url) else: logger.warning(str(excep))
def copy(self, source_url, destination_url, execution_mode): with self._lock: if 'file://' in source_url: from_dir = urlparse(source_url).path to_dir = self._set_dir(urlparse(destination_url).path) else: from_dir = self._set_dir(urlparse(source_url).path) to_dir = urlparse(destination_url).path out, err = self.execCommand("cp -r %s %s" % (from_dir,to_dir)) if err: output = "Could not copy from %s to %s : %s" % ( from_dir, to_dir , ' '.join( err.split( '\n' ) ) ) logger.error( output ) raise ComException( output ) if execution_mode == 'X': os.chmod(to_dir, execution_permissions )
def copy(self, source_url, destination_url, execution_mode=''): with self._sem: self.connect() scp = SCPClient(self._trans) if 'file://' in source_url: from_dir = urlparse(source_url).path to_dir = self._set_dir(urlparse(destination_url).path) scp.put(from_dir, to_dir) if execution_mode == 'X': stdout, stderr = self.execCommand("chmod +x %s" % to_dir) else: from_dir = self._set_dir(urlparse(source_url).path) to_dir = urlparse(destination_url).path logger.warning("%s , %s" % (from_dir, to_dir)) scp.get(from_dir, to_dir)
def rmDirectory(self, url): to_dir = self._set_dir(urlparse(url).path) out, err = self.execCommand("rm -rf %s" % to_dir ) if err: output = "Could not remove %s directory: %s " % ( to_dir , ' '.join( err.split( '\n' ) ) ) logger.error( output ) raise ComException( output )
def do_RMDIR(self, args): """ RMDIR: Removes directory SRC_URL (i.e. RMDIR JID - - SRC_URL -) @param args : arguments of operation @type args : string """ OPERATION, JID, TID, EXE_MODE, SRC_URL, DST_URL = args.split() try: com = self._update_com( urlparse( SRC_URL ).host ) com.rmDirectory( SRC_URL ) out = 'RMDIR %s - SUCCESS -' % ( JID ) except Exception as err : out = 'RMDIR %s - FAILURE %s' % ( JID , str( err ) ) self.message.stdout( out ) self.logger.debug( out, exc_info=1 )
def rmDirectory(self, url): try: logger.debug("Running rmDirectory function from %s" % self.parent_module) to_dir = self._set_dir(urlparse(url).path) stdout, stderr = self.execCommand( "rm -rf %s" % to_dir ) if stderr: logger.warning( "Could not remove %s directory: %s" % ( to_dir , stderr ) ) logger.debug("Ending rmDirectory function from %s" % self.parent_module) except Exception as excep: if "disabling multiplexing" in str(excep): logger.debug("Mux isn't working from the rmDirectory function. Eliminating "+self.parent_module+"'s socket file.") self._delete_socket() self.rmDirectory(url) else: logger.warning(str(excep))
def do_CP(self, args): """ CP: start a copy of SRC_URL to DST_URL, with identification TID, and associated with job JID.(i.e. CP JID TID - SRC_URL DST_URL) @param args : arguments of operation @type args : string """ OPERATION, JID, TID, EXE_MODE, SRC_URL, DST_URL = args.split() if 'file:' in SRC_URL: url = DST_URL else: url = SRC_URL try: com = self._update_com( urlparse( url ).host ) com.copy( SRC_URL , DST_URL , EXE_MODE ) out = 'CP %s %s SUCCESS -' % ( JID , TID ) except Exception as err : out = 'CP %s %s FAILURE %s' % ( JID , TID , str( err ) ) self.message.stdout( out ) self.logger.debug(out , exc_info=1 )
def rmDirectory(self, url): to_dir = self._set_dir(urlparse(url).path) stdout, stderr = self.execCommand("rm -rf %s" % to_dir) if stderr: raise ComException("Could not remove %s directory on '%s': %s" % (to_dir, self.frontend , stderr ))
def mkDirectory(self, url): to_dir = self._set_dir(urlparse(url).path) stdout, stderr = self.execCommand("mkdir -p %s" % to_dir) if stderr: raise ComException("Could not create %s directory on '%s': %s" % (to_dir, self.frontend , stderr ))
def checkOutLock(self, url): to_dir = self._set_dir(urlparse(url).path) return os.path.isfile('%s/.lock' % to_dir)