3 # Copyright (C) 2012-2013 W. Trevor King <wking@tremily.us>
5 # This file is part of update-copyright.
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
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
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/>.
20 """Update copyright information with information from the VCS repository.
22 Run from the project's repository root.
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.
30 You should configure this program via an ``.update-copyright.conf``
31 file in your project root.
34 import logging as _logging
35 import os.path as _os_path
37 from update_copyright import __version__
38 from update_copyright import LOG as _LOG
39 from update_copyright.project import Project
42 if __name__ == '__main__':
46 p = argparse.ArgumentParser(description=__doc__)
48 '--version', action='version',
49 version='%(prog)s {}'.format(__version__))
51 '--config', dest='config', default='.update-copyright.conf',
52 metavar='PATH', help='path to project config file')
54 '--no-authors', dest='authors', default=True, action='store_const',
55 const=False, help="Don't generate AUTHORS")
57 '--no-files', dest='files', default=True, action='store_const',
58 const=False, help="Don't update file copyrights")
60 '--no-pyfile', dest='pyfile', default=True, action='store_const',
61 const=False, help="Don't update the pyfile")
63 '--dry-run', dest='dry_run', default=False, action='store_const',
64 const=True, help="Don't make any changes")
66 '-v', '--verbose', dest='verbose', default=0, action='count',
67 help='Increment verbosity')
71 'Explicitly select files to update (otherwise update the whole '
76 _LOG.setLevel(max(_logging.DEBUG, _logging.ERROR - 10*args.verbose))
78 project = Project(root=_os_path.dirname(_os_path.abspath(args.config)))
79 project.load_config(open(args.config, 'r'))
80 if args.authors and project.with_authors:
81 project.update_authors(dry_run=args.dry_run)
82 if args.files and project.with_files:
83 project.update_files(files=args.file, dry_run=args.dry_run)
84 if args.pyfile and project._pyfile:
85 project.update_pyfile(dry_run=args.dry_run)