Package osh :: Module builtins
[frames] | no frames]

Source Code for Module osh.builtins

 1  # osh 
 2  # Copyright (C) Jack Orenstein <jao@geophile.com> 
 3  # 
 4  # This program is free software; you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published by 
 6  # the Free Software Foundation; either version 2 of the License, or 
 7  # (at your option) any later version. 
 8  # 
 9  # This program is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
12  # GNU General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with this program; if not, write to the Free Software 
16  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
17   
18  """This module contains miscellaneous functions builtin to osh. 
19  See also the C{osh.process} module for other builtins. 
20  """ 
21   
22  import config 
23  from core import add_to_namespace 
24  from cluster import cluster_named 
25   
26  #---------------------------------------------------------------------- 
27   
28  # processes 
29   
30  from process import processes 
31   
32  add_to_namespace('processes', processes) 
33   
34  #---------------------------------------------------------------------- 
35   
36  # ifelse 
37   
38 -def ifelse(predicate, if_true, if_false):
39 """Returns C{if_true} if C{predicate} is true, C{if_false} otherwise. 40 Both C{if_true} and C{if_false} are evaluated unconditionally. 41 (This function is provided because the Python equivalent, the if expression, 42 is not present prior to release 2.5.) 43 """ 44 if predicate: 45 return if_true 46 else: 47 return if_false
48 49 add_to_namespace('ifelse', ifelse) 50 51 #---------------------------------------------------------------------- 52 53 # hosts 54
55 -def hosts(cluster_name):
56 """Returns the value of C{cluster_name}'s C{hosts} configuration value, 57 as specified in C{.oshrc}. Returns a map containing entries 58 in which the key is the node's name, and the value is the node's 59 IP address or DNS name. 60 """ 61 map = {} 62 cluster = cluster_named(cluster_name) 63 if cluster: 64 for host in cluster.hosts: 65 map[host.name] = host.address 66 return map 67 else: 68 return None
69 70 add_to_namespace('hosts', hosts) 71