~launchpad-pqm/launchpad/devel

7675.1203.4 by Steve Kowalik
* BinaryPackagePaths -> BinaryPackagePath.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
__metaclass__ = type
5
6
__all__ = [
7
    'BinaryPackagePath',
8
    ]
9
10
from storm.locals import (
11
    Int,
7675.1203.11 by Steve Kowalik
Switch from text to bytea, allowing us to store non-UTF8 data.
12
    RawStr,
7675.1203.4 by Steve Kowalik
* BinaryPackagePaths -> BinaryPackagePath.
13
    Storm,
14
    )
15
from zope.interface import implements
16
17
from canonical.launchpad.interfaces.lpstorm import IMasterStore
18
from lp.soyuz.interfaces.binarypackagepath import IBinaryPackagePath
19
20
21
class BinaryPackagePath(Storm):
22
    """See `IBinaryPackagePath`."""
23
    implements(IBinaryPackagePath)
24
    __storm_table__ = 'BinaryPackagePath'
25
    id = Int(primary=True)
7675.1203.11 by Steve Kowalik
Switch from text to bytea, allowing us to store non-UTF8 data.
26
    path = RawStr(name='path', allow_none=False)
7675.1203.4 by Steve Kowalik
* BinaryPackagePaths -> BinaryPackagePath.
27
28
    def getOrCreate(self, path):
7675.1203.9 by Steve Kowalik
* BinaryPackagePathSource -> BinaryPackagePathSet.
29
        """See `IBinaryPackagePathSet`."""
7675.1203.4 by Steve Kowalik
* BinaryPackagePaths -> BinaryPackagePath.
30
        store = IMasterStore(BinaryPackagePath)
7675.1203.9 by Steve Kowalik
* BinaryPackagePathSource -> BinaryPackagePathSet.
31
        bpp = store.find(
32
            BinaryPackagePath, BinaryPackagePath.path == path).one()
33
        if bpp is None:
7675.1203.4 by Steve Kowalik
* BinaryPackagePaths -> BinaryPackagePath.
34
            bpp = BinaryPackagePath()
35
            bpp.path = path
7675.1203.9 by Steve Kowalik
* BinaryPackagePathSource -> BinaryPackagePathSet.
36
            store.add(bpp)
37
        return bpp