1 # Copyright (C) 2012 W. Trevor King
3 # This file is part of update-copyright.
5 # update-copyright is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
10 # update-copyright is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with update-copyright. If not, see
17 # <http://www.gnu.org/licenses/>.
19 """Backends for version control systems."""
21 import os.path as _os_path
23 from . import utils as _utils
26 class VCSBackend (object):
29 def __init__(self, root='.', author_hacks=None, year_hacks=None,
32 if author_hacks is None:
34 self._author_hacks = author_hacks
35 if year_hacks is None:
37 self._year_hacks = year_hacks
40 self._aliases = aliases
42 def _years(self, filename=None):
43 raise NotImplementedError()
45 def original_year(self, filename=None):
46 years = self._years(filename=filename)
48 years.update(self._year_hacks.values())
50 filename = _os_path.relpath(filename, self._root)
51 if _utils.splitpath(filename) in self._year_hacks:
52 years.add(self._year_hacks[_utils.splitpath(filename)])
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)
64 elif _utils.splitpath(filename) in self._author_hacks:
65 authors.update(self._author_hacks[_utils.splitpath(filename)])
66 return _utils.replace_aliases(
67 authors, with_email=with_emails, aliases=self._aliases)
69 def is_versioned(self, filename=None):
70 raise NotImplementedError()