def __init__(self): usage = "usage: %prog rhn [OPTIONS]" shortdesc = "Fetches content from a rhn source." desc = "rhn" CliDriver.__init__(self, "rhn", usage, shortdesc, desc) GrinderLog.setup(self.debug) self.rhnSync = RHNSync() self.parser.add_option('-a', '--all', action='store_true', help='Fetch ALL packages from a channel, not just latest') self.parser.add_option('-b', '--basepath', action='store', help='Path RPMs are stored') self.parser.add_option('-c', '--certfile', action='store', help='Entitlement Certificate') self.parser.add_option('-C', '--config', action='store', help='Configuration file') self.parser.add_option('-k', '--kickstarts', action='store_true', help='Sync all kickstart trees for channels specified') self.parser.add_option('-K', '--skippackages', action='store_true', help='Skip sync of packages', default=False) self.parser.add_option('-L', '--listchannels', action='store_true', help='List all channels we have access to synchronize') self.parser.add_option('-p', '--password', action='store', help='RHN Password') self.parser.add_option('-P', '--parallel', action='store', help='Number of threads to fetch in parallel.') self.parser.add_option('-r', '--removeold', action='store_true', help='Remove older rpms') self.parser.add_option('-s', '--systemid', action='store', help='System ID') self.parser.add_option('-u', '--username', action='store', help='RHN User Account') self.parser.add_option('-U', '--url', action='store', help='Red Hat Server URL')
class RHNDriver(CliDriver): def __init__(self): usage = "usage: %prog rhn [OPTIONS]" shortdesc = "Fetches content from a rhn source." desc = "rhn" CliDriver.__init__(self, "rhn", usage, shortdesc, desc) GrinderLog.setup(self.debug) self.rhnSync = RHNSync() self.parser.add_option('-a', '--all', action='store_true', help='Fetch ALL packages from a channel, not just latest') self.parser.add_option('-b', '--basepath', action='store', help='Path RPMs are stored') self.parser.add_option('-c', '--certfile', action='store', help='Entitlement Certificate') self.parser.add_option('-C', '--config', action='store', help='Configuration file') self.parser.add_option('-k', '--kickstarts', action='store_true', help='Sync all kickstart trees for channels specified') self.parser.add_option('-K', '--skippackages', action='store_true', help='Skip sync of packages', default=False) self.parser.add_option('-L', '--listchannels', action='store_true', help='List all channels we have access to synchronize') self.parser.add_option('-p', '--password', action='store', help='RHN Password') self.parser.add_option('-P', '--parallel', action='store', help='Number of threads to fetch in parallel.') self.parser.add_option('-r', '--removeold', action='store_true', help='Remove older rpms') self.parser.add_option('-s', '--systemid', action='store', help='System ID') self.parser.add_option('-u', '--username', action='store', help='RHN User Account') self.parser.add_option('-U', '--url', action='store', help='Red Hat Server URL') def _validate_options(self): if self.options.all and self.options.removeold: systemExit(1, "Conflicting options specified 'all' and 'removeold'.") if self.options.config: if not self.rhnSync.loadConfig(self.options.config): systemExit(1, "Unable to parse config file: %s" % (self.options.config)) if self.options.all: self.rhnSync.setFetchAllPackages(self.options.all) if self.options.basepath: self.rhnSync.setBasePath(self.options.basepath) if self.options.url: self.rhnSync.setURL(self.options.url) if self.options.username: self.rhnSync.setUsername(self.options.username) if self.options.password: self.rhnSync.setPassword(self.options.password) if self.options.certfile: cert = open(self.options.certfile, 'r').read() self.rhnSync.setCert(cert) if self.options.systemid: sysid = open(self.options.systemid, 'r').read() self.rhnSync.setSystemId(sysid) if self.options.parallel: self.rhnSync.setParallel(self.options.parallel) if self.options.debug: self.rhnSync.setVerbose(self.options.debug) if self.options.removeold: self.rhnSync.setRemoveOldPackages(self.options.removeold) def _do_command(self): """ Executes the command. """ self._validate_options() if self.options.listchannels: self.rhnSync.displayListOfChannels() else: # Check command line args for bad channel labels badChannels = self.rhnSync.checkChannels(self.args) if len(badChannels) > 0: LOG.critical("Bad channel labels: %s" % (badChannels)) systemExit(1, "Please correct the channel labels you entered, then re-run") channels = self.rhnSync.getChannelSyncList() # Check config file for bad channel labels badChannels = self.rhnSync.checkChannels([x['label'] for x in channels]) if len(badChannels) > 0: LOG.critical("Bad channel labels: %s" % (badChannels)) systemExit(1, "Please correct the channel labels in: %s, then re-run" % (self.options.config)) basePath = self.rhnSync.getBasePath() if not basePath: basePath = "./" for c in self.args: channels.append({'label':c, 'relpath':os.path.join(basePath,c)}) report = {} for info in channels: label = info['label'] savePath = info['relpath'] report[label] = {} if not self.options.skippackages: report[label]["packages"] = self.rhnSync.syncPackages(label, savePath, self.rhnSync.getVerbose()) if self.options.kickstarts: report[label]["kickstarts"] = self.rhnSync.syncKickstarts(label, savePath, self.rhnSync.getVerbose()) for r in report: if report[r].has_key("packages"): print "%s packages = %s" % (r, report[r]["packages"]) if report[r].has_key("kickstarts"): print "%s kickstarts = %s" % (r, report[r]["kickstarts"]) def stop(self): self.rhnSync.stop()