/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
See ``bzr help rules`` for details.
20
20
"""
21
21
 
22
 
from __future__ import absolute_import
23
 
 
24
 
import configobj
25
 
 
26
 
from . import (
 
22
from bzrlib import (
27
23
    config,
28
24
    cmdline,
29
25
    errors,
30
26
    globbing,
31
27
    osutils,
32
28
    )
 
29
from bzrlib.util.configobj import configobj
33
30
 
34
31
 
35
32
# Name of the file holding rules in a tree
43
40
_per_user_searcher = None
44
41
 
45
42
 
46
 
class UnknownRules(errors.BzrError):
47
 
 
48
 
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
49
 
 
50
 
    def __init__(self, unknowns):
51
 
        errors.BzrError.__init__(self, unknowns_str=", ".join(unknowns))
52
 
 
53
 
 
54
43
class _RulesSearcher(object):
55
44
    """An object that provides rule-based preferences."""
56
45
 
75
64
        """
76
65
        raise NotImplementedError(self.get_selected_items)
77
66
 
78
 
    def get_single_value(self, path, preference_name):
79
 
        """Get a single preference for a single file.
80
 
 
81
 
        :returns: The string preference value, or None.
82
 
        """
83
 
        for key, value in self.get_selected_items(path, [preference_name]):
84
 
            return value
85
 
        return None
86
 
 
87
67
 
88
68
class _IniBasedRulesSearcher(_RulesSearcher):
89
69
 
94
74
 
95
75
        :param inifile: the name of the file or a sequence of lines.
96
76
        """
97
 
        self._cfg = configobj.ConfigObj(inifile, encoding='utf-8')
 
77
        options = {'encoding': 'utf-8'}
 
78
        self._cfg = configobj.ConfigObj(inifile, options=options)
98
79
        sections = self._cfg.keys()
99
80
        patterns = []
100
81
        self.pattern_to_section = {}
107
88
        if len(patterns) < len(sections):
108
89
            unknowns = [s for s in sections
109
90
                if not s.startswith(FILE_PREFS_PREFIX)]
110
 
            raise UnknownRules(unknowns)
 
91
            raise errors.UnknownRules(unknowns)
111
92
        elif patterns:
112
93
            self._globster = globbing._OrderedGlobster(patterns)
113
94
        else: