Beispiel #1
0
    def getPackageSource(self, channel, package, msgCallback = None, progressCallback = None):
        filename = package
        filePath = "%s/%s" % (self.cfg["storageDir"], filename)

        if msgCallback:
            msgCallback(package)
            
        # interesting, yum doesnt seem to let you specify a path for the
        # source rpm...

        # Actually, it does now, but I need to download another meta data
        # file to do it, will do but not till .16 or so

        url = "%s/SRPMS/%s" % (channel['url'], 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
Beispiel #2
0
    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
Beispiel #3
0
    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
Beispiel #4
0
    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
Beispiel #5
0
    def getPackageSource(self,
                         channel,
                         package,
                         msgCallback=None,
                         progressCallback=None):
        filename = package
        filePath = "%s/%s" % (self.cfg["storageDir"], filename)

        if msgCallback:
            msgCallback(package)

        # interesting, yum doesnt seem to let you specify a path for the
        # source rpm...

        # Actually, it does now, but I need to download another meta data
        # file to do it, will do but not till .16 or so

        url = "%s/SRPMS/%s" % (channel['url'], 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
Beispiel #6
0
def getGETServer(logininfo, serverSettings):
    server= rpcServer.RetryGETServer(serverSettings.serverList.server(),
                                     proxy = serverSettings.proxyUrl,
                                     username = serverSettings.proxyUser,
                                     password = serverSettings.proxyPassword,
                                     headers = logininfo)
    server.add_header("X-Up2date-Version", up2dateUtils.version())
    server.addServerList(serverSettings.serverList)
    return server
Beispiel #7
0
def getGETServer(logininfo, serverSettings):
    server = rpcServer.RetryGETServer(serverSettings.serverList.server(),
                                      proxy=serverSettings.proxyUrl,
                                      username=serverSettings.proxyUser,
                                      password=serverSettings.proxyPassword,
                                      headers=logininfo)
    server.add_header("X-Up2date-Version", up2dateUtils.version())
    server.addServerList(serverSettings.serverList)
    return server
Beispiel #8
0
 def __versionString():
     versionString = (
         _(
             "%%prog (Red Hat Network Client Tools) %s\n"
             "Copyright (C) 1999--2012 Red Hat, Inc.\n"
             "Licensed under the terms of the GPLv2."
         )
         % up2dateUtils.version()
     )
     return versionString
Beispiel #9
0
    def getPackageSource(self, channel, package, msgCallback=None, progressCallback=None):
        filename = package
        filePath = "%s/%s" % (self.cfg["storageDir"], filename)

        if msgCallback:
            msgCallback(filename)
        url = "%s/SRPMS.%s/%s" % (channel["url"], channel["dist"], 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
Beispiel #10
0
    def getPackageSource(self,
                         channel,
                         package,
                         msgCallback=None,
                         progressCallback=None):
        filename = package
        filePath = "%s/%s" % (self.cfg["storageDir"], filename)

        if msgCallback:
            msgCallback(filename)
        url = "%s/SRPMS.%s/%s" % (channel['url'], channel['dist'], 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
Beispiel #11
0
    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
Beispiel #12
0
    def get_server(self, refreshCallback=None, serverOverride=None, timeout=None):
        """
        Moved from rpcServer.
        """
        ca = self.cfg["sslCACert"]
        if isinstance(ca, basestring):
            ca = [ca]

        rhns_ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"]
        if self.cfg["enableProxy"]:
            proxy_host = config.getProxySetting()
        else:
            proxy_host = None

        if not serverOverride:
            server_urls = config.getServerlURL()
        else:
            server_urls = serverOverride
        server_list = rpcServer.ServerList(server_urls)

        proxy_user = None
        proxy_password = None
        if self.cfg["enableProxyAuth"]:
            proxy_user = self.cfg["proxyUser"] or None
            proxy_password = self.cfg["proxyPassword"] or None

        lang = None
        for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG':
            if os.environ.get(env):
                lang = os.environ[env].split(':')[0].split('.')[0]
                break
            else:
                continue

        retry_server = rpcServer.RetryServer(server_list.server(),
                                             refreshCallback=refreshCallback,
                                             proxy=proxy_host,
                                             username=proxy_user,
                                             password=proxy_password)
        retry_server.addServerList(server_list)
        retry_server.add_header("X-Up2date-Version", up2dateUtils.version())

        if lang:
            retry_server.setlang(lang)

        # require RHNS-CA-CERT file to be able to authenticate the SSL connections
        need_ca = [True for i in retry_server.serverList.serverList if urlparse.urlparse(i)[0] == 'https']
        if need_ca:
            for rhns_ca_cert in rhns_ca_certs:
                if not os.access(rhns_ca_cert, os.R_OK):
                    msg = "%s: %s" % ("ERROR: can not find RHNS CA file", rhns_ca_cert)
                    log.log_me("%s" % msg)
                    raise up2dateErrors.SSLCertificateFileNotFound(msg)

                # force the validation of the SSL cert
                retry_server.add_trusted_cert(rhns_ca_cert)

        clientCaps.loadLocalCaps()

        # send up the capabality info
        header_list = clientCaps.caps.headerFormat()
        for (headerName, value) in header_list:
            retry_server.add_header(headerName, value)

        return retry_server
Beispiel #13
0
 def __versionString():
     versionString = _(
         "%%prog (Spacewalk Client Tools) %s\n"
         "Copyright (C) 1999--2014 Red Hat, Inc.\n"
         "Licensed under the terms of the GPLv2.") % up2dateUtils.version()
     return versionString
Beispiel #14
0
    def listPackages(self, channel, msgCallback=None, progressCallback=None):

        # TODO: implement cache invalidations, Last-Modified
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel["label"], channel["version"])

        # a glob used to find the old versions to cleanup
        globPattern = "%s/%s.*" % (self.cfg["storageDir"], channel["label"])
        oldLists = glob.glob(globPattern)
        channelTimeStamp = None
        if oldLists:
            filename = oldLists[0]
            filename = os.path.basename(filename)
            oldVersion = string.split(filename, ".")[-1]
            channelTimeStamp = time.strptime(oldVersion, "%Y%m%d%H%M%S")

        # assuming this is always bz2?
        url = "%s/base/pkglist.%s.bz2" % (channel["url"], channel["dist"])
        if msgCallback:
            msgCallback("Fetching %s" % url)

        ret = urlUtils.fetchUrl(
            url,
            lastModified=channelTimeStamp,
            progressCallback=progressCallback,
            agent="Up2date %s/Apt" % up2dateUtils.version(),
        )
        if ret:
            (buffer, lmtime) = ret
        else:
            return None

        symlinkname = "%s/link-%s" % (self.cfg["storageDir"], channel["label"])
        try:
            os.unlink(symlinkname)
        except OSError:
            # file doesnt exist, shrug
            pass

        self.version = time.strftime("%Y%m%d%H%M%S", lmtime)
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel["label"], self.version)

        # sigh, no native bzip2 module... do it the old fashioned way
        tmpfilename = "%s/tmp-%s-%s" % (self.cfg["storageDir"], channel["label"], self.version)
        # print "timefilename: %s" % tmpfilename
        f = open("%s.bz2" % tmpfilename, "w")
        f.write(buffer)
        f.close()

        # FIXME, um, lame... once we settle on what url/http lib
        # we use, plugin in proper callbacks
        if progressCallback:
            progressCallback(1, 1)

        # well, since we dont have any knowledge about what the
        # channel version is supposed to be, I'cant really rely
        # on that (with up2date, the login tells me what channel
        # versions to look for). So we need a generic name
        # we symlink to the latest version.

        pipe = os.popen("/usr/bin/bunzip2 %s.bz2" % tmpfilename)
        tmp = pipe.read()

        os.symlink(tmpfilename, symlinkname)

        hdrList = rpm.readHeaderListFromFile(tmpfilename)
        # a list of rpm hdr's, handy!!

        pkgList = []

        for hdr in hdrList:
            epoch = hdr["epoch"]
            if epoch == None or epoch == "0" or epoch == 0:
                epoch = ""
            pkgList.append(
                [
                    hdr["name"],
                    hdr["version"],
                    hdr["release"],
                    epoch,
                    hdr["arch"],
                    # we want the actual filesize, but alas...
                    str(hdr["size"]),
                    channel["label"],
                ]
            )

            # what the hell, this is a little bit of a side effect, but
            # were already poking at headers, lets just save them while
            # were at it to same us some trouble
            rpmSourceUtils.saveHeader(hdr)
            self.headerCache["%s-%s-%s.%s" % (hdr["name"], hdr["version"], hdr["release"], hdr["arch"])] = hdr

        # nowwe have the package list, convert it to xmlrpc style
        # presentation and dump it
        pkgList.sort(lambda a, b: cmp(a[0], b[0]))

        rpmSourceUtils.saveListToDisk(pkgList, filePath, globPattern)

        return pkgList
Beispiel #15
0
def getServer(refreshCallback=None, serverOverride=None, timeout=None):
    log = up2dateLog.initLog()
    cfg = config.initUp2dateConfig()

    # Where do we keep the CA certificate for RHNS?
    # The servers we're talking to need to have their certs
    # signed by one of these CA.
    ca = cfg["sslCACert"]
    if not isinstance(ca, list):
        ca = [ca]

    rhns_ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"]
    if cfg["enableProxy"]:
        proxyHost = config.getProxySetting()
    else:
        proxyHost = None

    if not serverOverride:
        serverUrls = config.getServerlURL()
    else:
        serverUrls = serverOverride
    serverList = ServerList(serverUrls)

    proxyUser = None
    proxyPassword = None
    if cfg["enableProxyAuth"]:
        proxyUser = cfg["proxyUser"] or None
        proxyPassword = cfg["proxyPassword"] or None

    lang = None
    for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG':
        if env in os.environ:
            if not os.environ[env]:
                # sometimes unset
                continue
            lang = os.environ[env].split(':')[0]
            lang = lang.split('.')[0]
            break


    s = RetryServer(serverList.server(),
                    refreshCallback=refreshCallback,
                    proxy=proxyHost,
                    username=proxyUser,
                    password=proxyPassword,
                    timeout=timeout)
    s.addServerList(serverList)

    s.add_header("X-Up2date-Version", up2dateUtils.version())

    if lang:
        s.setlang(lang)

    # require RHNS-CA-CERT file to be able to authenticate the SSL connections
    need_ca = [ True for i in s.serverList.serverList
                     if urlparse.urlparse(i)[0] == 'https']
    if need_ca:
        for rhns_ca_cert in rhns_ca_certs:
            if not os.access(rhns_ca_cert, os.R_OK):
                msg = "%s: %s" % (_("ERROR: can not find RHNS CA file"),
                                     rhns_ca_cert)
                log.log_me("%s" % msg)
                raise up2dateErrors.SSLCertificateFileNotFound(msg)

            # force the validation of the SSL cert
            s.add_trusted_cert(rhns_ca_cert)

    clientCaps.loadLocalCaps()

    # send up the capabality info
    headerlist = clientCaps.caps.headerFormat()
    for (headerName, value) in headerlist:
        s.add_header(headerName, value)
    return s
Beispiel #16
0
    def listPackages(self, channel,
                     msgCallback = None, progressCallback = None):

        # TODO: where do we implement cache validation? guess we
        # use http header time stamps to make a best guess since we
        # dont have any real info about the file format
        
        # a glob used to find the old versions to cleanup

        # FIXME: this is probabaly overkill... Should only have
        # one version of any given
        globPattern = "%s/%s.*" % (self.cfg["storageDir"], channel['label'])
        oldLists = glob.glob(globPattern)
        channelTimeStamp = None
        if oldLists:
            filename = oldLists[0]
            filename = os.path.basename(filename)
            oldVersion = string.split(filename, '.')[-1]
            channelTimeStamp = time.strptime(oldVersion,"%Y%m%d%H%M%S")


        # for yum stuff, we assume that serverUrl is the base
        # path, channel is the relative path, and version isnt
        # user
        url = "%s/headers/header.info" % (channel['url'])
        if msgCallback:
            msgCallback("Fetching %s" % url)

        # oh, this lame, but implement a fancy url fetcher later
        # heck, maybe even borrow the one from yum
        #print urlUtils
        
        ret = urlUtils.fetchUrl(url, lastModified=channelTimeStamp,
                                progressCallback = progressCallback,
                                agent = "Up2date %s/Yum" % up2dateUtils.version())
        
        if ret:
            (buffer, lmtime) = ret
        else:
            return None

        if not lmtime:
            lmtime = time.gmtime(time.time())
        version = time.strftime("%Y%m%d%H%M%S", lmtime)
        
        # use the time stamp on the headerlist as the channel "version"
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel['label'], version)

        # it's possible to get bogus data here, so at least try not
        # to traceback
        if buffer:
            lines = string.split(buffer)
        else:
            lines = []

        # this gives us the raw yum header list, which is _not_
        # in the pretty format up2date likes, so convert it
        # and sadly, I can no longer proudly state that up2date
        # at no points attempts to parse rpm filenames into something
        # useful. At least yum includes the epoch
        pkgList = []
        # yum can have a different path for each rpm. Not exactly
        # sure how this meets the "keep it simple" idea, but alas
        self.pkgNamePath = {}
        for line in lines:
            if line == "" or line[0] == "#":
                continue
            (envra, rpmPath) = string.split(line, '=')
            rpmPath = string.strip(rpmPath)
            (epoch, name, ver, rel, arch) = self._stripENVRA(envra)
            # quite possibly need to encode channel info here as well
	    if epoch == "0" or epoch == 0:
                epoch = ""

            # hmm, if an arch doesnt apply, guess no point in
            # keeping it around, should make package lists smaller
            # and cut down on some churn
            if rpm.archscore(arch) == 0:
                continue



            self.pkgNamePath[(name,ver,rel,epoch,arch)] = rpmPath
            # doh, no size info. FIXME
            size = "1000"  # er, yeah... thats not lame at all...
            pkgList.append([name, ver, rel, epoch, arch, size, channel['label'], rpmPath])

        # now we have the package list, convert it to xmlrpc style
        # presentation and dump it
        pkgList.sort(lambda a, b: cmp(a[0], b[0]))
        
        count = 0
        total = len(pkgList)
        rd = repoDirector.initRepoDirector()
        
        for pkg in pkgList:
            # were deep down in the yum specific bits, but we want to call
            # the generic getHeader to get it off disc or cache
            
            hdr = rd.getHeader([name,ver,rel,epoch,arch, "0",channel['label']])
            if progressCallback:
                progressCallback(count, total)
            count = count + 1

        rpmSourceUtils.saveListToDisk(pkgList, filePath, globPattern)
        self.pkglists[channel['label']] = pkgList
        return pkgList
Beispiel #17
0
    def listPackages(self, channel, msgCallback=None, progressCallback=None):

        # TODO: implement cache invalidations, Last-Modified
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel['label'],
                                 channel['version'])

        # a glob used to find the old versions to cleanup
        globPattern = "%s/%s.*" % (self.cfg["storageDir"], channel['label'])
        oldLists = glob.glob(globPattern)
        channelTimeStamp = None
        if oldLists:
            filename = oldLists[0]
            filename = os.path.basename(filename)
            oldVersion = string.split(filename, '.')[-1]
            channelTimeStamp = time.strptime(oldVersion, "%Y%m%d%H%M%S")

        # assuming this is always bz2?
        url = "%s/base/pkglist.%s.bz2" % (channel['url'], channel['dist'])
        if msgCallback:
            msgCallback("Fetching %s" % url)

        ret = urlUtils.fetchUrl(url,
                                lastModified=channelTimeStamp,
                                progressCallback=progressCallback,
                                agent="Up2date %s/Apt" %
                                up2dateUtils.version())
        if ret:
            (buffer, lmtime) = ret
        else:
            return None

        symlinkname = "%s/link-%s" % (self.cfg["storageDir"], channel['label'])
        try:
            os.unlink(symlinkname)
        except OSError:
            # file doesnt exist, shrug
            pass

        self.version = time.strftime("%Y%m%d%H%M%S", lmtime)
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel['label'],
                                 self.version)

        # sigh, no native bzip2 module... do it the old fashioned way
        tmpfilename = "%s/tmp-%s-%s" % (self.cfg['storageDir'],
                                        channel['label'], self.version)
        #print "timefilename: %s" % tmpfilename
        f = open("%s.bz2" % tmpfilename, "w")
        f.write(buffer)
        f.close()

        # FIXME, um, lame... once we settle on what url/http lib
        # we use, plugin in proper callbacks
        if progressCallback:
            progressCallback(1, 1)

        # well, since we dont have any knowledge about what the
        # channel version is supposed to be, I'cant really rely
        # on that (with up2date, the login tells me what channel
        # versions to look for). So we need a generic name
        # we symlink to the latest version.

        pipe = os.popen("/usr/bin/bunzip2 %s.bz2" % tmpfilename)
        tmp = pipe.read()

        os.symlink(tmpfilename, symlinkname)

        hdrList = rpm.readHeaderListFromFile(tmpfilename)
        # a list of rpm hdr's, handy!!

        pkgList = []

        for hdr in hdrList:
            epoch = hdr['epoch']
            if epoch == None or epoch == "0" or epoch == 0:
                epoch = ""
            pkgList.append([
                hdr['name'],
                hdr['version'],
                hdr['release'],
                epoch,
                hdr['arch'],
                # we want the actual filesize, but alas...
                str(hdr['size']),
                channel['label']
            ])

            # what the hell, this is a little bit of a side effect, but
            # were already poking at headers, lets just save them while
            # were at it to same us some trouble
            rpmSourceUtils.saveHeader(hdr)
            self.headerCache["%s-%s-%s.%s" %
                             (hdr['name'], hdr['version'], hdr['release'],
                              hdr['arch'])] = hdr

        # nowwe have the package list, convert it to xmlrpc style
        # presentation and dump it
        pkgList.sort(lambda a, b: cmp(a[0], b[0]))

        rpmSourceUtils.saveListToDisk(pkgList, filePath, globPattern)

        return pkgList
