/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 bzrlib/rules.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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