-# Copyright (C) 2012 W. Trevor King
+# 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 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.
+# 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/>.
+# 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
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
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