1 # Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
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
16 """Stores per-repository settings."""
18 from bzrlib import osutils
19 from bzrlib.config import IniBasedConfig, config_dir, ensure_config_dir_exists
23 from scheme import BranchingScheme
25 # Settings are stored by UUID.
26 # Data stored includes default branching scheme and locations the repository
29 def subversion_config_filename():
30 """Return per-user configuration ini file filename."""
31 return osutils.pathjoin(config_dir(), 'subversion.conf')
33 class SvnRepositoryConfig(IniBasedConfig):
34 """Per-repository settings."""
36 def __init__(self, uuid):
37 name_generator = subversion_config_filename
38 super(SvnRepositoryConfig, self).__init__(name_generator)
40 if not self.uuid in self._get_parser():
41 self._get_parser()[self.uuid] = {}
43 def set_branching_scheme(self, scheme):
44 """Change the branching scheme.
46 :param scheme: New branching scheme.
48 self.set_user_option('branching-scheme', str(scheme))
50 def get_branching_scheme(self):
51 """Get the branching scheme.
53 :return: BranchingScheme instance.
56 return BranchingScheme.find_scheme(self._get_parser()[self.uuid]['branching-scheme'])
60 def get_locations(self):
61 """Find the locations this repository has been seen at.
63 :return: Set with URLs.
66 return set(self._get_parser()[self.uuid]['locations'].split(";"))
70 def add_location(self, location):
71 """Add a location for this repository.
73 :param location: URL of location to add.
75 locations = self.get_locations()
76 locations.add(location.rstrip("/"))
77 self.set_user_option('locations', ";".join(list(locations)))
79 def set_user_option(self, name, value):
80 """Change a user option.
82 :param name: Name of the option.
83 :param value: Value of the option.
85 conf_dir = os.path.dirname(self._get_filename())
86 ensure_config_dir_exists(conf_dir)
87 self._get_parser()[self.uuid][name] = value
88 f = open(self._get_filename(), 'wb')
89 self._get_parser().write(f)