Ran update-copyright.
[update-copyright.git] / update_copyright / vcs / bazaar.py
index e54eed5ae04c4330cf9c95872d5b66980bed2d0c..27aac6a12aa820b51f5c1a65a3631a1a5962f486 100644 (file)
@@ -1,6 +1,22 @@
-# Copyright
+# Copyright (C) 2012 W. Trevor King <wking@tremily.us>
+#
+# This file is part of update-copyright.
+#
+# update-copyright 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 3 of the License, or (at your option) any
+# later version.
+#
+# update-copyright 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
+# update-copyright.  If not, see <http://www.gnu.org/licenses/>.
 
 import StringIO as _StringIO
+import os as _os
 
 import bzrlib as _bzrlib
 import bzrlib.builtins as _bzrlib_builtins
@@ -40,13 +56,21 @@ class BazaarBackend (_VCSBackend):
         super(BazaarBackend, self).__init__(**kwargs)
         self._version = _bzrlib.__version__
 
+    def _bzr_cmd(self, cmd, **kwargs):
+        cwd = _os.getcwd()
+        _os.chdir(self._root)
+        try:
+            cmd.run(**kwargs)
+        finally:
+            _os.chdir(cwd)
+
     def _years(self, filename=None):
         cmd = _bzrlib_builtins.cmd_log()
         cmd.outf = _StringIO.StringIO()
         kwargs = {'log_format':_YearLogFormatter, 'levels':0}
         if filename is not None:
             kwargs['file_list'] = [filename]
-        cmd.run(**kwargs)
+        self._bzr_cmd(cmd=cmd, **kwargs)
         years = set(int(year) for year in cmd.outf.getvalue().splitlines())
         return years
 
@@ -56,12 +80,12 @@ class BazaarBackend (_VCSBackend):
         kwargs = {'log_format':_AuthorLogFormatter, 'levels':0}
         if filename is not None:
             kwargs['file_list'] = [filename]
-        cmd.run(**kwargs)
+        self._bzr_cmd(cmd=cmd, **kwargs)
         authors = set(cmd.outf.getvalue().splitlines())
         return authors
 
     def is_versioned(self, filename):
         cmd = _bzrlib_builtins.cmd_log()
         cmd.outf = StringIO.StringIO()
-        cmd.run(file_list=[filename])
+        self._bzr_cmd(cmd=cmd, file_list=[filename])
         return True