~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/features/rulesource.py

  • Committer: Curtis Hovey
  • Date: 2011-08-12 14:39:51 UTC
  • mto: This revision was merged to the branch mainline in revision 13685.
  • Revision ID: curtis.hovey@canonical.com-20110812143951-74vfvrt37gtt4fz2
Sorted imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
__metaclass__ = type
14
14
 
 
15
import re
15
16
from collections import (
16
17
    defaultdict,
17
18
    namedtuple,
18
19
    )
19
 
import re
20
20
 
21
21
from storm.locals import Desc
22
22
 
 
23
from canonical.launchpad.webapp import adapter
23
24
from lp.services.features.model import (
24
25
    FeatureFlag,
25
26
    getFeatureStore,
26
27
    )
27
 
from lp.services.webapp import adapter
 
28
 
28
29
 
29
30
# A convenient mapping for a feature flag rule in the database.
30
31
Rule = namedtuple("Rule", "flag scope priority value")
86
87
    def parseRules(self, text_form):
87
88
        """Return a list of tuples for the parsed form of the text input.
88
89
 
89
 
        For each non-blank line gives back a tuple of
90
 
        (flag, scope, priority, value).
 
90
        For each non-blank line gives back a tuple of (flag, scope, priority, value).
91
91
 
92
92
        Returns a list rather than a generator so that you see any syntax
93
93
        errors immediately.
139
139
 
140
140
        :param new_rules: List of (name, scope, priority, value) tuples.
141
141
        """
142
 
        # XXX: would be slightly better to only update rules as necessary so
143
 
        # we keep timestamps, and to avoid the direct sql etc -- mbp 20100924
 
142
        # XXX: would be slightly better to only update rules as necessary so we keep
 
143
        # timestamps, and to avoid the direct sql etc -- mbp 20100924
144
144
        store = getFeatureStore()
145
145
        store.execute('DELETE FROM FeatureFlag')
146
146
        for (flag, scope, priority, value) in new_rules:
149
149
                flag=unicode(flag),
150
150
                value=value,
151
151
                priority=priority))
152
 
        store.flush()
153
152
 
154
153
 
155
154
class NullFeatureRuleSource(FeatureRuleSource):