1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import time
17 from spacewalk.common.usix import StringType
18
19 from spacewalk.common import rhnLib
20 from spacewalk.common.rhnLog import log_debug
21 from spacewalk.server import rhnSQL
25
27 self._arr = arr
28 if self._arr:
29 self._pos = 0
30 else:
31
32 self._pos = None
33
36
38 if self._pos is None:
39 return None
40 i = self._pos
41 self._pos = self._pos + 1
42 if self._pos == len(self._arr):
43 self._pos = None
44 return self._arr[i]
45
48
49
50 - def __init__(self, writer, data_iterator=None):
51 self._writer = writer
52 self._attributes = {}
53 self._iterator = data_iterator
54
55
56 @staticmethod
57 - def timer(debug_level, message, function, *args, **kwargs):
62
65
68
70 if not hasattr(self, "tag_name"):
71 raise Exception("Programmer error: subclass did not set tag_name")
72 tag_name = getattr(self, "tag_name")
73 self._attributes = self.set_attributes() or {}
74 self._iterator = self.timer(5, "set_iterator", self.set_iterator)
75
76 if not self._iterator:
77 self._writer.empty_tag(tag_name, attributes=self._attributes)
78 return
79
80 data_found = 0
81 while 1:
82 data = self.timer(6, "fetchone_dict", self._iterator.fetchone_dict)
83 if not data:
84 break
85 if not data_found:
86 data_found = 1
87 self._writer.open_tag(tag_name, attributes=self._attributes)
88
89 if isinstance(data, StringType):
90
91 self._writer.stream.write(data)
92 else:
93 self.timer(6, "dump_subelement", self.dump_subelement, data)
94
95 if data_found:
96 self._writer.close_tag(tag_name)
97 else:
98 self._writer.empty_tag(tag_name, attributes=self._attributes)
99
104
107
109 self._writer = writer
110
113
114 - def __init__(self, writer, tag_name, attributes=None):
118
121
124
125 - def __init__(self, writer, tag_name, value, max_value_bytes=None):
132
140
147
150
152
153 checksum_arr = [{'type': self._row['checksum_type'],
154 'value': self._row['checksum']}]
155 arr = [_ChecksumDumper(self._writer, data_iterator=ArrayIterator(checksum_arr))]
156 return ArrayIterator(arr)
157
168
171
172 subelement_dumper_class = object
173
175 d = self.subelement_dumper_class(self._writer, data)
176 d.dump()
177
182
183 - def __init__(self, writer, start_date=None, end_date=None):
184 if start_date:
185 self.type = 'incremental'
186 else:
187 self.type = 'full'
188 self.start_date = start_date
189 if end_date:
190 self.end_date = end_date
191 else:
192 self.end_date = time.strftime("%Y%m%d%H%M%S")
193 BaseDumper.__init__(self, writer)
194
196 self._writer.open_tag('export-type')
197 self._writer.stream.write(self.type)
198 self._writer.close_tag('export-type')
199 if self.start_date:
200 self._writer.open_tag('export-start-date')
201 self._writer.stream.write(self.start_date)
202 self._writer.close_tag('export-start-date')
203 if self.end_date:
204 self._writer.open_tag('export-end-date')
205 self._writer.stream.write(self.end_date)
206 self._writer.close_tag('export-end-date')
207
210 tag_name = 'rhn-satellite'
211
215
217 return {
218 'version': 'x.y',
219 }
220
223
233
236 tag_name = 'rhn-org'
237
241
242 _query_org_trusts = """
243 select rto.org_trust_id
244 from rhnTrustedOrgs rto
245 where rto.org_id = :org_id
246 """
247
253
255 attributes = {
256 'id': self.org['id'],
257 'name': self.org['name'],
258 }
259 return attributes
260
263 tag_name = 'rhn-orgs'
264
265 - def __init__(self, writer, data_iterator=None):
267
271
274 tag_name = 'rhn-channel-trusted-orgs'
275
280
283 tag_name = 'rhn-channel'
284
285 - def __init__(self, writer, row, start_date=None, end_date=None, use_rhn_date=True, whole_errata=False):
286 BaseRowDumper.__init__(self, writer, row)
287 self.start_date = start_date
288 self.end_date = end_date
289 self.use_rhn_date = use_rhn_date
290 self.whole_errata = whole_errata
291
293 channel_id = self._row['id']
294
295 packages = ["rhn-package-%s" % x for x in self._get_package_ids()]
296
297
298
299 errata = ["rhn-erratum-%s" % x for x in self._get_errata_ids()]
300 ks_trees = self._get_kickstartable_trees()
301
302 return {
303 'channel-id': 'rhn-channel-%s' % channel_id,
304 'label': self._row['label'],
305 'org_id': self._row['org_id'] or "",
306 'channel-arch': self._row['channel_arch'],
307 'packages': ' '.join(packages),
308 'channel-errata': ' '.join(errata),
309 'kickstartable-trees': ' '.join(ks_trees),
310 'sharing': self._row['channel_access'],
311 }
312
313 _query_channel_families = rhnSQL.Statement("""
314 select cf.id, cf.label
315 from rhnChannelFamily cf, rhnChannelFamilyMembers cfm
316 where cfm.channel_family_id = cf.id
317 and cfm.channel_id = :channel_id
318 """)
319 _query_dist_channel_map = rhnSQL.Statement("""
320 select dcm.os, dcm.release, ca.label channel_arch
321 from rhnDistChannelMap dcm, rhnChannelArch ca
322 where dcm.channel_id = :channel_id
323 and dcm.channel_arch_id = ca.id
324 and dcm.org_id is null
325 """)
326
327 _query_get_channel_trusts = rhnSQL.Statement("""
328 select org_trust_id
329 from rhnChannelTrust
330 where channel_id = :channel_id
331 """)
332
334 channel_id = self._row['id']
335 arr = []
336 mappings = [
337 ('rhn-channel-parent-channel', 'parent_channel'),
338 ('rhn-channel-basedir', 'basedir'),
339 ('rhn-channel-name', 'name'),
340 ('rhn-channel-summary', 'summary'),
341 ('rhn-channel-description', 'description'),
342 ('rhn-channel-gpg-key-url', 'gpg_key_url'),
343 ('rhn-channel-checksum-type', 'checksum_type'),
344 ]
345 for k, v in mappings:
346 arr.append(SimpleDumper(self._writer, k, self._row[v]))
347
348 arr.append(SimpleDumper(self._writer, 'rhn-channel-last-modified',
349 _dbtime2timestamp(self._row['last_modified'])))
350 channel_product_details = self._get_channel_product_details()
351 arr.append(SimpleDumper(self._writer, 'rhn-channel-product-name',
352 channel_product_details[0]))
353 arr.append(SimpleDumper(self._writer, 'rhn-channel-product-version',
354 channel_product_details[1]))
355 arr.append(SimpleDumper(self._writer, 'rhn-channel-product-beta',
356 channel_product_details[2]))
357
358 comp_last_modified = self._channel_comps_last_modified()
359 modules_last_modified = self._channel_modules_last_modified()
360 if comp_last_modified is not None:
361 arr.append(SimpleDumper(self._writer, 'rhn-channel-comps-last-modified',
362 _dbtime2timestamp(comp_last_modified[0])))
363 if modules_last_modified is not None:
364 arr.append(SimpleDumper(self._writer, 'rhn-channel-modules-last-modified',
365 _dbtime2timestamp(modules_last_modified[0])))
366
367 h = rhnSQL.prepare(self._query_get_channel_trusts)
368 h.execute(channel_id=channel_id)
369 arr.append(ChannelTrustedOrgsDumper(self._writer, data_iterator=h))
370
371 h = rhnSQL.prepare(self._query_channel_families)
372 h.execute(channel_id=channel_id)
373 arr.append(ChannelFamiliesDumper(self._writer, data_iterator=h,
374 ignore_subelements=1))
375
376 h = rhnSQL.prepare(self._query_dist_channel_map)
377 h.execute(channel_id=channel_id)
378 arr.append(DistsDumper(self._writer, h))
379
380
381 h = self._get_cursor_source_packages()
382 arr.append(ChannelSourcePackagesDumper(self._writer, h))
383
384 query_args = {'channel_id': channel_id}
385 if self.start_date:
386 if self.use_rhn_date:
387 query = self._query__get_errata_ids_by_rhnlimits
388 else:
389 query = self._query__get_errata_ids_by_limits
390 query_args.update({'lower_limit': self.start_date,
391 'upper_limit': self.end_date})
392 else:
393 query = self._query__get_errata_ids
394
395 h = rhnSQL.prepare(query)
396 h.execute(**query_args)
397 arr.append(ChannelErrataDumper(self._writer, h))
398 arr.append(ExportTypeDumper(self._writer, self.start_date, self.end_date))
399
400 return ArrayIterator(arr)
401
402 _query_get_package_ids = rhnSQL.Statement("""
403 select package_id as id
404 from rhnChannelPackage
405 where channel_id = :channel_id
406 """)
407
408 _query_get_package_ids_by_date_limits = rhnSQL.Statement("""
409 select package_id as id
410 from rhnChannelPackage rcp
411 where rcp.channel_id = :channel_id
412 and rcp.modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
413 and rcp.modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS')
414 """)
415
416 _query_get_package_ids_by_rhndate_limits = rhnSQL.Statement("""
417 select package_id as id
418 from rhnPackage rp, rhnChannelPackage rcp
419 where rcp.channel_id = :channel_id
420 and rcp.package_id = rp.id
421 and rp.last_modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
422 and rp.last_modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS')
423 """)
424
425 _query_pkgids_by_date_whole_errata = rhnSQL.Statement("""
426 select rcp.package_id as id
427 from rhnChannelPackage rcp, rhnPackage rp
428 left join rhnErrataPackage rep on rp.id = rep.package_id
429 left join rhnErrata re on rep.errata_id = re.id
430 where rcp.channel_id = :channel_id
431 and rcp.package_id = rp.id
432 and ((re.modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
433 and re.modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS')
434 ) or (rep.package_id is NULL
435 and rcp.modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
436 and rcp.modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS'))
437 )
438 """)
439
440 _query_get_pkgids_by_rhndate_whole_errata = rhnSQL.Statement("""
441 select rcp.package_id as id
442 from rhnChannelPackage rcp, rhnPackage rp
443 left join rhnErrataPackage rep on rp.id = rep.package_id
444 left join rhnErrata re on rep.errata_id = re.id
445 where rcp.channel_id = :channel_id
446 and rcp.package_id = rp.id
447 and ((re.last_modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
448 and re.last_modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS')
449 ) or (rep.package_id is NULL
450 and rp.last_modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
451 and rp.last_modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS'))
452 )
453 """)
454
455
465
466 - def _get_ids(self, query_with_limit, query_with_rhnlimit, query_no_limits):
467 query_args = {'channel_id': self._row['id']}
468 if self.start_date:
469 if self.use_rhn_date:
470 query = query_with_rhnlimit
471 else:
472 query = query_with_limit
473 query_args.update({'lower_limit': self.start_date,
474 'upper_limit': self.end_date})
475 else:
476 query = query_no_limits
477 h = rhnSQL.prepare(query)
478 h.execute(**query_args)
479 return [x['id'] for x in h.fetchall_dict() or []]
480
481 _query_get_source_package_ids = rhnSQL.Statement("""
482 select distinct ps.id, sr.name source_rpm,
483 TO_CHAR(ps.last_modified, 'YYYYMMDDHH24MISS') last_modified
484 from rhnChannelPackage cp, rhnPackage p, rhnPackageSource ps,
485 rhnSourceRPM sr
486 where cp.channel_id = :channel_id
487 and cp.package_id = p.id
488 and p.source_rpm_id = ps.source_rpm_id
489 and ((p.org_id is null and ps.org_id is null) or
490 p.org_id = ps.org_id)
491 and ps.source_rpm_id = sr.id
492 """)
493
500
501 _query__get_errata_ids = rhnSQL.Statement("""
502 select ce.errata_id as id, e.advisory_name,
503 TO_CHAR(e.last_modified, 'YYYYMMDDHH24MISS') last_modified
504 from rhnChannelErrata ce, rhnErrata e
505 where ce.channel_id = :channel_id
506 and ce.errata_id = e.id
507 """)
508
509 _query__get_errata_ids_by_limits = rhnSQL.Statement("""
510 %s
511 and ce.modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
512 and ce.modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS')
513 """ % _query__get_errata_ids)
514
515 _query__get_errata_ids_by_rhnlimits = rhnSQL.Statement("""
516 %s
517 and e.last_modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
518 and e.last_modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS')
519 """ % _query__get_errata_ids)
520
525
526 _query_get_kickstartable_trees = rhnSQL.Statement("""
527 select kt.label as id
528 from rhnKickstartableTree kt
529 where kt.channel_id = :channel_id
530 and kt.org_id is null
531 """)
532
533 _query_get_kickstartable_trees_by_rhnlimits = rhnSQL.Statement("""
534 %s
535 and kt.last_modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
536 and kt.last_modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS')
537 """ % _query_get_kickstartable_trees)
538
539 _query_get_kickstartable_trees_by_limits = rhnSQL.Statement("""
540 %s
541 and kt.modified >= TO_TIMESTAMP(:lower_limit, 'YYYYMMDDHH24MISS')
542 and kt.modified <= TO_TIMESTAMP(:upper_limit, 'YYYYMMDDHH24MISS')
543 """ % _query_get_kickstartable_trees)
544
551
552 _query_get_channel_product_details = rhnSQL.Statement("""
553 select cp.product as name,
554 cp.version as version,
555 cp.beta
556 from rhnChannel c,
557 rhnChannelProduct cp
558 where c.id = :channel_id
559 and c.channel_product_id = cp.id
560 """)
561
563 """
564 Export rhnChannelProduct table content through ChannelDumper
565
566 return a tuple containing (product name, product version, beta status)
567 or (None, None, None) if the information is missing
568 """
569
570 channel_id = self._row['id']
571
572 h = rhnSQL.prepare(self._query_get_channel_product_details)
573 h.execute(channel_id=channel_id)
574 row = h.fetchone_dict()
575 if not row:
576 return (None, None, None)
577 else:
578 return (row['name'], row['version'], row['beta'])
579
580 _query_channel_comps_last_modified = rhnSQL.Statement("""
581 select to_char(last_modified, 'YYYYMMDDHH24MISS') as comps_last_modified
582 from rhnChannelComps
583 where channel_id = :channel_id
584 and comps_type_id = 1
585 order by id desc
586 """)
587
593
594 _query_channel_modules_last_modified = rhnSQL.Statement("""
595 select to_char(last_modified, 'YYYYMMDDHH24MISS') as modules_last_modified
596 from rhnChannelComps
597 where channel_id = :channel_id
598 and comps_type_id = 2
599 order by id desc
600 """)
601
607
610 tag_name = 'rhn-channels'
611 subelement_dumper_class = _ChannelDumper
612
613 - def __init__(self, writer, channels=()):
616
618 if not self._channels:
619
620 return
621
622 raise NotImplementedError("To be overridden in a child class")
623
626
627
630
631
632
633
634
635
636
637
638
639
640
642 arrayiterator = _ChannelDumper.set_iterator()
643 arr = arrayiterator.get_array()
644 mappings = [
645 ('rhn-channel-receiving-updates', 'receiving_updates'),
646 ]
647 for k, v in mappings:
648 arr.append(SimpleDumper(self._writer, k, self._row[v]))
649
650
651
652
653
654
655 return arrayiterator
656
678 tag_name = 'source-package'
679
681 return {
682 'id': 'rhn-source-package-%s' % self._row['id'],
683 'source-rpm': self._row['source_rpm'],
684 'last-modified': _dbtime2timestamp(self._row['last_modified']),
685 }
686
693
696 tag_name = 'erratum'
697
699 return {
700 'id': 'rhn-erratum-%s' % self._row['id'],
701 'advisory-name': self._row['advisory_name'],
702 'last-modified': _dbtime2timestamp(self._row['last_modified']),
703 }
704
711
714 tag_name = 'rhn-dist'
715
717 return {
718 'os': self._row['os'],
719 'release': self._row['release'],
720 'channel-arch': self._row['channel_arch'],
721 }
722
727
729 tag_name = 'rhn-channel-families'
730 iterator_query = 'select cf.* from rhnChannelFamily'
731
732 - def __init__(self, writer, data_iterator=None, ignore_subelements=0,
733 null_max_members=1):
734 BaseQueryDumper.__init__(self, writer, data_iterator=data_iterator)
735 self._ignore_subelements = ignore_subelements
736 self._null_max_members = null_max_members
737
739 cf = _ChannelFamilyDumper(self._writer, data,
740 ignore_subelements=self._ignore_subelements,
741 null_max_members=self._null_max_members)
742 cf.dump()
743
746 tag_name = 'rhn-channel-family'
747
748 - def __init__(self, writer, row, ignore_subelements=0, null_max_members=1):
749 BaseRowDumper.__init__(self, writer, row)
750 self._ignore_subelements = ignore_subelements
751 self._null_max_members = null_max_members
752
754 if self._ignore_subelements:
755 return None
756
757 arr = []
758
759 mappings = [
760 ('rhn-channel-family-name', 'name'),
761 ('rhn-channel-family-product-url', 'product_url'),
762 ]
763 for k, v in mappings:
764 arr.append(SimpleDumper(self._writer, k, self._row[v]))
765
766 return ArrayIterator(arr)
767
768 _query_get_channel_family_channels = rhnSQL.Statement("""
769 select c.label
770 from rhnChannelFamilyMembers cfm, rhnChannel c
771 where cfm.channel_family_id = :channel_family_id
772 and cfm.channel_id = c.id
773 """)
774
776
777 h = rhnSQL.prepare(self._query_get_channel_family_channels)
778 channel_family_id = self._row['id']
779 h.execute(channel_family_id=channel_family_id)
780 channels = [x['label'] for x in h.fetchall_dict() or []]
781
782 attributes = {
783 'id': "rhn-channel-family-%s" % channel_family_id,
784 'label': self._row['label'],
785 'channel-labels': ' '.join(channels),
786 }
787
788 if self._ignore_subelements:
789 return attributes
790 if self._row['label'] != 'rh-public':
791 if self._null_max_members:
792 attributes['max-members'] = 0
793 elif ('max_members' in self._row) and self._row['max_members']:
794 attributes['max-members'] = self._row['max_members']
795 return attributes
796
801 tag_name = 'rhn-package'
802
804 attrs = ["name", "version", "release", "package_arch",
805 "package_group", "rpm_version", "package_size", "payload_size",
806 "installed_size", "build_host", "source_rpm", "payload_format",
807 "compat"]
808 attr_dict = {
809 'id': "rhn-package-%s" % self._row['id'],
810 'org_id': self._row['org_id'] or "",
811 'epoch': self._row['epoch'] or "",
812 'cookie': self._row['cookie'] or "",
813 'build-time': _dbtime2timestamp(self._row['build_time']),
814 'last-modified': _dbtime2timestamp(self._row['last_modified']),
815 }
816 for attr in attrs:
817 attr_dict[attr.replace('_', '-')] = self._row[attr]
818 if self._row['checksum_type'] == 'md5':
819
820 attr_dict['md5sum'] = self._row['checksum']
821 return attr_dict
822
824 arr = []
825
826 mappings = [
827 ('rhn-package-summary', 'summary'),
828 ('rhn-package-description', 'description'),
829 ('rhn-package-vendor', 'vendor'),
830 ('rhn-package-copyright', 'copyright'),
831 ('rhn-package-header-sig', 'header_sig'),
832 ('rhn-package-header-start', 'header_start'),
833 ('rhn-package-header-end', 'header_end')
834 ]
835 for k, v in mappings:
836 arr.append(SimpleDumper(self._writer, k, self._row[v]))
837
838
839 checksum_arr = [{'type': self._row['checksum_type'],
840 'value': self._row['checksum']}]
841 arr.append(_ChecksumDumper(self._writer,
842 data_iterator=ArrayIterator(checksum_arr)))
843
844 h = rhnSQL.prepare("""
845 select
846 name, text,
847 TO_CHAR(time, 'YYYYMMDDHH24MISS') as time
848 from rhnPackageChangeLog
849 where package_id = :package_id
850 """)
851 h.execute(package_id=self._row['id'])
852 arr.append(_ChangelogDumper(self._writer, data_iterator=h))
853
854
855 mappings = [
856 ['rhnPackageRequires', 'rhn-package-requires', 'rhn-package-requires-entry'],
857 ['rhnPackageProvides', 'rhn-package-provides', 'rhn-package-provides-entry'],
858 ['rhnPackageConflicts', 'rhn-package-conflicts', 'rhn-package-conflicts-entry'],
859 ['rhnPackageObsoletes', 'rhn-package-obsoletes', 'rhn-package-obsoletes-entry'],
860 ['rhnPackageRecommends', 'rhn-package-recommends', 'rhn-package-recommends-entry'],
861 ['rhnPackageSuggests', 'rhn-package-suggests', 'rhn-package-suggests-entry'],
862 ['rhnPackageSupplements', 'rhn-package-supplements', 'rhn-package-supplements-entry'],
863 ['rhnPackageEnhances', 'rhn-package-enhances', 'rhn-package-enhances-entry'],
864 ['rhnPackageBreaks', 'rhn-package-breaks', 'rhn-package-breaks-entry'],
865 ['rhnPackagePredepends', 'rhn-package-predepends', 'rhn-package-predepends-entry'],
866 ]
867 for table_name, container_name, entry_name in mappings:
868 h = rhnSQL.prepare("""
869 select pc.name, pc.version, pd.sense
870 from %s pd, rhnPackageCapability pc
871 where pd.capability_id = pc.id
872 and pd.package_id = :package_id
873 """ % table_name)
874 h.execute(package_id=self._row['id'])
875 arr.append(_DependencyDumper(self._writer, data_iterator=h,
876 container_name=container_name,
877 entry_name=entry_name))
878
879
880 h = rhnSQL.prepare("""
881 select
882 pc.name, pf.device, pf.inode, pf.file_mode, pf.username,
883 pf.groupname, pf.rdev, pf.file_size,
884 TO_CHAR(mtime, 'YYYYMMDDHH24MISS') mtime,
885 c.checksum_type as "checksum-type",
886 c.checksum, pf.linkto, pf.flags, pf.verifyflags, pf.lang
887 from rhnPackageFile pf
888 left join rhnChecksumView c
889 on pf.checksum_id = c.id,
890 rhnPackageCapability pc
891 where pf.capability_id = pc.id
892 and pf.package_id = :package_id
893 """)
894 h.execute(package_id=self._row['id'])
895 arr.append(_PackageFilesDumper(self._writer, data_iterator=h))
896 return ArrayIterator(arr)
897
905
906
907
908
909 -class ShortPackageEntryDumper(BaseChecksumRowDumper):
910 tag_name = 'rhn-package-short'
911
912 - def set_attributes(self):
913 attr = {
914 'id': "rhn-package-%s" % self._row['id'],
915 'name': self._row['name'],
916 'version': self._row['version'],
917 'release': self._row['release'],
918 'epoch': self._row['epoch'] or "",
919 'package-arch': self._row['package_arch'],
920 'package-size': self._row['package_size'],
921 'last-modified': _dbtime2timestamp(self._row['last_modified']),
922 'org-id': self._row['org_id'] or "",
923 }
924 if self._row['checksum_type'] == 'md5':
925
926 attr['md5sum'] = self._row['checksum']
927 return attr
928
936
941 tag_name = 'rhn-source-packages'
942
944 attributes = {}
945 attrs = [
946 "id", "source_rpm", "package_group", "rpm_version",
947 "payload_size", "build_host", "sigchecksum_type", "sigchecksum", "vendor",
948 "cookie", "package_size", "checksum_type", "checksum"
949 ]
950 for attr in attrs:
951 attributes[attr.replace('_', '-')] = data[attr]
952 attributes['id'] = "rhn-source-package-%s" % data['id']
953 attributes['build-time'] = _dbtime2timestamp(data['build_time'])
954 attributes['last-modified'] = _dbtime2timestamp(data['last_modified'])
955 d = EmptyDumper(self._writer, 'rhn-source-package',
956 attributes=attributes)
957 d.dump()
958
971
972
973
974
975 -class _ChangelogEntryDumper(BaseRowDumper):
976 tag_name = 'rhn-package-changelog-entry'
977
978 - def set_iterator(self):
979 arr = []
980 mappings = [
981 ('rhn-package-changelog-entry-name', 'name'),
982 ('rhn-package-changelog-entry-text', 'text'),
983 ]
984 for k, v in mappings:
985 arr.append(SimpleDumper(self._writer, k, self._row[v]))
986
987 arr.append(SimpleDumper(self._writer, 'rhn-package-changelog-entry-time',
988 _dbtime2timestamp(self._row['time'])))
989
990 return ArrayIterator(arr)
991
996
1001
1002 - def __init__(self, writer, data_iterator, container_name, entry_name):
1006
1014
1019 tag_name = 'rhn-package-files'
1020
1034
1039 tag_name = 'rhn-erratum'
1040
1042 h = rhnSQL.prepare("""
1043 select c.label
1044 from rhnChannelErrata ec, rhnChannel c
1045 where ec.channel_id = c.id
1046 and ec.errata_id = :errata_id
1047 """)
1048 h.execute(errata_id=self._row['id'])
1049 channels = [x['label'] for x in h.fetchall_dict() or []]
1050
1051 h = rhnSQL.prepare("""
1052 select ep.package_id
1053 from rhnErrataPackage ep
1054 where ep.errata_id = :errata_id
1055 """)
1056 h.execute(errata_id=self._row['id'])
1057 packages = ["rhn-package-%s" % x['package_id'] for x in
1058 h.fetchall_dict() or []]
1059
1060 h = rhnSQL.prepare("""
1061 select c.name cve
1062 from rhnErrataCVE ec, rhnCVE c
1063 where ec.errata_id = :errata_id
1064 and ec.cve_id = c.id
1065 """)
1066 h.execute(errata_id=self._row['id'])
1067 cves = [x['cve'] for x in h.fetchall_dict() or []]
1068
1069 return {
1070 'id': 'rhn-erratum-%s' % self._row['id'],
1071 'org_id': self._row['org_id'] or "",
1072 'advisory': self._row['advisory'],
1073 'channels': ' '.join(channels),
1074 'packages': ' '.join(packages),
1075 'cve-names': ' '.join(cves),
1076 }
1077
1078 type_id_column = ""
1079
1081 arr = []
1082
1083 mappings = [
1084 ('rhn-erratum-advisory-name', 'advisory_name', 100),
1085 ('rhn-erratum-advisory-rel', 'advisory_rel', 32),
1086 ('rhn-erratum-advisory-type', 'advisory_type', 32),
1087 ('rhn-erratum-product', 'product', 64),
1088 ('rhn-erratum-description', 'description', 4000),
1089 ('rhn-erratum-synopsis', 'synopsis', 4000),
1090 ('rhn-erratum-topic', 'topic', 4000),
1091 ('rhn-erratum-solution', 'solution', 4000),
1092 ('rhn-erratum-refers-to', 'refers_to', 4000),
1093 ('rhn-erratum-notes', 'notes', 4000),
1094 ('rhn-erratum-errata-from', 'errata_from', 127),
1095 ('rhn-erratum-severity', 'severity_id', 127)
1096 ]
1097 for k, v, b in mappings:
1098 value = self._row[v] if self._row[v] is not None else ""
1099 arr.append(SimpleDumper(self._writer, k, value, b))
1100 arr.append(SimpleDumper(self._writer, 'rhn-erratum-issue-date',
1101 _dbtime2timestamp(self._row['issue_date'])))
1102 arr.append(SimpleDumper(self._writer, 'rhn-erratum-update-date',
1103 _dbtime2timestamp(self._row['update_date'])))
1104 arr.append(SimpleDumper(self._writer, 'rhn-erratum-last-modified',
1105 _dbtime2timestamp(self._row['last_modified'])))
1106
1107 h = rhnSQL.prepare("""
1108 select keyword
1109 from rhnErrataKeyword
1110 where errata_id = :errata_id
1111 """)
1112 h.execute(errata_id=self._row['id'])
1113 arr.append(_ErratumKeywordDumper(self._writer, data_iterator=h))
1114
1115 h = rhnSQL.prepare("""
1116 select bug_id, summary, href
1117 from rhnErrataBuglist
1118 where errata_id = :errata_id
1119 """)
1120 h.execute(errata_id=self._row['id'])
1121 arr.append(_ErratumBuglistDumper(self._writer, data_iterator=h))
1122 _query_errata_file_info = """
1123 select ef.id errata_file_id, c.checksum_type, c.checksum,
1124 ef.filename, eft.label as type,
1125 efp.package_id, efps.package_id as source_package_id
1126 from rhnErrataFile ef left outer join rhnErrataFilePackage efp on ef.id = efp.errata_file_id
1127 left outer join rhnErrataFilePackageSource efps on ef.id = efps.errata_file_id,
1128 rhnErrataFileType eft, rhnChecksumView c
1129 where ef.errata_id = :errata_id
1130 and ef.type = eft.id
1131 and ef.checksum_id = c.id
1132 %s
1133 """
1134 h = rhnSQL.prepare(_query_errata_file_info % self.type_id_column)
1135 h.execute(errata_id=self._row['id'])
1136 arr.append(_ErratumFilesDumper(self._writer, data_iterator=h))
1137
1138 return ArrayIterator(arr)
1139
1142 tag_name = 'rhn-errata'
1143 subelement_dumper_class = _ErratumDumper
1144
1146 if self._iterator:
1147 return self._iterator
1148 raise NotImplementedError("To be overridden in a child class")
1149
1152 tag_name = 'rhn-erratum-keywords'
1153
1157
1160 tag_name = 'rhn-erratum-bug'
1161
1163 arr = [
1164 SimpleDumper(self._writer, 'rhn-erratum-bug-id', self._row['bug_id']),
1165 SimpleDumper(self._writer, 'rhn-erratum-bug-summary',
1166 self._row['summary'] or ""),
1167 SimpleDumper(self._writer, 'rhn-erratum-bug-href', self._row['href']),
1168 ]
1169 return ArrayIterator(arr)
1170
1175
1176
1177 -class _ErratumFileEntryDumper(BaseChecksumRowDumper):
1178 tag_name = 'rhn-erratum-file'
1179
1180 - def set_attributes(self):
1181 attributes = {
1182 'filename': self._row['filename'][:4000],
1183 'type': self._row['type'],
1184 }
1185 if self._row['checksum_type'] == 'md5':
1186 attributes['md5sum'] = self._row['checksum']
1187
1188
1189 h = rhnSQL.prepare("""
1190 select c.label
1191 from rhnErrataFileChannel efc, rhnChannel c
1192 where efc.errata_file_id = :errata_file_id
1193 and efc.channel_id = c.id
1194 """)
1195 h.execute(errata_file_id=self._row['errata_file_id'])
1196 channels = ' '.join(
1197 [x['label'] for x in h.fetchall_dict() or []])
1198 if channels:
1199 attributes['channels'] = channels
1200
1201
1202 if self._row['type'] == 'RPM':
1203 package_id = self._row['package_id']
1204 if package_id is not None:
1205 attributes['package'] = 'rhn-package-%s' % package_id
1206 elif self._row['type'] == 'SRPM':
1207 package_id = self._row['source_package_id']
1208 if package_id is not None:
1209 attributes['source-package'] = 'rhn-package-source-%s' % package_id
1210 return attributes
1211
1216
1239
1242
1243 - def __init__(self, writer, data_iterator=None, rpm_arch_type_only=0):
1244 BaseArchesDumper.__init__(self, writer=writer,
1245 data_iterator=data_iterator)
1246 self.rpm_arch_type_only = rpm_arch_type_only
1247
1249 query_templ = """
1250 select aa.id, aa.label, aa.name,
1251 at.label arch_type_label, at.name arch_type_name
1252 from %s aa,
1253 rhnArchType at
1254 where aa.arch_type_id = at.id
1255 %s
1256 """
1257 if self.rpm_arch_type_only:
1258 h = rhnSQL.prepare(query_templ % (self.table_name, "and at.label = 'rpm'"))
1259 else:
1260 h = rhnSQL.prepare(query_templ % (self.table_name, ""))
1261 h.execute()
1262 return h
1263
1273
1279
1285
1291
1297
1331
1334 tag_name = 'rhn-server-package-arch-compatibility-map'
1335 _subelement_tag = 'rhn-server-package-arch-compat'
1336
1337 _query_rpm_arch_type_only = rhnSQL.Statement("""
1338 select sa.label "server-arch",
1339 pa.label "package-arch",
1340 spac.preference
1341 from rhnServerPackageArchCompat spac,
1342 rhnServerArch sa,
1343 rhnPackageArch pa,
1344 rhnArchType aas,
1345 rhnArchType aap
1346 where spac.server_arch_id = sa.id
1347 and spac.package_arch_id = pa.id
1348 and sa.arch_type_id = aas.id
1349 and aas.label = 'rpm'
1350 and pa.arch_type_id = aap.id
1351 and aap.label = 'rpm'
1352 """)
1353
1354 _query_arch_type_all = rhnSQL.Statement("""
1355 select sa.label "server-arch",
1356 pa.label "package-arch",
1357 spac.preference
1358 from rhnServerPackageArchCompat spac,
1359 rhnServerArch sa,
1360 rhnPackageArch pa
1361 where spac.server_arch_id = sa.id
1362 and spac.package_arch_id = pa.id
1363 """)
1364
1367 tag_name = 'rhn-server-channel-arch-compatibility-map'
1368 _subelement_tag = 'rhn-server-channel-arch-compat'
1369
1370 _query_rpm_arch_type_only = rhnSQL.Statement("""
1371 select sa.label "server-arch",
1372 ca.label "channel-arch"
1373 from rhnServerChannelArchCompat scac,
1374 rhnServerArch sa,
1375 rhnChannelArch ca,
1376 rhnArchType aas,
1377 rhnArchType aac
1378 where scac.server_arch_id = sa.id
1379 and scac.channel_arch_id = ca.id
1380 and sa.arch_type_id = aas.id
1381 and aas.label = 'rpm'
1382 and ca.arch_type_id = aac.id
1383 and aac.label = 'rpm'
1384 """)
1385
1386 _query_arch_type_all = rhnSQL.Statement("""
1387 select sa.label "server-arch",
1388 ca.label "channel-arch"
1389 from rhnServerChannelArchCompat scac,
1390 rhnServerArch sa,
1391 rhnChannelArch ca
1392 where scac.server_arch_id = sa.id
1393 and scac.channel_arch_id = ca.id
1394 """)
1395
1398 tag_name = 'rhn-channel-package-arch-compatibility-map'
1399 _subelement_tag = 'rhn-channel-package-arch-compat'
1400
1401 _query_rpm_arch_type_only = rhnSQL.Statement("""
1402 select ca.label "channel-arch",
1403 pa.label "package-arch"
1404 from rhnChannelPackageArchCompat cpac,
1405 rhnChannelArch ca,
1406 rhnPackageArch pa,
1407 rhnArchType aac,
1408 rhnArchType aap
1409 where cpac.channel_arch_id = ca.id
1410 and cpac.package_arch_id = pa.id
1411 and ca.arch_type_id = aac.id
1412 and aac.label = 'rpm'
1413 and pa.arch_type_id = aap.id
1414 and aap.label = 'rpm'
1415 """)
1416
1417 _query_arch_type_all = rhnSQL.Statement("""
1418 select ca.label "channel-arch",
1419 pa.label "package-arch"
1420 from rhnChannelPackageArchCompat cpac,
1421 rhnChannelArch ca,
1422 rhnPackageArch pa
1423 where cpac.channel_arch_id = ca.id
1424 and cpac.package_arch_id = pa.id
1425 """)
1426
1429 tag_name = 'rhn-server-group-server-arch-compatibility-map'
1430 _subelement_tag = 'rhn-server-group-server-arch-compat'
1431
1432 _query_rpm_arch_type_only = """
1433 select sgt.label "server-group-type",
1434 sa.label "server-arch"
1435 from rhnServerGroupType sgt,
1436 rhnServerArch sa,
1437 rhnArchType aas,
1438 rhnServerServerGroupArchCompat ssgac
1439 where ssgac.server_arch_id = sa.id
1440 and sa.arch_type_id = aas.id
1441 and aas.label = 'rpm'
1442 and ssgac.server_group_type = sgt.id
1443 %s
1444 """
1445
1446
1447 _query_arch_type_all = """
1448 select sgt.label "server-group-type",
1449 sa.label "server-arch"
1450 from rhnServerGroupType sgt,
1451 rhnServerArch sa,
1452 rhnServerServerGroupArchCompat ssgac
1453 where ssgac.server_arch_id = sa.id
1454 and ssgac.server_group_type = sgt.id
1455 %s
1456 """
1457
1460 tag_name = 'rhn-blacklist-obsoletes'
1461
1463 note = """\n<!-- This file is intentionally left empty.
1464 Older Satellites and Spacewalks require this file to exist in the dump. -->\n"""
1465 self._writer.stream.write(note)
1466 self._writer.empty_tag(self.tag_name)
1467
1470 tag_name = 'rhn-kickstartable-tree'
1471
1478
1480 kstree_id = self._row['id']
1481 h = rhnSQL.prepare("""
1482 select relative_filename,
1483 c.checksum_type,
1484 c.checksum,
1485 file_size,
1486 TO_CHAR(last_modified, 'YYYYMMDDHH24MISS') "last-modified"
1487 from rhnKSTreeFile, rhnChecksumView c
1488 where kstree_id = :kstree_id
1489 and checksum_id = c.id
1490 """)
1491 h.execute(kstree_id=kstree_id)
1492 return ArrayIterator([_KickstartFilesDumper(self._writer, h)])
1493
1496 tag_name = 'rhn-kickstartable-trees'
1497 subelement_dumper_class = _KickstartableTreeDumper
1498 iterator_query = """
1499 select kt.id,
1500 c.label channel,
1501 kt.base_path "base-path",
1502 kt.label,
1503 kt.boot_image "boot-image",
1504 ktt.name "kstree-type-name",
1505 ktt.label "kstree-type-label",
1506 kit.name "install-type-name",
1507 kit.label "install-type-label",
1508 TO_CHAR(kt.last_modified, 'YYYYMMDDHH24MISS') "last-modified"
1509 from rhnKickstartableTree kt,
1510 rhnKSTreeType ktt,
1511 rhnKSInstallType kit,
1512 rhnChannel c
1513 where kt.channel_id = c.id
1514 and ktt.id = kt.kstree_type
1515 and kit.id = kt.install_type
1516 and kt.org_id is NULL
1517 """
1518
1521
1522
1523 -class _KickstartFileEntryDumper(BaseChecksumRowDumper):
1524 tag_name = 'rhn-kickstart-file'
1525
1526 - def set_attributes(self):
1527 attr = {
1528 'relative-path': self._row['relative_filename'],
1529 'file-size': self._row['file_size'],
1530 'last-modified': _dbtime2timestamp(self._row['last-modified']),
1531 }
1532 if self._row['checksum_type'] == 'md5':
1533 attr['md5sum'] = self._row['checksum']
1534 return attr
1535
1540
1544
1547 tag_name = "rhn-product-names"
1548
1551