Beispiel #18
0
    def listPackages(self, channel, msgCallback=None, progressCallback=None):

        # TODO: where do we implement cache validation? guess we
        # use http header time stamps to make a best guess since we
        # dont have any real info about the file format

        # a glob used to find the old versions to cleanup

        # FIXME: this is probabaly overkill... Should only have
        # one version of any given
        globPattern = "%s/%s.*" % (self.cfg["storageDir"], channel['label'])
        oldLists = glob.glob(globPattern)
        channelTimeStamp = None
        if oldLists:
            filename = oldLists[0]
            filename = os.path.basename(filename)
            oldVersion = string.split(filename, '.')[-1]
            channelTimeStamp = time.strptime(oldVersion, "%Y%m%d%H%M%S")

        # for yum stuff, we assume that serverUrl is the base
        # path, channel is the relative path, and version isnt
        # user
        url = "%s/headers/header.info" % (channel['url'])
        if msgCallback:
            msgCallback("Fetching %s" % url)

        # oh, this lame, but implement a fancy url fetcher later
        # heck, maybe even borrow the one from yum
        #print urlUtils

        ret = urlUtils.fetchUrl(url,
                                lastModified=channelTimeStamp,
                                progressCallback=progressCallback,
                                agent="Up2date %s/Yum" %
                                up2dateUtils.version())

        if ret:
            (buffer, lmtime) = ret
        else:
            return None

        if not lmtime:
            lmtime = time.gmtime(time.time())
        version = time.strftime("%Y%m%d%H%M%S", lmtime)

        # use the time stamp on the headerlist as the channel "version"
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel['label'],
                                 version)

        # it's possible to get bogus data here, so at least try not
        # to traceback
        if buffer:
            lines = string.split(buffer)
        else:
            lines = []

        # this gives us the raw yum header list, which is _not_
        # in the pretty format up2date likes, so convert it
        # and sadly, I can no longer proudly state that up2date
        # at no points attempts to parse rpm filenames into something
        # useful. At least yum includes the epoch
        pkgList = []
        # yum can have a different path for each rpm. Not exactly
        # sure how this meets the "keep it simple" idea, but alas
        self.pkgNamePath = {}
        for line in lines:
            if line == "" or line[0] == "#":
                continue
            (envra, rpmPath) = string.split(line, '=')
            rpmPath = string.strip(rpmPath)
            (epoch, name, ver, rel, arch) = self._stripENVRA(envra)
            # quite possibly need to encode channel info here as well
            if epoch == "0" or epoch == 0:
                epoch = ""

            # hmm, if an arch doesnt apply, guess no point in
            # keeping it around, should make package lists smaller
            # and cut down on some churn
            if rpm.archscore(arch) == 0:
                continue

            self.pkgNamePath[(name, ver, rel, epoch, arch)] = rpmPath
            # doh, no size info. FIXME
            size = "1000"  # er, yeah... thats not lame at all...
            pkgList.append(
                [name, ver, rel, epoch, arch, size, channel['label'], rpmPath])

        # now we have the package list, convert it to xmlrpc style
        # presentation and dump it
        pkgList.sort(lambda a, b: cmp(a[0], b[0]))

        count = 0
        total = len(pkgList)
        rd = repoDirector.initRepoDirector()

        for pkg in pkgList:
            # were deep down in the yum specific bits, but we want to call
            # the generic getHeader to get it off disc or cache

            hdr = rd.getHeader(
                [name, ver, rel, epoch, arch, "0", channel['label']])
            if progressCallback:
                progressCallback(count, total)
            count = count + 1

        rpmSourceUtils.saveListToDisk(pkgList, filePath, globPattern)
        self.pkglists[channel['label']] = pkgList
        return pkgList
