Skip to content

Commit 1af5648

Browse files
committed
Adopt new handler design for RPMs
We now have these data file handlers: * RpmInstalledNdbDatabaseHandler * RpmInstalledSqliteDatabaseHandler * RpmInstalledBdbDatabaseHandler * RpmSpecfileHandler * RpmArchiveHandler And we assemble these in Packages correctly. Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 8d67fd8 commit 1af5648

14 files changed

+1939
-1220
lines changed

src/packagedcode/pyrpm.py

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@
3131
This is heavily modified version from the original.
3232
"""
3333

34-
3534
from io import BytesIO
3635
import struct
3736

38-
3937
"""""
4038
RPM constants
4139
From rpm.org lib/rpmtag.h
@@ -96,28 +94,115 @@
9694
)
9795

9896
# tags to collect
97+
# see https://rpm-software-management.github.io/rpm/manual/tags.html
9998

10099
RPMTAG_NAME = 1000
101100
RPMTAG_VERSION = 1001
102101
RPMTAG_RELEASE = 1002
103102
RPMTAG_EPOCH = 1003
104103
RPMTAG_SUMMARY = 1004
105104
RPMTAG_DESCRIPTION = 1005
105+
106+
# Distribution name
106107
RPMTAG_DISTRIBUTION = 1010
108+
107109
RPMTAG_VENDOR = 1011
108110
RPMTAG_COPYRIGHT = 1014
109111
RPMTAG_LICENSE = 1014
110112
RPMTAG_PACKAGER = 1015
111113
RPMTAG_GROUP = 1016
114+
112115
RPMTAG_PATCH = 1019
116+
117+
# Package URL, typically project upstream website.
113118
RPMTAG_URL = 1020
119+
# Package source code VCS location. rarely seen
120+
RPMTAG_VCS = 5034
121+
114122
RPMTAG_OS = 1021
115123
RPMTAG_ARCH = 1022
124+
125+
RPMTAG_CHANGELOG = 1017
126+
RPMTAG_CHANGELOGTIME = 1080
127+
RPMTAG_CHANGELOGNAME = 1081
128+
RPMTAG_CHANGELOGTEXT = 1082
129+
130+
# A list of source archive names as in strace-4.24.tar.xz
131+
RPMTAG_SOURCE = 1018
132+
# the full RPM archive file name for the source package of a binary RPM
116133
RPMTAG_SOURCERPM = 1044
117-
# a number ... not clear what it is
134+
# integer set to 1 for source RPMs
118135
RPMTAG_SOURCEPACKAGE = 1106
136+
137+
# URL to a package bug tracker
138+
RPMTAG_BUGURL = 5012
139+
140+
RPMTAG_FILESIZES = 1028
141+
RPMTAG_FILEDIGESTS = 1035
142+
143+
# ID of file digest algorithm.
144+
# MD5: 0 (default if missing)
145+
# SHA1: 2
146+
# SHA256: 8
147+
# SHA384: 9
148+
# SHA512: 10
149+
RPMTAG_FILEDIGESTALGO = 5011
150+
151+
RPMTAG_FILELINKTOS = 1036
152+
# File virtual attributes (doc, license, ghost, artifact etc)
153+
# doc:2, license:128, 0 is most common
154+
RPMTAG_FILEFLAGS = 1037
155+
156+
RPMTAG_DIRINDEXES = 1116
157+
RPMTAG_BASENAMES = 1117
158+
RPMTAG_DIRNAMES = 1118
159+
# is zero unless this is a special/char device file
160+
RPMTAG_FILERDEVS = 1033
161+
162+
# File “color” - 1 for 32bit ELF, 2 for 64bit ELF and 0 otherwise
163+
RPMTAG_FILECOLORS = 1140
164+
165+
# Original file paths for relocated packages only
166+
# same design as RPMTAG_DIRINDEXES et al.
167+
RPMTAG_ORIGDIRINDEXES = 1119
168+
RPMTAG_ORIGBASENAMES = 1120
169+
RPMTAG_ORIGDIRNAMES = 1121
170+
171+
RPMTAG_PROVIDES = 1047
172+
RPMTAG_PROVIDEFLAGS = 1112
173+
RPMTAG_PROVIDEVERSION = 1113
174+
175+
RPMTAG_REQUIRES = 1049
176+
RPMTAG_REQUIREFLAGS = 1048
177+
RPMTAG_REQUIREVERSION = 1050
178+
179+
RPMTAG_CONFLICTS = 1054
180+
RPMTAG_CONFLICTFLAGS = 1053
181+
RPMTAG_CONFLICTVERSION = 1055
182+
183+
RPMTAG_OBSOLETES = 1090
184+
RPMTAG_OBSOLETEFLAGS = 1114
185+
RPMTAG_OBSOLETEVERSION = 1115
186+
187+
# Distribution specific URL of the package. Seen only in Suse with obs:// links
119188
RPMTAG_DISTURL = 1123
120189

