Example #1
0
    def _cache_channel_packages_short(self, channel_id, key, last_modified):
        """ Caches the short package entries for channel_id """
        # Create a temporary file
        temp_stream = tempfile.TemporaryFile()
        # Always compress the result
        compress_level = 5
        stream = gzip.GzipFile(None, "wb", compress_level, temp_stream)
        writer = xmlWriter.XMLWriter(stream=stream)

        # Fetch packages
        h = rhnSQL.prepare(self._query_get_channel_packages)
        h.execute(channel_id=channel_id)
        package_ids = h.fetchall_dict() or []
        # Sort packages
        package_ids.sort(lambda a, b: cmp(a['package_id'], b['package_id']))

        dumper = SatelliteDumper(writer,
                                 ShortPackagesDumper(writer, package_ids))
        dumper.dump()
        writer.flush()
        # We're done with the stream object
        stream.close()
        del stream
        temp_stream.seek(0, 0)
        # Set the value in the cache. We don't recompress the result since
        # it's already compressed
        rhnCache.set(key,
                     temp_stream.read(),
                     modified=last_modified,
                     compressed=0,
                     raw=1)
        return self._normalize_compressed_stream(temp_stream)
Example #2
0
    def dump_subelement(self, data):
        log_debug(2)
        # CachedQueryIterator returns (params, row) as data
        params, row = data
        s = StringIO()
        # Back up the old writer and replace it with a StringIO-based one
        ow = self.get_writer()
        # Use into a tee stream (which writes to both streams at the same
        # time)
        tee_stream = TeeStream(s, ow.stream)
        self.set_writer(xmlWriter.XMLWriter(stream=tee_stream, skip_xml_decl=1))

        start = time.time()
        # call dump_subelement() from original (non-cached) class
        self.non_cached_class.dump_subelement(self, row)
        log_debug(5,
                  "Timer for _dump_subelement: %.2f" % (time.time() - start))

        # Restore the old writer
        self.set_writer(ow)

        self.cache_set(params, s.getvalue())
Example #3
0
 def _get_xml_writer(self):
     return xmlWriter.XMLWriter(stream=StringBuffer(self))
Example #4
0
#
# Copyright (c) 2008--2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
from spacewalk.server import rhnSQL
from spacewalk.satellite_tools.exporter import xmlWriter, exportLib

rhnSQL.initDB()

w = xmlWriter.XMLWriter(skip_xml_decl=1)

e = exportLib.KickstartableTreesDumper(w)
e.dump()
Example #5
0
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
import sys
import StringIO
from spacewalk.server import rhnSQL
from spacewalk.satellite_tools import xmlSource
from spacewalk.satellite_tools.exporter import xmlWriter, exportLib

rhnSQL.initDB()

s = StringIO.StringIO()
writer = xmlWriter.XMLWriter(stream=s)

channels = ['redhat-advanced-server-i386']


class ChannelsDumper(exportLib.ChannelsDumper):
    _query_list_channels = rhnSQL.Statement("""
        select c.id, c.label, ca.label channel_arch, c.basedir, c.name,
               c.summary, c.description,
               TO_CHAR(c.last_modified, 'YYYYMMDDHH24MISS') last_modified,
               pc.label parent_channel
          from rhnChannel c left outer join rhnChannel pc on c.parent_channel = pc.id,
               rhnChannelArch ca
         where c.label = :channel
           and c.channel_arch_id = ca.id
    """)