def getServer(refreshCallback=None, serverOverride=None, timeout=None):
    log = up2dateLog.initLog()
    cfg = config.initUp2dateConfig()

    # Where do we keep the CA certificate for RHNS?
    # The servers we're talking to need to have their certs
    # signed by one of these CA.
    ca = cfg["sslCACert"]
    if not isinstance(ca, list):
        ca = [ca]

    rhns_ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"]
    if cfg["enableProxy"]:
        proxyHost = config.getProxySetting()
    else:
        proxyHost = None

    if not serverOverride:
        serverUrls = config.getServerlURL()
    else:
        serverUrls = serverOverride
    serverList = ServerList(serverUrls)

    proxyUser = None
    proxyPassword = None
    if cfg["enableProxyAuth"]:
        proxyUser = cfg["proxyUser"] or None
        proxyPassword = cfg["proxyPassword"] or None

    lang = None
    for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG':
        if env in os.environ:
            if not os.environ[env]:
                # sometimes unset
                continue
            lang = os.environ[env].split(':')[0]
            lang = lang.split('.')[0]
            break

    s = RetryServer(serverList.server(),
                    refreshCallback=refreshCallback,
                    proxy=proxyHost,
                    username=proxyUser,
                    password=proxyPassword,
                    timeout=timeout)
    s.addServerList(serverList)

    s.add_header("X-Up2date-Version", up2dateUtils.version())

    if lang:
        s.setlang(lang)

    # require RHNS-CA-CERT file to be able to authenticate the SSL connections
    need_ca = [
        True for i in s.serverList.serverList
        if urlparse.urlparse(i)[0] == 'https'
    ]
    if need_ca:
        for rhns_ca_cert in rhns_ca_certs:
            if not os.access(rhns_ca_cert, os.R_OK):
                msg = "%s: %s" % (_("ERROR: can not find RHNS CA file"),
                                  rhns_ca_cert)
                log.log_me("%s" % msg)
                raise up2dateErrors.SSLCertificateFileNotFound(msg)

            # force the validation of the SSL cert
            s.add_trusted_cert(rhns_ca_cert)

    clientCaps.loadLocalCaps()

    # send up the capabality info
    headerlist = clientCaps.caps.headerFormat()
    for (headerName, value) in headerlist:
        s.add_header(headerName, value)
    return s