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