~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/rules.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-09 20:23:07 UTC
  • mfrom: (4265.1.4 bbc-merge)
  • Revision ID: pqm@pqm.ubuntu.com-20090409202307-n0depb16qepoe21o
(jam) Change _fetch_uses_deltas = False for CHK repos until we can
        write a better fix.

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
21
21
 
22
22
from bzrlib import (
23
23
    config,
24
 
    cmdline,
 
24
    commands,
25
25
    errors,
26
26
    globbing,
27
27
    osutils,
36
36
FILE_PREFS_PREFIX = 'name '
37
37
FILE_PREFS_PREFIX_LEN = len(FILE_PREFS_PREFIX)
38
38
 
39
 
# The object providing default rules
40
 
_per_user_searcher = None
41
 
 
42
39
 
43
40
class _RulesSearcher(object):
44
41
    """An object that provides rule-based preferences."""
64
61
        """
65
62
        raise NotImplementedError(self.get_selected_items)
66
63
 
67
 
    def get_single_value(self, path, preference_name):
68
 
        """Get a single preference for a single file.
69
 
        
70
 
        :returns: The string preference value, or None.
71
 
        """
72
 
        for key, value in self.get_selected_items(path, [preference_name]):
73
 
            return value
74
 
        return None
75
 
 
76
64
 
77
65
class _IniBasedRulesSearcher(_RulesSearcher):
78
66
 
83
71
 
84
72
        :param inifile: the name of the file or a sequence of lines.
85
73
        """
86
 
        self._cfg = configobj.ConfigObj(inifile, encoding='utf-8')
 
74
        options = {'encoding': 'utf-8'}
 
75
        self._cfg = configobj.ConfigObj(inifile, options=options)
87
76
        sections = self._cfg.keys()
88
77
        patterns = []
89
78
        self.pattern_to_section = {}
90
79
        for s in sections:
91
80
            if s.startswith(FILE_PREFS_PREFIX):
92
 
                file_patterns = cmdline.split(s[FILE_PREFS_PREFIX_LEN:])
 
81
                file_patterns = commands.shlex_split_unicode(
 
82
                    s[FILE_PREFS_PREFIX_LEN:])
93
83
                patterns.extend(file_patterns)
94
84
                for fp in file_patterns:
95
85
                    self.pattern_to_section[fp] = s
156
146
    return osutils.pathjoin(config.config_dir(), 'rules')
157
147
 
158
148
 
159
 
def reset_rules():
160
 
    global _per_user_searcher
161
 
    _per_user_searcher = _IniBasedRulesSearcher(rules_filename())
162
 
 
163
 
reset_rules()
 
149
# The object providing default rules
 
150
_per_user_searcher = _IniBasedRulesSearcher(rules_filename())