~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/binarypackagepath.py

[r=stub,
        wgrant][bug=796997][incr] Add infrastructure to eventually support
        contents generation from the database.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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,
 
12
    RawStr,
 
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)
 
26
    path = RawStr(name='path', allow_none=False)
 
27
 
 
28
    def getOrCreate(self, path):
 
29
        """See `IBinaryPackagePathSet`."""
 
30
        store = IMasterStore(BinaryPackagePath)
 
31
        bpp = store.find(
 
32
            BinaryPackagePath, BinaryPackagePath.path == path).one()
 
33
        if bpp is None:
 
34
            bpp = BinaryPackagePath()
 
35
            bpp.path = path
 
36
            store.add(bpp)
 
37
        return bpp