Ran update-copyright.
[update-copyright.git] / bin / update-copyright.py
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2012 W. Trevor King <wking@tremily.us>
4 #
5 # This file is part of update-copyright.
6 #
7 # update-copyright is free software: you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the Free
9 # Software Foundation, either version 3 of the License, or (at your option) any
10 # later version.
11 #
12 # update-copyright is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15 # more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # update-copyright.  If not, see <http://www.gnu.org/licenses/>.
19
20 """Update copyright information with information from the VCS repository.
21
22 Run from the project's repository root.
23
24 Replaces every line starting with ``^# Copyright`` and continuing with
25 ``^#`` with an auto-generated copyright blurb.  If you want to add
26 ``#``-commented material after a copyright blurb, please insert a blank
27 line between the blurb and your comment, so the next run of
28 ``update_copyright.py`` doesn't clobber your comment.
29
30 You should configure this program via an ``.update-copyright.conf``
31 file in your project root.
32 """
33
34 import logging as _logging
35 import os.path as _os_path
36
37 from update_copyright import LOG as _LOG
38 from update_copyright.project import Project
39
40
41 if __name__ == '__main__':
42     import optparse
43     import sys
44
45     usage = "%prog [options] [file ...]"
46
47     p = optparse.OptionParser(usage=usage, description=__doc__)
48     p.add_option('--config', dest='config', default='.update-copyright.conf',
49                  metavar='PATH', help='path to project config file (%default)')
50     p.add_option('--no-authors', dest='authors', default=True,
51                  action='store_false', help="Don't generate AUTHORS")
52     p.add_option('--no-files', dest='files', default=True,
53                  action='store_false', help="Don't update file copyrights")
54     p.add_option('--no-pyfile', dest='pyfile', default=True,
55                  action='store_false', help="Don't update the pyfile")
56     p.add_option('--dry-run', dest='dry_run', default=False,
57                  action='store_true', help="Don't make any changes")
58     p.add_option('-v', '--verbose', dest='verbose', default=0,
59                  action='count', help='Increment verbosity')
60     options,args = p.parse_args()
61
62     _LOG.setLevel(max(_logging.DEBUG, _logging.ERROR - 10*options.verbose))
63
64     project = Project(root=_os_path.dirname(_os_path.abspath(options.config)))
65     project.load_config(open(options.config, 'r'))
66     if options.authors:
67         project.update_authors(dry_run=options.dry_run)
68     if options.files:
69         project.update_files(files=args, dry_run=options.dry_run)
70     if options.pyfile:
71         project.update_pyfile(dry_run=options.dry_run)