590f27b63d1d0a7aef2f67709101308ac7e05892
[update-copyright.git] / bin / update-copyright.py
1 #!/usr/bin/env python
2 #
3 # Copyright
4
5 """Update copyright information with information from the VCS repository.
6
7 Run from the project's repository root.
8
9 Replaces every line starting with ``^# Copyright`` and continuing with
10 ``^#`` with an auto-generated copyright blurb.  If you want to add
11 ``#``-commented material after a copyright blurb, please insert a blank
12 line between the blurb and your comment, so the next run of
13 ``update_copyright.py`` doesn't clobber your comment.
14
15 If no files are given, a list of files to update is generated
16 automatically.
17 """
18
19 import logging as _logging
20
21 from update_copyright import LOG as _LOG
22 from update_copyright.project import Project
23
24
25 if __name__ == '__main__':
26     import optparse
27     import sys
28
29     usage = "%%prog [options] [file ...]"
30
31     p = optparse.OptionParser(usage=usage, description=__doc__)
32     p.add_option('--config', dest='config', default='.update-copyright.conf',
33                  metavar='PATH', help='path to project config file (%default)')
34     p.add_option('--no-authors', dest='authors', default=True,
35                  action='store_false', help="Don't generate AUTHORS")
36     p.add_option('--no-files', dest='files', default=True,
37                  action='store_false', help="Don't update file copyrights")
38     p.add_option('--no-pyfile', dest='pyfile', default=True,
39                  action='store_false', help="Don't update the pyfile")
40     p.add_option('--dry-run', dest='dry_run', default=False,
41                  action='store_true', help="Don't make any changes")
42     p.add_option('-v', '--verbose', dest='verbose', default=0,
43                  action='count', help='Increment verbosity')
44     options,args = p.parse_args()
45
46     _LOG.setLevel(max(0, _logging.ERROR - 10*options.verbose))
47
48     project = Project()
49     project.load_config(open(options.config, 'r'))
50     if options.authors:
51         project.update_authors(dry_run=options.dry_run)
52     if options.files:
53         project.update_files(files=args, dry_run=options.dry_run)
54     if options.pyfile:
55         project.update_pyfile(dry_run=options.dry_run)