def main(): if OPTIONS.add: need_channel(OPTIONS.channel) result = subscribeChannels(OPTIONS.channel, OPTIONS.user, OPTIONS.password) if OPTIONS.verbose: if result == 0: print _("Channel(s): %s successfully added") % ", ".join(OPTIONS.channel) else: sys.stderr.write( rhncli.utf8_encode(_("Error during adding channel(s) %s") % ", ".join(OPTIONS.channel)) ) if result != 0: sys.exit(result) elif OPTIONS.remove: need_channel(OPTIONS.channel) result = unsubscribeChannels(OPTIONS.channel, OPTIONS.user, OPTIONS.password) if OPTIONS.verbose: if result == 0: print _("Channel(s): %s successfully removed") % ", ".join(OPTIONS.channel) else: sys.stderr.write( rhncli.utf8_encode(_("Error during removal of channel(s) %s") % ", ".join(OPTIONS.channel)) ) if result != 0: sys.exit(result) elif OPTIONS.list: try: channels = map(lambda x: x["label"], getChannels().channels()) except up2dateErrors.NoChannelsError: systemExit(1, _("This system is not associated with any channel.")) except up2dateErrors.NoSystemIdError: systemExit(1, _("Unable to locate SystemId file. Is this system registered?")) channels.sort() print "\n".join(channels) elif OPTIONS.base: try: for channel in getChannels().channels(): # Base channel has no parent if not channel["parent_channel"]: print channel["label"] except up2dateErrors.NoChannelsError: systemExit(1, "This system is not associated with any channel.") except up2dateErrors.NoSystemIdError: systemExit(1, "Unable to locate SystemId file. Is this system registered?") elif OPTIONS.available_channels: channels = get_available_channels(OPTIONS.user, OPTIONS.password) channels.sort() print "\n".join(channels) else: systemExit(3, _("ERROR: you may want to specify --add, --remove or --list"))
def getPackage(self, package, msgCallback=None, progressCallback=None): filename = "%s-%s-%s.%s.rpm" % (package[0], package[1], package[2], package[4]) channels = rhnChannel.getChannels() channel = channels.getByLabel(package[6]) filePath = "%s/%s" % (self.cfg["storageDir"], filename) # FIXME: apt has some more sophisticated logic for actually finding # the package that this, probabaly need to implement to support # most repos url = "%s/RPMS.%s/%s" % (channel['url'], channel['dist'], filename) if msgCallback: #DEBUG msgCallback(filename) fd = open(filePath, "w+") (lmtime) = urlUtils.fetchUrlAndWriteFD( url, fd, progressCallback=progressCallback, agent="Up2date %s/Apt" % up2dateUtils.version()) fd.close() buffer = open(filePath, "r").read() return buffer
def get_subscribed_channels_list(self): try: subscribed_channels = map(lambda x: x["label"], getChannels().channels()) except Exception: log.error(traceback.format_exc()) system_exit(1, _("Problem encountered getting the list of subscribed channels. Exiting.")) return subscribed_channels
def getPackage(self, pkg, msgCallback = None, progressCallback = None): filename = "%s-%s-%s.%s.rpm" % (pkg[0], pkg[1], pkg[2], pkg[4]) channels = rhnChannel.getChannels() channel = channels.getByLabel(pkg[6]) #print "self.pkgNamePath: %s" % self.pkgNamePath #print "stored rpmpath: %s" % self.pkgNamePath[(pkg[0], pkg[1], pkg[2], pkg[3], pkg[4])] filePath = "%s/%s" % (self.cfg["storageDir"], filename) #rpmPath = self.pkgNamePath[(pkg[0], pkg[1], pkg[2], pkg[3], pkg[4])] rpmPath = pkg[7] url = "%s/%s" % (channel['url'],rpmPath ) if msgCallback: # for now, makes it easier to debug #msgCallback(url) msgCallback(filename) fd = open(filePath, "w+") (lmtime) = urlUtils.fetchUrlAndWriteFD(url, fd, progressCallback = progressCallback, agent = "Up2date %s/Yum" % up2dateUtils.version()) fd.close() buffer = open(filePath, "r").read() return buffer
def getPackage(self, pkg, msgCallback=None, progressCallback=None): filename = "%s-%s-%s.%s.rpm" % (pkg[0], pkg[1], pkg[2], pkg[4]) channels = rhnChannel.getChannels() channel = channels.getByLabel(pkg[6]) #print "self.pkgNamePath: %s" % self.pkgNamePath #print "stored rpmpath: %s" % self.pkgNamePath[(pkg[0], pkg[1], pkg[2], pkg[3], pkg[4])] filePath = "%s/%s" % (self.cfg["storageDir"], filename) #rpmPath = self.pkgNamePath[(pkg[0], pkg[1], pkg[2], pkg[3], pkg[4])] rpmPath = pkg[7] url = "%s/%s" % (channel['url'], rpmPath) if msgCallback: # for now, makes it easier to debug #msgCallback(url) msgCallback(filename) fd = open(filePath, "w+") (lmtime) = urlUtils.fetchUrlAndWriteFD( url, fd, progressCallback=progressCallback, agent="Up2date %s/Yum" % up2dateUtils.version()) fd.close() buffer = open(filePath, "r").read() return buffer
def get_subscribed_channels_list(self, rpc_session, session_key): try: channels = getChannels().channels() except Exception, e: log.exception(e) system_exit( 1, _("Problem encountered getting the list of subscribed channels. " ) + SEE_LOG_FILE)
def get_subscribed_channels_list(self, rpc_session, session_key): try: channels = getChannels().channels() except Exception as e: log.exception(e) system_exit(os.EX_SOFTWARE, _("Problem encountered getting the list of subscribed channels. ") + SEE_LOG_FILE) if self.options.five_to_six: channels = [self.resolve_base_channel(c['label'], rpc_session, session_key) for c in channels] return [x['label'] for x in channels]
def list_channels(only_base_channels=False): try: channels = getChannels().channels() except up2dateErrors.NoChannelsError: systemExit(1, _('This system is not associated with any channel.')) except up2dateErrors.NoSystemIdError: systemExit(1, _('Unable to locate SystemId file. Is this system registered?')) for channel in sorted(channels): if not (only_base_channels and channel.get('parent_channel')): print channel['label']
def get_subscribed_channels_list(self): try: subscribed_channels = map(lambda x: x['label'], getChannels().channels()) except Exception: log.error(traceback.format_exc()) system_exit( 1, _("Problem encountered getting the list of subscribed channels. Exiting." )) return subscribed_channels
def getHeader(self, package, msgCallback = None, progressCallback = None): # yum adds the epoch into the filename of the header, so create the # approriate remotename, handling epoch=0 crap as well if package[3] == "": remoteFilename = "%s-%s-%s-%s.%s.hdr" % (package[0], "0", package[1], package[2], package[4]) else: remoteFilename = "%s-%s-%s-%s.%s.hdr" % (package[0], package[3], package[1], package[2], package[4]) if msgCallback: msgCallback(remoteFilename) channels = rhnChannel.getChannels() channel = channels.getByLabel(package[6]) url = "%s/headers/%s" % (channel['url'],remoteFilename ) if msgCallback: msgCallback("Fetching %s" % url) # heck, maybe even borrow the one from yum nohdr = 1 count = 0 while ((nohdr) and (count < 5)): count = count + 1 try: # fix this to use fetchUrl and stringIO's for gzip (fn, h) = urllib.urlretrieve(url) # print fn # the yum headers are gzip'ped fh = gzip.open(fn, "r") hdrBuf = fh.read() # FIXME: lame, need real callbacks if progressCallback: progressCallback(1,1) hdr = rpmUtils.readHeaderBlob(hdrBuf) rpmSourceUtils.saveHeader(hdr) self.headerCache["%s-%s-%s" % (hdr['name'], hdr['version'], hdr['release'])] = hdr nohdr = 0 except: print "There was an error downloading:", "%s" % url nohdr = 1 return hdr
def main(): if OPTIONS.add: need_channel(OPTIONS.channel) result = subscribeChannels(OPTIONS.channel, OPTIONS.user, OPTIONS.password) if OPTIONS.verbose: if result == 0: print _("Channel(s): %s successfully added") % ', '.join( OPTIONS.channel) else: sys.stderr.write( rhncli.utf8_encode( _("Error during adding channel(s) %s") % ', '.join(OPTIONS.channel))) if result != 0: sys.exit(result) elif OPTIONS.remove: need_channel(OPTIONS.channel) result = unsubscribeChannels(OPTIONS.channel, OPTIONS.user, OPTIONS.password) if OPTIONS.verbose: if result == 0: print _("Channel(s): %s successfully removed") % ', '.join( OPTIONS.channel) else: sys.stderr.write( rhncli.utf8_encode( _("Error during removal of channel(s) %s") % ', '.join(OPTIONS.channel))) if result != 0: sys.exit(result) elif OPTIONS.list: try: channels = map(lambda x: x['label'], getChannels().channels()) except up2dateErrors.NoChannelsError: systemExit(1, _('This system is not associated with any channel.')) except up2dateErrors.NoSystemIdError: systemExit( 1, _('Unable to locate SystemId file. Is this system registered?') ) channels.sort() print '\n'.join(channels) elif OPTIONS.available_channels: channels = get_available_channels(OPTIONS.user, OPTIONS.password) channels.sort() print '\n'.join(channels) else: systemExit( 3, _("ERROR: you may want to specify --add, --remove or --list"))
def getSolutions(self, unknowns, msgCallback = None, progressCallback = None): channels = rhnChannel.getChannels() repoChannels = channels.getByType(self.type) repoPackages = [] channelNames = [] for channel in repoChannels: channelNames.append(channel['label']) for pkg in self.availList: if pkg[6] in channelNames: repoPackages.append(pkg) solutions = {} totalLen = len(repoPackages) count = 0 # dont show the message if were not going to do anything if msgCallback and totalLen: msgCallback("Downloading headers to solve dependencies") for pkg in repoPackages: hdr = self.getHeader(pkg) if progressCallback: progressCallback(count, totalLen) count = count + 1 # this bit basically straight out of yum/pkgaction.py GPL Duke Univeristy 2002 fullprovideslist = hdr[rpm.RPMTAG_PROVIDES] if hdr[rpm.RPMTAG_FILENAMES] != None: fullprovideslist = fullprovideslist + hdr[rpm.RPMTAG_FILENAMES] if hdr[rpm.RPMTAG_DIRNAMES] != None: fullprovideslist = fullprovideslist + hdr[rpm.RPMTAG_DIRNAMES] unknownsCopy = unknowns[:] for unknown in unknowns: for item in fullprovideslist: if unknown == item: if solutions.has_key(unknown): solutions[unknown].append(pkg) else: solutions[unknown] = [pkg] try: unknownsCopy.remove(unknown) except ValueError: # already removed from list pass if len(unknownsCopy) == 0: break del fullprovideslist self.retDict = solutions
def getSolutions(self, unknowns, msgCallback=None, progressCallback=None): channels = rhnChannel.getChannels() repoChannels = channels.getByType(self.type) repoPackages = [] channelNames = [] for channel in repoChannels: channelNames.append(channel['label']) for pkg in self.availList: if pkg[6] in channelNames: repoPackages.append(pkg) solutions = {} totalLen = len(repoPackages) count = 0 # dont show the message if were not going to do anything if msgCallback and totalLen: msgCallback("Downloading headers to solve dependencies") for pkg in repoPackages: hdr = self.getHeader(pkg) if progressCallback: progressCallback(count, totalLen) count = count + 1 # this bit basically straight out of yum/pkgaction.py GPL Duke Univeristy 2002 fullprovideslist = hdr[rpm.RPMTAG_PROVIDES] if hdr[rpm.RPMTAG_FILENAMES] != None: fullprovideslist = fullprovideslist + hdr[rpm.RPMTAG_FILENAMES] if hdr[rpm.RPMTAG_DIRNAMES] != None: fullprovideslist = fullprovideslist + hdr[rpm.RPMTAG_DIRNAMES] unknownsCopy = unknowns[:] for unknown in unknowns: for item in fullprovideslist: if unknown == item: if solutions.has_key(unknown): solutions[unknown].append(pkg) else: solutions[unknown] = [pkg] try: unknownsCopy.remove(unknown) except ValueError: # already removed from list pass if len(unknownsCopy) == 0: break del fullprovideslist self.retDict = solutions
def getHeader(self, package, msgCallback=None, progressCallback=None): # yum adds the epoch into the filename of the header, so create the # approriate remotename, handling epoch=0 crap as well if package[3] == "": remoteFilename = "%s-%s-%s-%s.%s.hdr" % ( package[0], "0", package[1], package[2], package[4]) else: remoteFilename = "%s-%s-%s-%s.%s.hdr" % ( package[0], package[3], package[1], package[2], package[4]) if msgCallback: msgCallback(remoteFilename) channels = rhnChannel.getChannels() channel = channels.getByLabel(package[6]) url = "%s/headers/%s" % (channel['url'], remoteFilename) if msgCallback: msgCallback("Fetching %s" % url) # heck, maybe even borrow the one from yum nohdr = 1 count = 0 while ((nohdr) and (count < 5)): count = count + 1 try: # fix this to use fetchUrl and stringIO's for gzip (fn, h) = urllib.urlretrieve(url) # print fn # the yum headers are gzip'ped fh = gzip.open(fn, "r") hdrBuf = fh.read() # FIXME: lame, need real callbacks if progressCallback: progressCallback(1, 1) hdr = rpmUtils.readHeaderBlob(hdrBuf) rpmSourceUtils.saveHeader(hdr) self.headerCache["%s-%s-%s" % (hdr['name'], hdr['version'], hdr['release'])] = hdr nohdr = 0 except: print "There was an error downloading:", "%s" % url nohdr = 1 return hdr
def main(): if OPTIONS.add: subscribeChannels(OPTIONS.channel, OPTIONS.user, OPTIONS.password) if OPTIONS.verbose: print "Channel(s): %s successfully added" % ', '.join(OPTIONS.channel) elif OPTIONS.remove: unsubscribeChannels(OPTIONS.channel, OPTIONS.user, OPTIONS.password) if OPTIONS.verbose: print "Channel(s): %s successfully removed" % ', '.join(OPTIONS.channel) elif OPTIONS.list: try: channels = map(lambda x: x['label'], getChannels().channels()) except up2dateErrors.NoChannelsError: systemExit(1, 'This system is not associated with any channel.') channels.sort() print '\n'.join(channels) else: s = rhnserver.RhnServer() print s.up2date.listall(up2dateAuth.getSystemId()) systemExit(3, "ERROR: you may want to specify --add, --remove or --list")
def getHeader(self, pkg, msgCallback=None, progressCallback=None): channels = rhnChannel.getChannels() channel = channels.getByName(pkg[6]) #filename = "%s/%s-%s-%s.%s.rpm" % (channel['path'], pkg[0], pkg[1], # pkg[2], pkg[4]) filename = pkg[7] # package doesnt exist if not os.access(filename, os.R_OK): return None hdrBuf = self.__getHeader(filename) try: hdr = rpmUtils.readHeaderBlob(hdrBuf.unload()) except: return None rpmSourceUtils.saveHeader(hdr) self.headerCache[up2dateUtils.pkgToStringArch(pkg)] = hdr self.__saveHeader(hdr) return hdr
def getHeader(self, pkg, msgCallback = None, progressCallback = None): channels = rhnChannel.getChannels() channel = channels.getByName(pkg[6]) #filename = "%s/%s-%s-%s.%s.rpm" % (channel['path'], pkg[0], pkg[1], # pkg[2], pkg[4]) filename = pkg[7] # package doesnt exist if not os.access(filename, os.R_OK): return None hdrBuf = self.__getHeader(filename) try: hdr = rpmUtils.readHeaderBlob(hdrBuf.unload()) except: return None rpmSourceUtils.saveHeader(hdr) self.headerCache[up2dateUtils.pkgToStringArch(pkg)] = hdr self.__saveHeader(hdr) return hdr
def getPackage(self, pkg, msgCallback=None, progressCallback=None): pkgFileName = "%s-%s-%s.%s.rpm" % (pkg[0], pkg[1], pkg[2], pkg[4]) channels = rhnChannel.getChannels() channel = channels.getByLabel(pkg[6]) # if msgCallback: # msgCallback(pkgFileName) storageFilePath = "%s/%s" % (self.cfg["storageDir"], pkgFileName) # symlink the file from /var/spool/up2date to whereever it is... # fileName = "%s/%s" % (channel['path'], pkgFileName) fileName = pkg[7] if (channel['path'] != self.cfg['storageDir']): try: os.remove(storageFilePath) except OSError: pass os.symlink(fileName, storageFilePath) if progressCallback: progressCallback(1, 1) return 1
def getPackage(self, pkg, msgCallback = None, progressCallback = None): pkgFileName = "%s-%s-%s.%s.rpm" % (pkg[0], pkg[1], pkg[2], pkg[4]) channels = rhnChannel.getChannels() channel = channels.getByLabel(pkg[6]) # if msgCallback: # msgCallback(pkgFileName) storageFilePath = "%s/%s" % (self.cfg["storageDir"], pkgFileName) # symlink the file from /var/spool/up2date to whereever it is... # fileName = "%s/%s" % (channel['path'], pkgFileName) fileName = pkg[7] if (channel['path'] != self.cfg['storageDir']): try: os.remove(storageFilePath) except OSError: pass os.symlink(fileName, storageFilePath) if progressCallback: progressCallback(1,1) return 1
def getPackage(self, package, msgCallback=None, progressCallback=None): filename = "%s-%s-%s.%s.rpm" % (package[0], package[1], package[2], package[4]) channels = rhnChannel.getChannels() channel = channels.getByLabel(package[6]) filePath = "%s/%s" % (self.cfg["storageDir"], filename) # FIXME: apt has some more sophisticated logic for actually finding # the package that this, probabaly need to implement to support # most repos url = "%s/RPMS.%s/%s" % (channel["url"], channel["dist"], filename) if msgCallback: # DEBUG msgCallback(filename) fd = open(filePath, "w+") (lmtime) = urlUtils.fetchUrlAndWriteFD( url, fd, progressCallback=progressCallback, agent="Up2date %s/Apt" % up2dateUtils.version() ) fd.close() buffer = open(filePath, "r").read() return buffer
def testUpdateChannels(self): "Test rhnChannel.updateChannels" channels = rhnChannel.getChannels() res = rhnChannel.updateChannels(channels)
def testGetChannels(self): "Test rhnChannel.getChannels()" res = rhnChannel.getChannels() write(res)
def get_subscribed_channels_list(self, rpc_session, session_key): try: channels = getChannels().channels() except Exception, e: log.exception(e) system_exit(os.EX_SOFTWARE, _("Problem encountered getting the list of subscribed channels. ") + SEE_LOG_FILE)
print 'DEBUGPRINT unknown ', dir(obj) print ' repr', obj print ' dir', dir(obj) print registered = getSystemId('rhel3as-i386') up2dateAuth.updateLoginInfo() cfg = config.initUp2dateConfig() repos = repoDirector.initRepoDirector() ### Print channels debugprint(rhnChannel) debugprint(rhnChannel.rhnChannelList()) debugprint(rhnChannel.rhnChannelList().list) debugprint(rhnChannel.getChannels(force=1)) debugprint(rhnChannel.getChannels(force=1).list) for channel in rhnChannel.rhnChannelList().list: print channel['label'], print for channel in rhnChannel.getChannels(force=1).list: print channel['label'], print for channel in repos.channels.list: print channel['label'], print for channel in subscribedChannels(): print channel['label'],
else: print 'DEBUGPRINT unknown ', dir(obj) print ' repr', obj print ' dir', dir(obj) print registered = getSystemId('rhel3as-i386') up2dateAuth.updateLoginInfo() cfg = config.initUp2dateConfig() repos = repoDirector.initRepoDirector() ### Print channels debugprint(rhnChannel) debugprint(rhnChannel.rhnChannelList()) debugprint(rhnChannel.rhnChannelList().list) debugprint(rhnChannel.getChannels(force=1)) debugprint(rhnChannel.getChannels(force=1).list) for channel in rhnChannel.rhnChannelList().list: print channel['label'], print for channel in rhnChannel.getChannels(force=1).list: print channel['label'], print for channel in repos.channels.list: print channel['label'], print for channel in subscribedChannels(): print channel['label'], print #sys.exit(0) debugprint(up2dateAuth.getLoginInfo())