/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: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

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
 
23
 
22
24
import configobj
23
25
 
24
26
from . import (
25
 
    bedding,
 
27
    config,
26
28
    cmdline,
27
29
    errors,
28
30
    globbing,
41
43
_per_user_searcher = None
42
44
 
43
45
 
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
 
 
52
46
class _RulesSearcher(object):
53
47
    """An object that provides rule-based preferences."""
54
48
 
75
69
 
76
70
    def get_single_value(self, path, preference_name):
77
71
        """Get a single preference for a single file.
78
 
 
 
72
        
79
73
        :returns: The string preference value, or None.
80
74
        """
81
75
        for key, value in self.get_selected_items(path, [preference_name]):
104
98
                    self.pattern_to_section[fp] = s
105
99
        if len(patterns) < len(sections):
106
100
            unknowns = [s for s in sections
107
 
                        if not s.startswith(FILE_PREFS_PREFIX)]
108
 
            raise UnknownRules(unknowns)
 
101
                if not s.startswith(FILE_PREFS_PREFIX)]
 
102
            raise errors.UnknownRules(unknowns)
109
103
        elif patterns:
110
104
            self._globster = globbing._OrderedGlobster(patterns)
111
105
        else:
160
154
        return ()
161
155
 
162
156
 
163
 
def rules_path():
164
 
    """Return the default rules file path."""
165
 
    return osutils.pathjoin(bedding.config_dir(), 'rules')
 
157
def rules_filename():
 
158
    """Return the default rules filename."""
 
159
    return osutils.pathjoin(config.config_dir(), 'rules')
166
160
 
167
161
 
168
162
def reset_rules():
169
163
    global _per_user_searcher
170
 
    _per_user_searcher = _IniBasedRulesSearcher(rules_path())
171
 
 
 
164
    _per_user_searcher = _IniBasedRulesSearcher(rules_filename())
172
165
 
173
166
reset_rules()