Package up2date_client :: Module clientCaps
[hide private]
[frames] | no frames]

Source Code for Module up2date_client.clientCaps

 1   
 2  # a dict with "capability name" as the key, and the version 
 3  # as the value. 
 4   
 5  import glob 
 6  import os 
 7   
 8  from up2date_client.capabilities import parseCap 
 9   
10  try: # python2 
11      import UserDict 
12  except ImportError: # python3 
13      import collections as UserDict 
14   
15 -class ClientCapabilities(UserDict.UserDict):
16 - def __init__(self):
17 UserDict.UserDict.__init__(self) 18 self.populate()
19
20 - def populate(self, capsToPopulate=None):
21 # FIXME: at some point, this will be 22 # intelligently populated... 23 localcaps = { 24 "caneatCheese":{'version':1, 'value': 1} 25 } 26 if capsToPopulate: 27 localcaps = capsToPopulate 28 self.data = localcaps
29
30 - def headerFormat(self):
31 headerList = [] 32 for key in self.data.keys(): 33 headerName = "X-RHN-Client-Capability" 34 value = "%s(%s)=%s" % (key, 35 self.data[key]['version'], 36 self.data[key]['value']) 37 headerList.append((headerName, value)) 38 return headerList
39 40 caps = ClientCapabilities() 41
42 -def loadLocalCaps(capsDir = "/etc/sysconfig/rhn/clientCaps.d"):
43 44 capsFiles = glob.glob("%s/*" % capsDir) 45 46 for capsFile in capsFiles: 47 if os.path.isdir(capsFile): 48 continue 49 if not os.access(capsFile, os.R_OK): 50 continue 51 52 fd = open(capsFile, "r") 53 for line in fd.readlines(): 54 line = line.strip() 55 if not line or line[0] == "#": 56 continue 57 caplist = parseCap(line) 58 59 for (cap,data) in caplist: 60 caps.data[cap] = data
61 62 # print(caps.data) 63 64 loadLocalCaps() 65 66 # register local caps we require.
67 -def registerCap(cap, data):
68 caps.data[cap] = data
69 70 71 # figure out something pretty here 72 registerCap("packages.runTransaction", {'version':'1', 'value':'1'}) 73 registerCap("packages.rollBack", {'version':'1', 'value':'1'}) 74 registerCap("packages.verify", {'version':'1', 'value':'1'}) 75 registerCap("packages.extended_profile", {'version':'2', 'value':'1'}) 76 registerCap("reboot.reboot", {'version':'1', 'value':'1'}) 77 registerCap("packages.update", {'version':'2', 'value':'2'}) 78