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

Source Code for Module up2date_client.rhnChannel

  1   
  2  # all the crap that is stored on the rhn side of stuff 
  3  # updating/fetching package lists, channels, etc 
  4   
  5  from up2date_client import up2dateAuth 
  6  from up2date_client import up2dateErrors 
  7  from up2date_client import config 
  8  from up2date_client import rhnserver 
  9   
 10  import gettext 
 11  t = gettext.translation('rhn-client-tools', fallback=True) 
 12  # Python 3 translations don't have a ugettext method 
 13  if not hasattr(t, 'ugettext'): 
 14      t.ugettext = t.gettext 
 15  _ = t.ugettext 
 16   
 17  # heh, dont get much more generic than this... 
18 -class rhnChannel:
19 # shrug, use attributes for thetime being
20 - def __init__(self, **kwargs):
21 self.dict = {} 22 23 for kw in kwargs.keys(): 24 self.dict[kw] = kwargs[kw]
25
26 - def __getitem__(self, item):
27 return self.dict[item]
28
29 - def __setitem__(self, item, value):
30 self.dict[item] = value
31
32 - def __lt__(self, other):
33 return (self.dict["name"] > other.dict["name"])
34
35 - def keys(self):
36 return self.dict.keys()
37
38 - def values(self):
39 return self.dict.values()
40
41 - def items(self):
42 return self.dict.items()
43
44 -class rhnChannelList:
45 - def __init__(self):
46 # probabaly need to keep these in order for 47 #precedence 48 self.list = []
49
50 - def addChannel(self, channel):
51 self.list.append(channel)
52 53
54 - def channels(self):
55 return self.list
56
57 - def getByLabel(self, channelname):
58 for channel in self.list: 59 if channel['label'] == channelname: 60 return channel
61 - def getByName(self, channelname):
62 return self.getByLabel(channelname)
63
64 - def getByType(self, type):
65 channels = [] 66 for channel in self.list: 67 if channel['type'] == type: 68 channels.append(channel) 69 return channels
70 71 # for the gui client that needs to show more info 72 # maybe we should always make this call? If nothing 73 # else, wrapper should have a way to show extended channel info
74 -def getChannelDetails(timeout=None):
75 76 channels = [] 77 sourceChannels = getChannels(timeout=timeout) 78 79 for sourceChannel in sourceChannels.channels(): 80 if sourceChannel['type'] != 'up2date': 81 # FIMXE: kluge since we dont have a good name, maybe be able to fix 82 sourceChannel['name'] = sourceChannel['label'] 83 sourceChannel['description'] = "%s channel %s from %s" % (sourceChannel['type'], 84 sourceChannel['label'], 85 sourceChannel['url']) 86 channels.append(sourceChannel) 87 return channels
88 89 cmdline_pkgs = [] 90 91 global selected_channels 92 selected_channels = None
93 -def getChannels(force=None, label_whitelist=None, timeout=None):
94 """ return rhnChannelList containing list of channel we are subscribed to """ 95 cfg = config.initUp2dateConfig() 96 global selected_channels 97 if not selected_channels and not force: 98 selected_channels = rhnChannelList() 99 s = rhnserver.RhnServer(timeout=timeout) 100 101 if not up2dateAuth.getSystemId(): 102 raise up2dateErrors.NoSystemIdError(_("Unable to Locate SystemId")) 103 104 up2dateChannels = s.up2date.listChannels(up2dateAuth.getSystemId()) 105 106 for chan in up2dateChannels: 107 if label_whitelist and not chan['label'] in label_whitelist: 108 continue 109 110 channel = rhnChannel(type = 'up2date', url = config.getServerlURL()) 111 for key in chan.keys(): 112 if key == "last_modified": 113 channel['version'] = chan['last_modified'] 114 else: 115 channel[key] = chan[key] 116 selected_channels.addChannel(channel) 117 118 if len(selected_channels.list) == 0: 119 raise up2dateErrors.NoChannelsError(_("This system may not be updated until it is associated with a channel.")) 120 121 return selected_channels
122 123
124 -def setChannels(tempchannels):
125 global selected_channels 126 selected_channels = None 127 whitelist = dict(map(lambda x: (x,1), tempchannels)) 128 return getChannels(label_whitelist=whitelist)
129 130 131
132 -def subscribeChannels(channels,username,passwd):
133 s = rhnserver.RhnServer() 134 return s.up2date.subscribeChannels(up2dateAuth.getSystemId(), channels, username, 135 passwd)
136
137 -def unsubscribeChannels(channels,username,passwd):
138 s = rhnserver.RhnServer() 139 return s.up2date.unsubscribeChannels(up2dateAuth.getSystemId(), channels, 140 username, passwd)
141