93
95
build_skeleton.inited = False
98
def relation_to_string(relation_tuple):
99
"""Convert an apt relation to a string representation.
101
@param relation_tuple: A tuple, (name, version, relation). version
102
and relation can be the empty string, if the relation is on a
105
Returns something like "name > 1.0"
107
name, version, relation_type = relation_tuple
108
relation_string = name
110
relation_string += " %s %s" % (relation_type, version)
111
return relation_string
114
def parse_record_field(record, record_field, relation_type,
115
or_relation_type=None):
116
"""Parse an apt C{Record} field and return skeleton relations
118
@param record: An C{apt.package.Record} instance with package information.
119
@param record_field: The name of the record field to parse.
120
@param relation_type: The deb relation that can be passed to
121
C{skeleton.add_relation()}
122
@param or_relation_type: The deb relation that should be used if
123
there is more than one value in a relation.
126
values = apt_pkg.parse_depends(record.get(record_field, ""))
128
value_strings = [relation_to_string(relation) for relation in value]
129
value_relation_type = relation_type
130
if len(value_strings) > 1:
131
value_relation_type = or_relation_type
132
relation_string = " | ".join(value_strings)
133
relations.add((value_relation_type, relation_string))
137
def build_skeleton_apt(version, with_info=False, with_unicode=False):
138
"""Build a package skeleton from an apt package.
140
@param version: An instance of C{apt.package.Version}
141
@param with_info: Whether to extract extra information about the
142
package, like description, summary, size.
143
@param with_unicode: Whether the C{name} and C{version} of the
144
skeleton should be unicode strings.
146
name, version_string = version.package.name, version.version
148
name, version_string = unicode(name), unicode(version_string)
149
skeleton = PackageSkeleton(DEB_PACKAGE, name, version_string)
151
relations.update(parse_record_field(
152
version.record, "Provides", DEB_PROVIDES))
155
"%s = %s" % (version.package.name, version.version)))
156
relations.update(parse_record_field(
157
version.record, "Pre-Depends", DEB_REQUIRES, DEB_OR_REQUIRES))
158
relations.update(parse_record_field(
159
version.record, "Depends", DEB_REQUIRES, DEB_OR_REQUIRES))
162
DEB_UPGRADES, "%s < %s" % (version.package.name, version.version)))
164
relations.update(parse_record_field(
165
version.record, "Conflicts", DEB_CONFLICTS))
166
relations.update(parse_record_field(
167
version.record, "Breaks", DEB_CONFLICTS))
168
skeleton.relations = sorted(relations)
171
skeleton.section = version.section
172
skeleton.summary = version.summary
173
skeleton.description = version.description
174
skeleton.size = version.size
175
if version.installed_size > 0:
176
skeleton.installed_size = version.installed_size
178
skeleton.section = skeleton.section.decode("utf-8")
179
skeleton.summary = skeleton.summary.decode("utf-8")
180
skeleton.description = skeleton.description.decode("utf-8")