diff --git a/maint-helper.py b/maint-helper.py index 10fa5782..45be31f5 100755 --- a/maint-helper.py +++ b/maint-helper.py @@ -19,6 +19,14 @@ import os import sys import re +import datetime + +source_exts = [ '.py', '.c', '.h', '.cpp' ] + +def is_source(path): + for ext in source_exts: + if path.endswith(ext): + return True def get_name_and_version(): f = open('configure.ac', 'r') @@ -35,8 +43,9 @@ def get_name_and_version(): def cmd_help(): print 'Usage: \n\ -maint-helper.py build-snapshot - build a source snapshot \n\ -maint-helper.py check-licenses - check licenses in the source' +maint-helper.py build-snapshot - build a source snapshot \n\ +maint-helper.py fix-copyright [path] - fix the copyright year \n\ +maint-helper.py check-licenses - check licenses in the source' def cmd_build_snapshot(): [ name, version ] = get_name_and_version() @@ -53,7 +62,6 @@ def cmd_build_snapshot(): def check_licenses(path, license, missing): matchers = { 'LGPL' : 'GNU Lesser General Public', 'GPL' : 'GNU General Public License' } - source_exts = [ '.py', '.c', '.h', '.cpp' ] license_file = os.path.join(path, '.license') if os.path.isfile(license_file): @@ -67,10 +75,7 @@ def check_licenses(path, license, missing): if os.path.isdir(full_path): check_licenses(full_path, license, missing) else: - check_source = False - for ext in source_exts: - if item.endswith(ext): - check_source = True + check_source = is_source(item) # Special cases. if item.find('marshal') > 0 or \ @@ -105,9 +110,52 @@ def cmd_check_licenses(): print path print '\n' +COPYRIGHT = 'Copyright (C) ' + +def fix_copyright(path): + for item in os.listdir(path): + full_path = os.path.join(path, item) + + if os.path.isdir(full_path): + fix_copyright(full_path) + elif is_source(item): + f = open(full_path, 'r') + source = f.read() + f.close() + + year_start = -1 + year_end = -1 + + i1 = source.find(COPYRIGHT) + if i1 != -1: + i1 += len(COPYRIGHT) + i2 = i1 + source[i1:].find(' ') + if i1 > 0: + try: + year_start = int(source[i1:i1 + 4]) + year_end = int(source[i1 + 6: i1 + 10]) + except ValueError: + pass + + if year_start > 0 and year_end < 0: + year_end = year_start + + year = datetime.date.today().year + if year_end < year: + result = '%s%d-%d%s' % (source[:i1], year_start, + year, source[i2:]) + f = open(full_path, 'w') + f.write(result) + f.close() + +def cmd_fix_copyright(path): + fix_copyright(path) + if len(sys.argv) < 2: cmd_help() elif sys.argv[1] == 'build-snapshot': cmd_build_snapshot() elif sys.argv[1] == 'check-licenses': cmd_check_licenses() +elif sys.argv[1] == 'fix-copyright' and len(sys.argv) > 2: + cmd_fix_copyright(sys.argv[2]) diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index ec6c50a1..56b0a1c5 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -3,7 +3,7 @@ This is currently the only reference for what an activity must do to participate in the Sugar desktop. """ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/activityfactory.py b/sugar/activity/activityfactory.py index 2cdf9a10..4bfccf0e 100644 --- a/sugar/activity/activityfactory.py +++ b/sugar/activity/activityfactory.py @@ -1,5 +1,5 @@ """Shell side object which manages request to start activity""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/activityfactoryservice.py b/sugar/activity/activityfactoryservice.py index ea0ff8c8..bc7c4e7b 100644 --- a/sugar/activity/activityfactoryservice.py +++ b/sugar/activity/activityfactoryservice.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/activityhandle.py b/sugar/activity/activityhandle.py index e683ac1b..26d0d47c 100644 --- a/sugar/activity/activityhandle.py +++ b/sugar/activity/activityhandle.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/activityservice.py b/sugar/activity/activityservice.py index 32511772..97a6034c 100644 --- a/sugar/activity/activityservice.py +++ b/sugar/activity/activityservice.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/bundlebuilder.py b/sugar/activity/bundlebuilder.py index b66a1629..dce3155f 100644 --- a/sugar/activity/bundlebuilder.py +++ b/sugar/activity/bundlebuilder.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/registry.py b/sugar/activity/registry.py index 255185bf..171f740e 100644 --- a/sugar/activity/registry.py +++ b/sugar/activity/registry.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/datastore/dbus_helpers.py b/sugar/datastore/dbus_helpers.py index bd868a05..2dfccaca 100644 --- a/sugar/datastore/dbus_helpers.py +++ b/sugar/datastore/dbus_helpers.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # Copyright (C) 2007, One Laptop Per Child # # This library is free software; you can redistribute it and/or diff --git a/sugar/env.py b/sugar/env.py index 03cfea71..8707fd9f 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -1,5 +1,5 @@ """Calculates file-paths for the Sugar working environment""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index ec141d0c..274291ab 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/frame.py b/sugar/graphics/frame.py index 4b800fd6..c8e6f9a9 100644 --- a/sugar/graphics/frame.py +++ b/sugar/graphics/frame.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/icon.py b/sugar/graphics/icon.py index f5cc25d1..03b1927b 100644 --- a/sugar/graphics/icon.py +++ b/sugar/graphics/icon.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/menu.py b/sugar/graphics/menu.py index c8afb243..14f471eb 100644 --- a/sugar/graphics/menu.py +++ b/sugar/graphics/menu.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/menushell.py b/sugar/graphics/menushell.py index 61b98b08..f2ff9fa6 100644 --- a/sugar/graphics/menushell.py +++ b/sugar/graphics/menushell.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/roundbox.py b/sugar/graphics/roundbox.py index f638a442..ba9ec988 100644 --- a/sugar/graphics/roundbox.py +++ b/sugar/graphics/roundbox.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/snowflakebox.py b/sugar/graphics/snowflakebox.py index af68d561..81e59812 100644 --- a/sugar/graphics/snowflakebox.py +++ b/sugar/graphics/snowflakebox.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/spreadbox.py b/sugar/graphics/spreadbox.py index 1002a44d..1c1ffc9d 100644 --- a/sugar/graphics/spreadbox.py +++ b/sugar/graphics/spreadbox.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/units.py b/sugar/graphics/units.py index 47aaf1b9..2487c591 100644 --- a/sugar/graphics/units.py +++ b/sugar/graphics/units.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/xocolor.py b/sugar/graphics/xocolor.py index 2fcc7910..f2e892d2 100644 --- a/sugar/graphics/xocolor.py +++ b/sugar/graphics/xocolor.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/logger.py b/sugar/logger.py index 495d7a00..a9042a02 100644 --- a/sugar/logger.py +++ b/sugar/logger.py @@ -1,5 +1,5 @@ """Logging module configuration for Sugar""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/ltihooks.py b/sugar/ltihooks.py index d68f2ebc..1de3034f 100644 --- a/sugar/ltihooks.py +++ b/sugar/ltihooks.py @@ -2,7 +2,7 @@ # vi:si:et:sw=4:sts=4:ts=4 # ltihooks.py: python import hooks that understand libtool libraries. -# Copyright (C) 2000 James Henstridge. +# Copyright (C) 2000-2007 James Henstridge. # renamed to gstltihooks.py so it does not accidentally get imported by # an installed copy of gtk # diff --git a/sugar/network.py b/sugar/network.py index e315cdbf..47927771 100644 --- a/sugar/network.py +++ b/sugar/network.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/profile.py b/sugar/profile.py index 8041a4e1..1638b2c9 100644 --- a/sugar/profile.py +++ b/sugar/profile.py @@ -1,5 +1,5 @@ """User settings/configuration loading""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/sugar/util.py b/sugar/util.py index 58fcc7b8..8e15e92c 100644 --- a/sugar/util.py +++ b/sugar/util.py @@ -1,5 +1,5 @@ """Various utility functions""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public