1
# Copyright (C) 2008 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Properties to associate with files based on file glob patterns.
19
Patterns and the properties for each are defined in ini file format in
20
BZR_HOME/.bzrproperties. For example::
28
Patterns use the same conventions as .bzrignore, namely:
30
* *.xyz match any file ending in .xyz
31
* foo/ matches all files in foo directories
32
* to specify the top level, start a pattern with ./
34
Patterns are ordered and searching stops as soon as one matches.
35
As a consequence, more explicit patterns should be placed towards
44
import bzrlib.util.configobj
47
# The object providing per-user properties
48
_user_properties_provider = _PropertiesProvider(properties_filename())
51
class _PropertiesProvider(object):
52
"""An object that provides properties for a file."""
54
def __init__(self, filename):
55
"""Create a provider of properties.
57
:param filename: the ini file holding the patterns and the
58
properties that apply to each.
60
self._cfg = configobj.ConfigObj(filename)
61
patterns = self._cfg.keys()
62
self._globster = globbing._OrderedGlobster(patterns)
64
def get_properties(self, path):
65
"""Return the dictionary of properties for a path.
67
:param path: tree relative path
68
:return: the properties or {} if none
70
pat =_self._globster.match(path)
77
def properties_filename():
78
"""Return per-user properties file filename."""
79
return osutils.pathjoin(config.config_dir(), '.bzrproperties')