Rev 492: Add config objects for repositories. in file:///data/jelmer/bzr-svn/0.4/
Jelmer Vernooij
jelmer at samba.org
Thu Jul 12 09:28:25 BST 2007
At file:///data/jelmer/bzr-svn/0.4/
------------------------------------------------------------
revno: 492
revision-id: jelmer at samba.org-20070624193508-2f21180q93i5v5bx
parent: jelmer at samba.org-20070624181404-olgk0xm9gvhl97rf
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Sun 2007-06-24 21:35:08 +0200
message:
Add config objects for repositories.
added:
config.py config.py-20070624185721-0j8f1ly75uo4s1lk-1
tests/test_config.py test_config.py-20070624193244-itvnst60evjidr4z-1
modified:
TODO todo-20060729211917-2kpobww0zyvvo0j2-1
tests/__init__.py __init__.py-20060508151940-e9f4d914801a2535
=== added file 'config.py'
--- a/config.py 1970-01-01 00:00:00 +0000
+++ b/config.py 2007-06-24 19:35:08 +0000
@@ -0,0 +1,63 @@
+# Copyright (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""Stores per-repository settings."""
+
+from bzrlib import osutils, urlutils
+from bzrlib.config import IniBasedConfig, config_dir
+
+# Settings are stored by UUID.
+# Data stored includes default branching scheme and locations the repository
+# was seen at.
+
+def subversion_config_filename():
+ """Return per-user configuration ini file filename."""
+ return osutils.pathjoin(config_dir(), 'subversion.conf')
+
+class SvnRepositoryConfig(IniBasedConfig):
+ """Per-repository settings."""
+
+ def __init__(self, uuid):
+ name_generator = subversion_config_filename
+ super(SvnRepositoryConfig, self).__init__(name_generator)
+ self.uuid = uuid
+ if not self.uuid in self._get_parser():
+ self._get_parser()[self.uuid] = {}
+
+ def set_branching_scheme(self, scheme):
+ self.set_user_option('branching-scheme', scheme)
+
+ def get_branching_scheme(self):
+ try:
+ return self._get_parser()[self.uuid]['branching-scheme']
+ except KeyError:
+ return None
+
+ def get_locations(self):
+ try:
+ return set(self._get_parser()[self.uuid]['locations'].split(";"))
+ except KeyError:
+ return set()
+
+ def add_location(self, location):
+ locations = self.get_locations()
+ locations.add(location)
+ self.set_user_option('locations', ";".join(list(locations)))
+
+ def set_user_option(self, name, value):
+ self._get_parser()[self.uuid][name] = value
+ f = open(self._get_filename(), 'wb')
+ self._get_parser().write(f)
+ f.close()
=== added file 'tests/test_config.py'
--- a/tests/test_config.py 1970-01-01 00:00:00 +0000
+++ b/tests/test_config.py 2007-06-24 19:35:08 +0000
@@ -0,0 +1,49 @@
+# Copyright (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Config tests."""
+
+from config import SvnRepositoryConfig
+
+from unittest import TestCase
+
+class ReposConfigTests(TestCase):
+ def test_create(self):
+ SvnRepositoryConfig("blabla")
+
+ def test_get_empty_locations(self):
+ c = SvnRepositoryConfig("blabla6")
+ self.assertEquals(set(), c.get_locations())
+
+ def test_get_location_one(self):
+ c = SvnRepositoryConfig("blabla5")
+ c.add_location("foobar")
+ self.assertEquals(set(["foobar"]), c.get_locations())
+
+ def test_get_location_two(self):
+ c = SvnRepositoryConfig("blabla4")
+ c.add_location("foobar")
+ c.add_location("brainslug")
+ self.assertEquals(set(["foobar", "brainslug"]), c.get_locations())
+
+ def test_get_scheme_none(self):
+ c = SvnRepositoryConfig("blabla3")
+ self.assertEquals(None, c.get_branching_scheme())
+
+ def test_get_scheme_set(self):
+ c = SvnRepositoryConfig("blabla2")
+ c.set_branching_scheme("random")
+ self.assertEquals("random", c.get_branching_scheme())
=== modified file 'TODO'
--- a/TODO 2007-06-24 14:08:49 +0000
+++ b/TODO 2007-06-24 19:35:08 +0000
@@ -8,6 +8,7 @@
- more blackbox tests
- split fetch tests out of test_repos
- integrate bzr:merge into bzr:revision-info or rename to bzr:merge-vXXYY ?
+- cache per-repository branching scheme
Working trees:
- custom implementation of WorkingTree.revert() / WorkingTree.merge()
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2007-05-17 19:04:30 +0000
+++ b/tests/__init__.py 2007-06-24 19:35:08 +0000
@@ -258,6 +258,7 @@
'test_branchprops',
'test_checkout',
'test_commit',
+ 'test_config',
'test_convert',
'test_errors',
'test_fileids',
More information about the bazaar-commits
mailing list