/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/rules.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Rule-based definition of preferences for selected files in selected branches.
 
17
"""Rule-based definition of preferences for selected files in selected branches
18
18
 
19
19
See ``bzr help rules`` for details.
20
20
"""
21
21
 
22
 
from __future__ import absolute_import
 
22
import configobj
23
23
 
24
 
from bzrlib import (
25
 
    config,
 
24
from . import (
 
25
    bedding,
26
26
    cmdline,
27
27
    errors,
28
28
    globbing,
29
29
    osutils,
30
30
    )
31
 
from bzrlib.util.configobj import configobj
32
31
 
33
32
 
34
33
# Name of the file holding rules in a tree
42
41
_per_user_searcher = None
43
42
 
44
43
 
 
44
class UnknownRules(errors.BzrError):
 
45
 
 
46
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
47
 
 
48
    def __init__(self, unknowns):
 
49
        errors.BzrError.__init__(self, unknowns_str=", ".join(unknowns))
 
50
 
 
51
 
45
52
class _RulesSearcher(object):
46
53
    """An object that provides rule-based preferences."""
47
54
 
68
75
 
69
76
    def get_single_value(self, path, preference_name):
70
77
        """Get a single preference for a single file.
71
 
        
 
78
 
72
79
        :returns: The string preference value, or None.
73
80
        """
74
81
        for key, value in self.get_selected_items(path, [preference_name]):
97
104
                    self.pattern_to_section[fp] = s
98
105
        if len(patterns) < len(sections):
99
106
            unknowns = [s for s in sections
100
 
                if not s.startswith(FILE_PREFS_PREFIX)]
101
 
            raise errors.UnknownRules(unknowns)
 
107
                        if not s.startswith(FILE_PREFS_PREFIX)]
 
108
            raise UnknownRules(unknowns)
102
109
        elif patterns:
103
110
            self._globster = globbing._OrderedGlobster(patterns)
104
111
        else:
153
160
        return ()
154
161
 
155
162
 
156
 
def rules_filename():
157
 
    """Return the default rules filename."""
158
 
    return osutils.pathjoin(config.config_dir(), 'rules')
 
163
def rules_path():
 
164
    """Return the default rules file path."""
 
165
    return osutils.pathjoin(bedding.config_dir(), 'rules')
159
166
 
160
167
 
161
168
def reset_rules():
162
169
    global _per_user_searcher
163
 
    _per_user_searcher = _IniBasedRulesSearcher(rules_filename())
 
170
    _per_user_searcher = _IniBasedRulesSearcher(rules_path())
 
171
 
164
172
 
165
173
reset_rules()