190+
# Distribution acronym: never seen in practice
191+
RPMTAG_DISTTAG = 1155
192+
193+
# Package platform (arch-os-vendor) as in x86_64-suse-linux or x86_64-redhat-linux-gnu
194+
RPMTAG_PLATFORM = 1132
195+
196+
# an index for each file to RPMTAG_CLASSDICT
197+
RPMTAG_FILECLASS = 1141
198+
# a "file" libmagic filetype
199+
RPMTAG_CLASSDICT = 1142
200+
201+
# Payload format (cpio)
202+
RPMTAG_PAYLOADFORMAT = 1124
203+
# Payload compressor name (as passed to rpmio Fopen()): for instance: gzip
204+
RPMTAG_PAYLOADCOMPRESSOR = 1125
205+
121206
RPMTAGS = {
122207
RPMTAG_NAME: 'name',
123208
RPMTAG_EPOCH: 'epoch',
@@ -136,6 +221,7 @@
136221
RPMTAG_ARCH: 'arch',
137222
RPMTAG_SOURCERPM: 'source_rpm',
138223
RPMTAG_DISTURL: 'dist_url',
224+
RPMTAG_FILEDIGESTALGO: 'files_digest_algo',
139225
}
140226

141227

@@ -161,6 +247,7 @@ class Entry(object):
161247
"""
162248
RPM Header Entry
163249
"""
250+
164251
def __init__(self, tag, type, value): # NOQA
165252
self.tag = tag
166253
self.type = type
@@ -294,7 +381,7 @@ class RPMError(BaseException):
294381
pass
295382

296383

297-
class RPM(object):
384+
class RPM:
298385

299386
def __init__(self, rpm):
300387
"""
@@ -421,7 +508,7 @@ def name(self):
421508
@property
422509
def epoch(self):
423510
"""
424-
Return a epoch or None for the epoch 0 and if no epoch is defined.
511+
Return an epoch or None for the epoch 0 and if no epoch is defined.
425512
"""
426513
epoch = self.get_entry_value(RPMTAG_EPOCH)
427514
if not epoch:
@@ -434,7 +521,7 @@ def epoch(self):
434521
return
435522
if epoch.lower() == 'none':
436523
return
437-
return epoch or None
524+
return epoch
438525

439526
@property
440527
def version(self):
@@ -501,6 +588,10 @@ def source_rpm(self):
501588
def package(self):
502589
return '-'.join([self.name, self.version])
503590

591+
@property
592+
def files_digest_algo(self):
593+
return self.get_entry_value(RPMTAG_FILEDIGESTALGO)
594+
504595
@property
505596
def filename(self):
506597
name = '-'.join([self.package, self.release])
@@ -542,4 +633,5 @@ def to_dict(self):
542633
dist_url=self.dist_url,
543634
source_rpm=self.source_rpm,
544635
is_binary=self.is_binary,
545-
)
636+
files_digest_algo=self.files_digest_algo,
637+
)

0 commit comments

Comments
 (0)