1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import os
20 import shutil
21 from spacewalk.common.usix import IntType, StringType, InstanceType
22 from UserDict import UserDict
23 try:
24
25 from UserList import UserList
26 except ImportError:
27
28 from collections import UserList
29
30 from spacewalk.common.checksum import getFileChecksum
31 from spacewalk.common.fileutils import createPath
32 from spacewalk.common.rhnConfig import CFG
33
34
35
36
39
40
41
42 -class Item(UserDict):
43
44 """
45 First level object, that stores information in a hash-like structure
46 """
47
50
52 self.update(hash)
53 return self
54
56 return "[<%s instance; attributes=%s]" % (str(self.__class__),
57 str(self.data))
58
59
60
61
62
90
91
92
93
99
100
101
102
110
111
112
114
120
124
128
129 add = append
130
134
139
144
149
154
156 return "[<%s instance; items=%s]" % (str(self.__class__),
157 str(self.data))
158
159
160
161
163 attributeTypes = {
164 'name': StringType,
165 'label': StringType,
166 'product_url': StringType,
167 'channels': [StringType],
168 'org_id': IntType,
169 }
170
172 attributeTypes = {
173 'os': StringType,
174 'release': StringType,
175 'channel_arch': StringType,
176 'channel': StringType,
177 'org_id': IntType,
178 }
179
181 attributeTypes = {
182 'product': StringType,
183 'version': StringType,
184 'release': StringType,
185 'channel_arch_id': IntType,
186 'channel_id': IntType
187 }
188
189
191 attributeTypes = {
192 'id': StringType,
193 'advisory_name': StringType,
194 'last_modified': DateType,
195 }
196
197
199 attributeTypes = {
200 'id': StringType,
201 'source_rpm': StringType,
202 'last_modified': DateType,
203 }
204
205
210
211
212 -class ContentSourceSsl(Information):
213 attributeTypes = {
214 'ssl_ca_cert_id': IntType,
215 'ssl_client_cert_id': IntType,
216 'ssl_client_key_id': IntType,
217 }
218
219
220 -class ContentSource(Information):
221 attributeTypes = {
222 'label': StringType,
223 'source_url': StringType,
224 'type_id': IntType,
225 'org_id': IntType,
226 'ssl-sets': [ContentSourceSsl],
227 'channels': [StringType],
228 }
229
230
232 attributeTypes = {
233 'label': StringType,
234 'org_id': IntType,
235 'channel_arch': StringType,
236 'parent_channel': StringType,
237 'name': StringType,
238 'summary': StringType,
239 'description': StringType,
240 'last_modified': DateType,
241 'comps_last_modified': DateType,
242 'modules_last_modified': DateType,
243 'gpg_key_url': StringType,
244 'product_name_id': IntType,
245 'channel_product_id': IntType,
246 'receiving_updates': StringType,
247 'checksum_type': StringType,
248 'channel_access': StringType,
249
250 'basedir': StringType,
251 'product_name': StringType,
252 'product_version': StringType,
253 'product_beta': StringType,
254
255 'families': [ChannelFamily],
256 'packages': [StringType],
257 'source_packages': [IncompleteSourcePackage],
258 'all-packages': [StringType],
259 'dists': [DistChannelMap],
260 'release': [ReleaseChannelMap],
261 'errata': [StringType],
262 'errata_timestamps': [ChannelErratum],
263 'kickstartable_trees': [StringType],
264 'trust_list': [ChannelTrust],
265 'export-type': StringType,
266 'export-end-date': StringType,
267 'export-start-date': StringType,
268 'content-sources': [ContentSource],
269 }
270
271
276
277
278 -class Org(Information):
284
285
287 attributeTypes = {
288 'name': StringType,
289 'device': IntType,
290 'inode': IntType,
291 'file_mode': IntType,
292 'username': StringType,
293 'groupname': StringType,
294 'rdev': IntType,
295 'file_size': IntType,
296 'mtime': DateType,
297 'linkto': StringType,
298 'flags': IntType,
299 'verifyflags': IntType,
300 'lang': StringType,
301 'checksum': StringType,
302 'checksum_type': StringType,
303 }
304
307
308
310 attributeTypes = {
311 'name': StringType,
312 'version': StringType,
313 'flags': IntType,
314 }
315
318
319
329
330
332 attributeTypes = {
333 'type': StringType,
334 'value': StringType,
335 }
336
339
340
342 attributeTypes = {
343 'package_id': StringType,
344 'name': StringType,
345 'epoch': StringType,
346 'version': StringType,
347 'release': StringType,
348 'arch': StringType,
349 'org_id': IntType,
350 'package_size': IntType,
351 'last_modified': DateType,
352 'md5sum': StringType,
353
354 'channels': [StringType],
355 'checksum_list': [Checksum],
356 }
357
364
366 dict = BaseInformation.toDict(self)
367 evr = list(self.evr)
368 if evr[0] is None:
369 evr[0] = ''
370
371 dict['name'] = self.name
372 dict['evr'] = evr
373 dict['arch'] = self.arch
374
375 org_id = self.org_id
376 if org_id is None:
377 org_id = ''
378 dict['org_id'] = org_id
379 return dict
380
382 return "%s-%s-%s.%s.rpm" % (self.name, self.evr[1], self.evr[2],
383 self.arch)
384
385
387
388 """
389 A package is a hash of attributes
390 """
391 attributeTypes = {
392 'description': StringType,
393 'summary': StringType,
394 'license': StringType,
395 'package_group': StringType,
396 'rpm_version': StringType,
397 'payload_size': IntType,
398 'installed_size': IntType,
399 'payload_format': StringType,
400 'build_host': StringType,
401 'build_time': DateType,
402 'cookie': StringType,
403 'vendor': StringType,
404 'source_rpm': StringType,
405 'package_size': IntType,
406 'last_modified': DateType,
407 'sigpgp': StringType,
408 'siggpg': StringType,
409 'sigsize': IntType,
410 'header_start': IntType,
411 'header_end': IntType,
412 'path': StringType,
413 'md5sum': StringType,
414 'sigmd5': StringType,
415 'multi_arch': StringType,
416
417 'files': [File],
418 'requires': [Dependency],
419 'provides': [Dependency],
420 'conflicts': [Dependency],
421 'obsoletes': [Dependency],
422 'recommends': [Dependency],
423 'supplements': [Dependency],
424 'enhances': [Dependency],
425 'suggests': [Dependency],
426 'breaks': [Dependency],
427 'predepends': [Dependency],
428 'changelog': [ChangeLog],
429 'channels': [StringType],
430 'checksum_list': [Checksum],
431 }
432
439
440
442 attributeTypes = {
443 'package_group': StringType,
444 'rpm_version': StringType,
445 'source_rpm': StringType,
446 'payload_size': IntType,
447 'payload_format': StringType,
448 'build_host': StringType,
449 'build_time': DateType,
450 'vendor': StringType,
451 'cookie': StringType,
452 'package_size': IntType,
453 'path': StringType,
454 'last_modified': DateType,
455
456 'md5sum': StringType,
457 'sigmd5': StringType,
458 'checksum_list': [Checksum],
459 }
460
468
470 return self.source_rpm
471
472
473 -class Bug(Information):
474 attributeTypes = {
475 'bug_id': StringType,
476 'summary': StringType,
477 'href': StringType,
478 }
479
480
482 attributeTypes = {
483 'filename': StringType,
484 'file_type': StringType,
485 'channel_list': [StringType],
486 'package_id': IntType,
487
488 'md5sum': StringType,
489 'checksum_list': [Checksum],
490 }
491
492
497
498
500 attributeTypes = {
501 'advisory': StringType,
502 'advisory_name': StringType,
503 'advisory_rel': IntType,
504 'advisory_type': StringType,
505 'product': StringType,
506 'description': StringType,
507 'synopsis': StringType,
508 'topic': StringType,
509 'solution': StringType,
510 'issue_date': DateType,
511 'update_date': DateType,
512 'last_modified': DateType,
513 'notes': StringType,
514 'org_id': IntType,
515 'refers_to': StringType,
516
517 'channels': [Channel],
518 'packages': [IncompletePackage],
519 'files': [ErrataFile],
520 'keywords': [Keyword],
521 'bugs': [Bug],
522 'cve': [StringType],
523 'errata_from': StringType,
524 'severity_id': IntType
525 }
526
527
529 attributeTypes = {
530 'label': StringType,
531 'name': StringType,
532 }
533
534
537
538
545
546
549
550
553
554
557
558
560 attributeTypes = {
561 'server-arch': StringType,
562 'package-arch': StringType,
563 'preference': IntType,
564 }
565
566
568 attributeTypes = {
569 'server-arch': StringType,
570 'channel-arch': StringType,
571 }
572
573
575 attributeTypes = {
576 'channel-arch': StringType,
577 'package-arch': StringType,
578 }
579
580
582 attributeTypes = {
583 'server-arch': StringType,
584 'server-group-type': StringType,
585 }
586
587
589 attributeTypes = {
590 'relative_path': StringType,
591 'last_modified': DateType,
592 'file_size': IntType,
593 'md5sum': StringType,
594 'checksum_list': [Checksum],
595 }
596
597
599 attributeTypes = {
600 'label': StringType,
601 'base_path': StringType,
602 'channel': StringType,
603 'boot_image': StringType,
604 'kstree_type_label': StringType,
605 'install_type_name': StringType,
606 'kstree_type_label': StringType,
607 'install_type_name': StringType,
608 'org_id': IntType,
609 'last_modified': DateType,
610 'files': [KickstartFile],
611 }
612
613
615 attributeTypes = {
616 'label': StringType,
617 'name': StringType,
618 }
619
620
621
622 -class Error(Information):
626
627
628
630
632 self.batch = batch
633 self.backend = backend
634
635 self.uploadForce = 1
636
637 self.forceVerify = 0
638
639 self.ignoreUploaded = 0
640
641 self.transactional = 0
642
644 self.uploadForce = value
645
647 self.forceVerify = value
648
650 self.ignoreUploaded = value
651
653 self.transactional = value
654
655
658
661
664
669
674
677
679
680 self.cleanup()
681 return self.batch
682
692
693
694
745
746
747
748
753
754
760
761
764
765
771
772
778
779
785
786
792
793
795
796 - def __init__(self, channel_family, *rest):
799
800
802
803 - def __init__(self, arch1, arch2, *rest):
807
808
813
814
819
820
821
822
823 -class Diff(UserList):
824
826 UserList.__init__(self)
827 self.level = 0
828
830 if self.level < level:
831 self.level = level
832
834
835 l = []
836 for item in self:
837 l.append(removeNone(item))
838 return {
839 'level': self.level,
840 'diff': l,
841 }
842
843
844
846 return [(x is not None and x) or '' for x in list]
847
848
849
850
851 -def move_package(filename, basedir, relpath, checksum_type, checksum, force=None):
852 """
853 Copies the information from the file descriptor to a file
854 Checks the file's checksum, raising FileConflictErrror if it's different
855 The force flag prevents the exception from being raised, and copies the
856 file even if the checksum has changed
857 """
858 packagePath = basedir + "/" + relpath
859
860 if os.path.isfile(packagePath):
861 if force:
862 os.unlink(packagePath)
863 else:
864
865 localsum = getFileChecksum(checksum_type, packagePath)
866 if checksum == localsum:
867
868 return
869 raise FileConflictError(os.path.basename(packagePath))
870
871 dir = os.path.dirname(packagePath)
872
873 if not os.path.exists(dir):
874 createPath(dir)
875
876
877
878
879 if filename.startswith(CFG.MOUNT_POINT):
880 shutil.move(filename, packagePath)
881 else:
882 shutil.copy(filename, packagePath)
883
884
885 os.chmod(packagePath, int('0644', 8))
886
887
888
889 NEVRA_TAGS = ['name', 'epoch', 'version', 'release', 'arch']
890
891
898
899
901
902 nevra = {}
903 for tag in NEVRA_TAGS:
904 nevra[tag] = header[tag]
905 if nevra['epoch'] == '':
906 nevra['epoch'] = None
907 return nevra
908