Author: bugman Date: Sat Mar 10 02:07:39 2007 New Revision: 3146 URL: http://svn.gna.org/viewcvs/relax?rev=3146&view=rev Log: Deleted the Pipes class and converted all its methods into module functions. Modified: 1.3/generic_fns/pipes.py Modified: 1.3/generic_fns/pipes.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/pipes.py?rev=3146&r1=3145&r2=3146&view=diff ============================================================================== --- 1.3/generic_fns/pipes.py (original) +++ 1.3/generic_fns/pipes.py Sat Mar 10 02:07:39 2007 @@ -33,107 +33,101 @@ relax_data_store = Data() - -class Pipes: - """Class containing the methods for manipulating data pipes.""" - - def __init__(self, relax): - - self.relax = relax +"""Class containing the methods for manipulating data pipes.""" - def create(self, pipe_name=None, pipe_type=None): - """Function for creating a data pipe.""" +def create(pipe_name=None, pipe_type=None): + """Function for creating a data pipe.""" - # Test if the data pipe already exists. - if pipe_name in relax_data_store.pipe_names: - raise RelaxRunError, pipe_name + # Test if the data pipe already exists. + if pipe_name in relax_data_store.pipe_names: + raise RelaxRunError, pipe_name - # List of valid data pipe types. - valid = ['jw', 'mf', 'noe', 'relax_fit', 'srls'] + # List of valid data pipe types. + valid = ['jw', 'mf', 'noe', 'relax_fit', 'srls'] - # Test if pipe_type is valid. - if not pipe_type in valid: - raise RelaxError, "The data pipe type " + `pipe_type` + " is invalid and must be one of the strings in the list " + `valid` + "." + # Test if pipe_type is valid. + if not pipe_type in valid: + raise RelaxError, "The data pipe type " + `pipe_type` + " is invalid and must be one of the strings in the list " + `valid` + "." - # Test that the C modules have been loaded. - if pipe_type == 'relax_fit' and not C_module_exp_fn: - raise RelaxError, "Relaxation curve fitting is not availible. Try compiling the C modules on your platform." + # Test that the C modules have been loaded. + if pipe_type == 'relax_fit' and not C_module_exp_fn: + raise RelaxError, "Relaxation curve fitting is not availible. Try compiling the C modules on your platform." - # Add the data pipe name and type. - relax_data_store.pipe_names.append(pipe_name) - relax_data_store.pipe_types.append(pipe_type) + # Add the data pipe name and type. + relax_data_store.pipe_names.append(pipe_name) + relax_data_store.pipe_types.append(pipe_type) - def delete(self, pipe_name=None): - """Function for deleting a data pipe.""" +def delete(pipe_name=None): + """Function for deleting a data pipe.""" - # Test if the data pipe exists. - if pipe_name != None and not pipe_name in relax_data_store.pipe_names: - raise RelaxNoRunError, pipe_name + # Test if the data pipe exists. + if pipe_name != None and not pipe_name in relax_data_store.pipe_names: + raise RelaxNoRunError, pipe_name - # Find out if any data in 'relax_data_store' is assigned to a data pipe. - for name in dir(relax_data_store): - # Get the object. - object = getattr(relax_data_store, name) + # Find out if any data in 'relax_data_store' is assigned to a data pipe. + for name in dir(relax_data_store): + # Get the object. + object = getattr(relax_data_store, name) - # Skip to the next data structure if the object is not a dictionary. - if not hasattr(object, 'keys'): - continue + # Skip to the next data structure if the object is not a dictionary. + if not hasattr(object, 'keys'): + continue - # Delete the data if the object contains the key 'pipe_name'. - if object.has_key(pipe_name): - del(object[pipe_name]) + # Delete the data if the object contains the key 'pipe_name'. + if object.has_key(pipe_name): + del(object[pipe_name]) - # Clean up the data pipes, ie delete any data pipes for which there is no data left. - self.eliminate_unused_pipes() + # Clean up the data pipes, ie delete any data pipes for which there is no data left. + eliminate_unused_pipes() - def eliminate_unused_pipes(self): - """Function for eliminating any data pipes for which there is no data.""" +def eliminate_unused_pipes(): + """Function for eliminating any data pipes for which there is no data.""" - # An array of data pipes to retain. - keep_pipes = [] + # An array of data pipes to retain. + keep_pipes = [] - # Find out if any data in 'relax_data_store' is assigned to a data pipe. - for name in dir(relax_data_store): - # Skip to the next data structure if the object is not a dictionary. - object = getattr(relax_data_store, name) - if not hasattr(object, 'keys'): - continue + # Find out if any data in 'relax_data_store' is assigned to a data pipe. + for name in dir(relax_data_store): + # Skip to the next data structure if the object is not a dictionary. + object = getattr(relax_data_store, name) + if not hasattr(object, 'keys'): + continue - # Add the keys to 'keep_pipes'. - for key in object.keys(): - if not key in keep_pipes: - keep_pipes.append(key) + # Add the keys to 'keep_pipes'. + for key in object.keys(): + if not key in keep_pipes: + keep_pipes.append(key) - # Delete the data pipes in 'relax_data_store.pipe_names' and 'relax_data_store.pipe_types' which are not in 'keep_pipes'. - for pipe in relax_data_store.pipe_names: - if not pipe in keep_pipes: - # Index. - index = relax_data_store.pipe_names.index(pipe) + # Delete the data pipes in 'relax_data_store.pipe_names' and 'relax_data_store.pipe_types' which are not in 'keep_pipes'. + for pipe in relax_data_store.pipe_names: + if not pipe in keep_pipes: + # Index. + index = relax_data_store.pipe_names.index(pipe) - # Remove from pipe_names. - relax_data_store.pipe_names.remove(pipe) + # Remove from pipe_names. + relax_data_store.pipe_names.remove(pipe) - # Remove from pipe_types. - temp = relax_data_store.pipe_types.pop(index) + # Remove from pipe_types. + temp = relax_data_store.pipe_types.pop(index) - def list_of_pipes(self, pipe): - """Function for creating a list of data pipes.""" +def list_of_pipes(pipe): + """Function for creating a list of data pipes.""" - # All data pipes. - if pipe == None: + # All data pipes. + if pipe == None: pipes = deepcopy(relax_data_store.pipe_names) - # Single data pipe. - elif type(pipe) == str: - pipes = [pipe] + # Single data pipe. + elif type(pipe) == str: + pipes = [pipe] - # List of data pipes. - else: - pipes = pipe + # List of data pipes. + else: + pipes = pipe - # Return the list. - return pipes + # Return the list. + return pipes