~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
= Package Relationship Model =

We call "package relationship" the DSC field which describes relation
between the package in question and others availble:

For sources DSC provides:

 * builddepends
 * builddependsindep

For binaries we have:

 * shlibdeps
 * depends
 * recommends
 * suggests
 * conflicts
 * replaces
 * provides

Those lines contain a list of comma-separated relationship where each
element follows this format:

    $NAME [($OPERATOR $VERSION)]

For example:

  >>> relationship_line = (
  ...    'gcc-3.4-base, libc6 (>= 2.3.2.ds1-4), gcc-3.4 ( = 3.4.1-4sarge1)')

Launchpad models package relationship elements via the
IPackageRelationShip instance. We use APT to parse the relationship
lines:

  >>> from apt_pkg import ParseDepends

ParseDepends returns a 'list of lists of tuples' as:

  [ [('$NAME', '$VERSION', '$OPERATOR')],
    [('$NAME', '$VERSION', '$OPERATOR')],
    ... ]

So we need perform a small treatment on its result in order to have
*sane* data:

  >>> parsed_relationships = [relationship for (relationship,) in
  ...                         ParseDepends(relationship_line)]

Let's see what we call 'sane':

  >>> parsed_relationships
  [('gcc-3.4-base', '', ''), ('libc6', '2.3.2.ds1-4', '>='), ('gcc-3.4', '3.4.1-4sarge1', '=')]

Now for each parsed element we can build an IPackageRelationship:

  >>> from lp.soyuz.browser.packagerelationship import PackageRelationship
  >>> from lp.soyuz.interfaces.packagerelationship import IPackageRelationship
  >>> from canonical.launchpad.webapp.testing import verifyObject

  >>> name, version, operator = parsed_relationships[1]
  >>> fake_url = 'http://host/path'

  >>> pkg_relationship = PackageRelationship(
  ...     name, operator, version, url=fake_url)

  >>> verifyObject(IPackageRelationship, pkg_relationship)
  True

  >>> pkg_relationship.name
  'libc6'
  >>> pkg_relationship.operator
  '>='
  >>> pkg_relationship.version
  '2.3.2.ds1-4'
  >>> pkg_relationship.url == fake_url
  True