1 # Copyright (C) 2012 W. Trevor King <wking@tremily.us>
3 # This file is part of update-copyright.
5 # update-copyright is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
10 # update-copyright is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # update-copyright. If not, see <http://www.gnu.org/licenses/>.
18 """Backends for version control systems."""
20 import os.path as _os_path
22 from . import utils as _utils
25 class VCSBackend (object):
28 def __init__(self, root='.', author_hacks=None, year_hacks=None,
31 if author_hacks is None:
33 self._author_hacks = author_hacks
34 if year_hacks is None:
36 self._year_hacks = year_hacks
39 self._aliases = aliases
41 def _years(self, filename=None):
42 raise NotImplementedError()
44 def original_year(self, filename=None):
45 years = self._years(filename=filename)
47 years.update(self._year_hacks.values())
49 filename = _os_path.relpath(filename, self._root)
50 splitpath = _utils.splitpath(filename)
51 if splitpath in self._year_hacks:
52 years.add(self._year_hacks[splitpath])
56 def _authors(self, filename=None):
57 raise NotImplementedError()
59 def authors(self, filename=None, with_emails=True):
60 authors = self._authors(filename=filename)
62 for path,_authors in self._author_hacks.items():
63 authors.update(_authors)
65 filename = _os_path.relpath(filename, self._root)
66 splitpath = _utils.splitpath(filename)
67 if splitpath in self._author_hacks:
68 authors.update(self._author_hacks[splitpath])
69 return _utils.replace_aliases(
70 authors, with_email=with_emails, aliases=self._aliases)
72 def is_versioned(self, filename=None):
73 raise NotImplementedError()