README: Replace '...?' with 'author'
[update-copyright.git] / update_copyright / vcs / mercurial.py
1 # Copyright (C) 2012-2014 W. Trevor King <wking@tremily.us>
2 #
3 # This file is part of update-copyright.
4 #
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
8 # later version.
9 #
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
13 # more details.
14 #
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/>.
17
18 from . import VCSBackend as _VCSBackend
19 from . import utils as _utils
20
21
22 class MercurialBackend (_VCSBackend):
23     name = 'Mercurial'
24
25     def __init__(self, **kwargs):
26         super(MercurialBackend, self).__init__(**kwargs)
27         self._version = _version
28
29     def _hg_cmd(*args):
30         status,stdout,stderr = _utils.invoke(
31             ['hg'] + list(args), cwd=self._root, unicode_output=True)
32         return stdout.rstrip('\n')
33
34     def _years(self, filename=None):
35         args = [
36             '--template', '{date|shortdate}\n',
37             # shortdate filter: YEAR-MONTH-DAY
38             ]
39         if filename is not None:
40             args.extend(['--follow', filename])
41         output,error = mercurial_cmd('log', *args)
42         years = set(int(line.split('-', 1)[0]) for line in output.splitlines())
43         return years
44
45     def _authors(self, filename=None):
46         args = ['--template', '{author}\n']
47         if filename is not None:
48             args.extend(['--follow', filename])
49         output,error = mercurial_cmd('log', *args)
50         authors = set(output.splitlines())
51         return authors
52
53     def is_versioned(self, filename):
54         output,error = mercurial_cmd('log', '--follow', filename)
55         if len(error) > 0:
56             return False
57         return True